diff --git a/changelog.md b/changelog.md index c382f0ba0..6aae01cd4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,39 @@ + + +# [4.0.0-beta.5](https://github.com/leancloud/js-realtime-sdk/compare/v4.0.0-beta.4...v4.0.0-beta.5) (2018-04-13) + +### Bug Fixes + +* 修复了多个导致切换用户时连接状态异常的问题。 + +### Features + +* 支持按照富媒体消息类型查询历史消息。`Conversation#queryMessages` 方法增加了 `type` 参数用于指定查询的消息的类型 + +
+ 示例 + + ```js + // 限定查询图片消息 + conversation + .queryMessage({ + type: ImageMessage.TYPE, + }) + .then(console.log) + .catch(console.error); + ``` + +
+ +* 新增枚举 `Event`。SDK 派发的事件的名称是全小写风格的字符串。当事件的名称由多个单词组成时,全小写风格的命名会很难辩识(例如 `unreadmessagescountupdate`)。SDK 现在提供了事件常量枚举 `Event`,你可以使用 `Event.UNREAD_MESSAGES_COUNT_UPDATE` 来代替 `unreadmessagescountupdate` 了。 +* 引入了更加可靠的通知机制。在断线期间发生的 `INVITED` 与 `KICKED` 事件,现在会在断线重连成功后收到。 + +### BREAKING CHANGES + +* 不再支持下列运行环境(SDK 应该仍能在这些环境下工作,但我们不再对其进行测试了): + * Chrome < 45 + * iOS < 9.3 + # 4.0.0-beta.4 (2018-02-06) @@ -144,8 +180,8 @@ * 初始化 `Realtime` 现在需要 `appKey` 参数。 -
-示例 +
+ 示例 ```diff const realtime = new Realtime({ @@ -154,12 +190,12 @@ }); ``` -
+
* 现在所有异步 API 的异常都是以异步的方式抛出。我们还更新了 API 文档,标出了 API 的异步属性。 -
-示例 +
+ 示例 ```javascript // before @@ -175,13 +211,13 @@ }); ``` -
+
* 为了更好的隔离服务,我们为每个应用提供了独立的域名。对于小程序用户,请前往 [《小程序域名白名单配置》](https://leancloud.cn/docs/weapp-domains.html) 更新域名白名单。 * 移除了 v3 中被标记为废弃的 API,包括: -
-移除 API 列表 +
+ 移除 API 列表 * `IMClient` * `#markAllAsRead` 方法 @@ -194,10 +230,11 @@ * `ConversationQuery` * `#withLastMessages` 方法 * `Message` + * `needReceipt` 与 `transient` 属性 * `#setNeedReceipt` 与 `#setTransient` 方法 -
+
### Features diff --git a/package.json b/package.json index 8e8619b83..a57c253cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "leancloud-realtime", - "version": "4.0.0-beta.4", + "version": "4.0.0-beta.5", "description": "LeanCloud Realtime Message JavaScript SDK", "main": "./dist/realtime.js", "jsnext:main": "./src/index.js", diff --git a/realtime.d.ts b/realtime.d.ts index d76596637..365aaf856 100644 --- a/realtime.d.ts +++ b/realtime.d.ts @@ -1,27 +1,47 @@ -declare module LeanCloudRealtime { +declare namespace LeanCloudRealtime { interface AVUser { getSessionToken(): string; } interface SignatureResult { - signature: string, - timestamp: number, - nonce: string, + signature: string; + timestamp: number; + nonce: string; } type SignatureFactoryResult = Promise | SignatureResult; export class Realtime extends EventEmitter { - constructor(options: { appId: string, appKey: string, region?: string, pushOfflineMessages?: boolean, noBinary?: boolean, ssl?: boolean, server?: string|{RTMRouter: string, api: string}, RTMServers?: string|string[], plugins?: Array }); + constructor(options: { + appId: string; + appKey: string; + region?: string; + pushOfflineMessages?: boolean; + noBinary?: boolean; + ssl?: boolean; + server?: string | { RTMRouter: string; api: string }; + RTMServers?: string | string[]; + plugins?: Array; + }); createIMClient( - client: string|AVUser, + client: string | AVUser, options?: { - signatureFactory?: (clientId: string) => SignatureFactoryResult, - conversationSignatureFactory?: (clientId: string, conversationId: string, targetIds: string[], action: string) => SignatureFactoryResult, - blacklistSignatureFactory?: (clientId: string, conversationId: string, targetIds: string[], action: string) => SignatureFactoryResult, - tag?: string, - isReconnect?: boolean, + signatureFactory?: (clientId: string) => SignatureFactoryResult; + conversationSignatureFactory?: ( + clientId: string, + conversationId: string, + targetIds: string[], + action: string + ) => SignatureFactoryResult; + blacklistSignatureFactory?: ( + clientId: string, + conversationId: string, + targetIds: string[], + action: string + ) => SignatureFactoryResult; + tag?: string; + isReconnect?: boolean; }, - tag?: string, + tag?: string ): Promise; static defineConversationProperty(prop: string, descriptor?: Object); register(messageClass: AVMessage[]); @@ -31,14 +51,28 @@ declare module LeanCloudRealtime { class IMClient extends EventEmitter { id: string; close(): Promise; - createConversation(options: { members?: string[], name?: string, transient?: boolean, unique?: boolean, [key: string]: any }): Promise; - createChatRoom(options: { name?: string, [key: string]: any }): Promise; - createTemporaryConversation(options: { members?: string[], ttl?: number }): Promise; + createConversation(options: { + members?: string[]; + name?: string; + transient?: boolean; + unique?: boolean; + [key: string]: any; + }): Promise; + createChatRoom(options: { + name?: string; + [key: string]: any; + }): Promise; + createTemporaryConversation(options: { + members?: string[]; + ttl?: number; + }): Promise; getConversation(id: string, noCache?: boolean): Promise; getQuery(): ConversationQuery; getServiceConversationQuery(): ConversationQuery; getChatRoomQuery(): ConversationQuery; - markAllAsRead(conversations: ConversationBase[]): Promise>; + markAllAsRead( + conversations: ConversationBase[] + ): Promise>; ping(clientIds: string[]): Promise>; parseMessage(json: Object): Promise; parseConversation(json: Object): Promise; @@ -74,8 +108,8 @@ declare module LeanCloudRealtime { withMembers(peerIds: string[], includeSelf: boolean): this; } /** - * 对话 - */ + * 对话 + */ class ConversationBase extends EventEmitter { id: string; lastMessage?: Message; @@ -87,13 +121,46 @@ declare module LeanCloudRealtime { readonly unreadMessagesMentioned: Boolean; [key: string]: any; // constructor(); - createMessagesIterator(option: { limit?: number, beforeTime?: Date, beforeMessageId?: string }); + createMessagesIterator(option: { + limit?: number; + beforeTime?: Date; + beforeMessageId?: string; + }); read(): Promise; fetchReceiptTimestamps(): Promise; - queryMessages(options: { beforeTime?: Date, beforeMessageId?: string, afterTime?: Date, afterMessageId?: string, limit?: number, type: number }): Promise>; - queryMessages(options: { startTime?: Date, startMessageId?: string, startClosed?: boolean, endTime?: Date, endMessageId?: string, endClosed?: boolean, limit?: number, type: number, direction?: MessageQueryDirection }): Promise>; - send(message: T, options?: { pushData?: Object, priority?: MessagePriority, receipt?: boolean, transient?: boolean, will?: boolean }): Promise; - update(message: MessagePointer, newMessage: T): Promise; + queryMessages(options: { + beforeTime?: Date; + beforeMessageId?: string; + afterTime?: Date; + afterMessageId?: string; + limit?: number; + type: number; + }): Promise>; + queryMessages(options: { + startTime?: Date; + startMessageId?: string; + startClosed?: boolean; + endTime?: Date; + endMessageId?: string; + endClosed?: boolean; + limit?: number; + type: number; + direction?: MessageQueryDirection; + }): Promise>; + send( + message: T, + options?: { + pushData?: Object; + priority?: MessagePriority; + receipt?: boolean; + transient?: boolean; + will?: boolean; + } + ): Promise; + update( + message: MessagePointer, + newMessage: T + ): Promise; recall(message: MessagePointer): Promise; count(): Promise; toJSON(): Object; @@ -142,13 +209,20 @@ declare module LeanCloudRealtime { remove(clientIds: string[]): Promise; muteMembers(clientIds: string[]): Promise; unmuteMembers(clientIds: string[]): Promise; - queryMutedMembers(options?: PagedQueryParams): Promise>; + queryMutedMembers( + options?: PagedQueryParams + ): Promise>; blockMembers(clientIds: string[]): Promise; unblockMembers(clientIds: string[]): Promise; - queryBlockedMembers(options?: PagedQueryParams): Promise>; + queryBlockedMembers( + options?: PagedQueryParams + ): Promise>; getAllMemberInfo(): Promise; getMemberInfo(memberId: string): Promise; - updateMemberRole(memberId: string, role: ConversationMemberRole): Promise; + updateMemberRole( + memberId: string, + role: ConversationMemberRole + ): Promise; } export class Conversation extends PresistentConversation {} @@ -176,7 +250,7 @@ declare module LeanCloudRealtime { toJSON(): Object; } - type MessagePointer = Message | {id: string, timestamp: Date|number}; + type MessagePointer = Message | { id: string; timestamp: Date | number }; type Payload = Object | String | ArrayBuffer; @@ -214,7 +288,7 @@ declare module LeanCloudRealtime { // 富媒体消息 export class TypedMessage extends Message { - static type: number; + static TYPE: number; attributes: Object; text: string; readonly summary: string; @@ -239,10 +313,10 @@ declare module LeanCloudRealtime { } interface Middleware { - (target: T): T + (target: T): T; } interface Decorator { - (target: T): void + (target: T): void; } export interface Plugin { @@ -300,7 +374,7 @@ declare module LeanCloudRealtime { INVALID_MESSAGING_TARGET, MESSAGE_REJECTED_BY_APP, } - + export enum Event { DISCONNECT, RECONNECT, @@ -310,7 +384,7 @@ declare module LeanCloudRealtime { ONLINE, RECONNECT_ERROR, - + INVITED, KICKED, MEMBERS_JOINED, @@ -338,8 +412,8 @@ declare module LeanCloudRealtime { INFO_UPDATED, } - export function messageType(type: number): Function - export function messageField(fields: string[]): Function + export function messageType(type: number): Function; + export function messageField(fields: string[]): Function; } export = LeanCloudRealtime;