IMClient

IMClient

new IMClient(idopt, optionsopt)

Source:
无法直接实例化,请使用 Realtime#createIMClient 创建新的 IMClient。
Parameters:
Name Type Attributes Description
id String <optional>
客户端 id
options Object <optional>
Properties
Name Type Attributes Description
signatureFactory function <optional>
open session 时的签名方法 // TODO need details
conversationSignatureFactory function <optional>
对话创建、增减成员操作时的签名方法

Extends

Members

id :String

Source:
客户端 id
Type:
  • String

Methods

close() → {Promise}

Source:
关闭客户端
Returns:
Type
Promise

createConversation(options) → {Promise.<Conversation>}

Source:
创建一个 conversation
Parameters:
Name Type Description
options Object 除了下列字段外的其他字段将被视为对话的自定义属性
Properties
Name Type Attributes Default Description
members Array.<String> 对话的初始成员列表,默认包含当前 client
name String <optional>
对话的名字
attributes Object <optional>
DEPRECATED: 额外属性,对应 _Conversation 表的 attr 列
transient Boolean <optional>
false 暂态会话
unique Boolean <optional>
false 唯一对话,当其为 true 时,如果当前已经有相同成员的对话存在则返回该对话,否则会创建新的对话
Returns:
Type
Promise.<Conversation>

emit(event) → {Boolean}

Source:
Inherited From:
依次调用 event 事件的监听器列表中的 listener。
Parameters:
Name Type Attributes Description
event String | Symbol The event name.
...arg Mixed <optional>
payloads
Returns:
`true` if the event had listeners, else `false`.
Type
Boolean

getConversation(id, noCacheopt) → {Promise.<Conversation>}

Source:
获取某个特定的对话
Parameters:
Name Type Attributes Default Description
id String 对话 id,对应 _Conversation 表中的 objectId
noCache Boolean <optional>
false 强制不从缓存中获取
Returns:
如果 id 对应的对话不存在则返回 null
Type
Promise.<Conversation>

getConversations(ids, noCacheopt) → {Promise.<Array.<Conversation>>}

Source:
Since:
  • 3.4.0
通过 id 批量获取某个特定的对话
Parameters:
Name Type Attributes Default Description
ids Array.<String> 对话 id 列表,对应 _Conversation 表中的 objectId
noCache Boolean <optional>
false 强制不从缓存中获取
Returns:
如果 id 对应的对话不存在则返回 null
Type
Promise.<Array.<Conversation>>

getQuery() → {ConversationQuery}

Source:
构造一个 ConversationQuery 来查询对话
Returns:
Type
ConversationQuery

markAllAsRead(conversations) → {Promise.<Array.<Conversation>>}

Source:
Deprecated:
  • 请遍历调用 conversations 的 read 方法
将指定的所有会话标记为已读
Parameters:
Name Type Description
conversations Array.<Conversation> 指定的会话列表
Returns:
conversations 返回输入的会话列表
Type
Promise.<Array.<Conversation>>

off(event, listeneropt, contextopt, onceopt) → {EventEmitter}

Source:
Inherited From:
移除 event 事件的监听器列表中的 listener。
Parameters:
Name Type Attributes Description
event String | Symbol The event name.
listener function <optional>
Only remove the listeners that match this function.
context Mixed <optional>
Only remove the listeners that have this context.
once Boolean <optional>
Only remove one-time listeners.
Returns:
self.
Type
EventEmitter

on(event, listener, contextopt) → {EventEmitter}

Source:
Inherited From:
给指定的 event 添加监听器,并将该监听器置于监听器列表的末位。该方法不会检查是否已经添加过该监听器。重复添加相同的 event 和 listener 会导致该事件和监听器被重复触发。
Parameters:
Name Type Attributes Default Description
event String | Symbol The event name.
listener function The listener function.
context Mixed <optional>
this The context to invoke the listener with.
Returns:
self.
Type
EventEmitter

once(event, listener, contextopt) → {EventEmitter}

Source:
Inherited From:
为 event 事件添加一个一次性的监听器,该事件第一次触发之后就会被注销。
Parameters:
Name Type Attributes Default Description
event String | Symbol The event name.
listener function The listener function.
context Mixed <optional>
this The context to invoke the listener with.
Returns:
self.
Type
EventEmitter

ping(clientIds) → {Primse.<Array.<String>>}

Source:
获取 client 列表中在线的 client,每次查询最多 20 个 clientId,超出部分会被忽略
Parameters:
Name Type Description
clientIds Array.<String> 要查询的 client ids
Returns:
在线的 client ids
Type
Primse.<Array.<String>>

Events

close

Source:
当前客户端被服务端强行下线
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
code Number 错误码
reason String 原因

conflict

Source:
用户在其他客户端登录,当前客户端被服务端强行下线。详见文档「单点登录」章节。

disconnect

Source:
Since:
  • 3.2.0
See:
客户端连接断开

invited

Source:
当前用户被添加至某个对话
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
invitedBy String 邀请者 id
conversation Conversation

kicked

Source:
当前用户被从某个对话中移除
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
kickedBy String 该移除操作的发起者 id
conversation Conversation

membersjoined

Source:
有用户被添加至某个对话
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
members Array.<String> 被添加的用户 id 列表
invitedBy String 邀请者 id
conversation Conversation

membersleft

Source:
有成员被从某个对话中移除
Parameters:
Name Type Description
payload Object
Properties
Name Type Description
members Array.<String> 被移除的成员 id 列表
kickedBy String 该移除操作的发起者 id
conversation Conversation

message

Source:
当前用户收到消息
Parameters:
Name Type Description
message Message
conversation Conversation 收到消息的对话

messagerecall

Source:
消息被撤回
Parameters:
Name Type Description
message AVMessage 被撤回的消息
conversation Conversation 消息所在的会话

messageupdate

Source:
消息被修改
Parameters:
Name Type Description
message AVMessage 被修改的消息
conversation Conversation 消息所在的会话

offline

Source:
Since:
  • 3.4.0
进入离线状态。 这通常意味着网络已断开,或者 Realtime#pause 被调用

online

Source:
Since:
  • 3.4.0
恢复在线状态 这通常意味着网络已恢复,或者 Realtime#resume 被调用

reconnect

Source:
Since:
  • 3.2.0
See:
客户端连接恢复正常,该事件通常在 Realtime#event:reconnect 之后发生

reconnecterror

Source:
Since:
  • 3.2.0
客户端重新登录发生错误(网络连接已恢复,但重新登录错误)

retry

Source:
Since:
  • 3.2.0
正在尝试重新连接
Parameters:
Name Type Description
attempt Number 尝试重连的次数

schedule

Source:
Since:
  • 3.2.0
计划在一段时间后尝试重新连接
Parameters:
Name Type Description
attempt Number 尝试重连的次数
delay Number 延迟的毫秒数

unreadmessages

Source:
Deprecated:
未读消息数目更新
Parameters:
Name Type Description
payload Object
Properties
Name Type Attributes Description
count Number 未读消息数
lastMessageId String <optional>
最新一条未读消息 id
lastMessageTimestamp Date <optional>
最新一条未读消息时间戳
conversation Conversation 未读消息数目有更新的对话

unreadmessagescountupdate

Source:
Since:
  • 3.4.0
未读消息数目更新
Parameters:
Name Type Description
conversations Array.<Conversation> 未读消息数目有更新的对话列表