WebIM JS SDK API 文档

更新时间:2020-05-08

初始化WebIM

new WebIM({appId, appKey, [autoConnect], environment, socketUrl, timeout})

ParamTypeDefaultDescription
appIdstringappId
appKeystringappKey
[autoConnect]booleantrue设置是否自动重连
environmentdevelopment | production环境变量
socketUrlsocketUrlsocket 地址
timeoutnumber超时时间

登录

WebIM.login(userId, token) ⇒ Promise.<{userId: string, unreadMsgCount: number}>

Kind: instance method of WebIM

ParamTypeDescription
userIdstring用户ID
tokenstring验证token

登出

WebIM.logout() ⇒ void

Kind: instance method of WebIM

群组部分

GroupManager Kind: global class

创建群组

groupManager.create(groupName) ⇒ void

Kind: instance method of GroupManager
Returns: void - {Promise<{groupId: string}>}

ParamTypeDescription
groupNamestring群组名称

查询群组

groupManager.query(groupId) ⇒ object

Kind: instance method of GroupManager
Returns: object - {Promise<{groupId: string, groupName: string, ownerId: string}>}

ParamTypeDescription
groupIdstring群组ID

更新群组

groupManager.update(groupId, groupName) ⇒ void

Kind: instance method of GroupManager
Returns: void - - {Promise\<void>}

ParamTypeDescription
groupIdstring群组ID
groupNamestring群组名称

删除群组

groupManager.delete(groupId) ⇒ void

Kind: instance method of GroupManager
Returns: void - - {Promise\<void>}

ParamTypeDescription
groupIdstring群组ID

加入群组

groupManager.join(groupId, [userName]) ⇒ void

Kind: instance method of GroupManager
Returns: void - - {Promise\<void>}

ParamTypeDescription
groupIdstring群组ID
[userName]string用户名

离开群组

groupManager.leave(groupId) ⇒ void

Kind: instance method of GroupManager
Returns: void - - {Promise\<void>}

ParamTypeDescription
groupIdstring群组ID

变更群主

groupManager.transfer(groupId, ownerId) ⇒ void

Kind: instance method of GroupManager
Returns: void - {Promise\<void>}

ParamTypeDescription
groupIdstring群组ID
ownerIdstring群主ID

获取群组中所有用户列表

groupManager.getUserList(groupId) ⇒ object

Kind: instance method of GroupManager
Returns: object - {Promise<[{userId:string,userName:string,role:number}]>}

ParamTypeDescription
groupIdstring群组ID

获取用户群组列表

groupManager.getUserGroupList([pageIndex], [pageSize]) ⇒ object

Kind: instance method of GroupManager
Returns: object - {Promise<[{groupId:string,groupName:string,ownerId:string}]>}

ParamTypeDefault
[pageIndex]number1
[pageSize]number-1

发送群组消息

groupManager.sendMessage(groupId, content) ⇒ void

Kind: instance method of GroupManager
Returns: void - {Promise\<void>}

ParamTypeDescription
groupIdstring群组ID
contentstring消息内容

发送接收反馈

groupManager.sendAck(received) ⇒ void

Kind: instance method of GroupManager
Returns: void - {Promise\<void>}

ParamTypeDescription
receivedarray.<{from: string, to: string, content: string}>接收消息列表

获取群组消息 event

"message" ⇒ object

Kind: event emitted by GroupManager
Returns: object - {{from: string, to: string, content: string}}

直播间部分

LiveroomManager Kind: global class

创建房间

liveroomManager.create(roomId) ⇒ void

Kind: instance method of LiveroomManager
Returns: void - {Promise\<void>}

ParamTypeDescription
roomIdstring房间ID

加入房间

liveroomManager.join(roomId) ⇒ void

Kind: instance method of LiveroomManager
Returns: void - {Promise\<void>}

ParamTypeDescription
roomIdstring房间ID

离开房间

liveroomManager.leave(roomId) ⇒ void

Kind: instance method of LiveroomManager
Returns: void - {Promise\<void>}

ParamTypeDescription
roomIdstring房间ID

用户静音

liveroomManager.mute(roomId, userId) ⇒ void

Kind: instance method of LiveroomManager
Returns: void - {Promise\<void>}

ParamTypeDescription
roomIdstring房间ID
userIdstring用户ID

用户取消静音

liveroomManager.unmute(roomId, userId) ⇒ void

Kind: instance method of LiveroomManager
Returns: void - {Promise\<void>}

ParamTypeDescription
roomIdstring房间ID
userIdstring用户ID

房间静音

liveroomManager.muteAll(roomId) ⇒ void

Kind: instance method of LiveroomManager
Returns: void - {Promise\<void>}

ParamTypeDescription
roomIdstring房间ID

房间取消静音

liveroomManager.unmuteAll(roomId) ⇒ void

Kind: instance method of LiveroomManager
Returns: void - {Promise\<void>}

ParamTypeDescription
roomIdstring房间ID

发送直播间消息

liveroomManager.sendMessage(roomId, content) ⇒ void

Kind: instance method of LiveroomManager
Returns: void - {Promise\<void>}

ParamTypeDescription
roomIdstring房间ID
contentstring消息内容

获取创建直播间消息 event

"create" ⇒ object

Kind: event emitted by LiveroomManager
Returns: object - {{roomId: string, userId: string}}

获取加入直播间消息 event

"join" ⇒ object

Kind: event emitted by LiveroomManager
Returns: object - {{roomId: string, userId: string}}

获取离开直播间消息 event

"leave" ⇒ object

Kind: event emitted by LiveroomManager
Returns: object - {{roomId: string, userId: string}}

获取直播间实时消息 event

"message" ⇒ object

Kind: event emitted by LiveroomManager
Returns: object - {{from: string, to: string, content: string}}

私信部分

PersonalManager Kind: global class

发送私信

personalManager.sendMessage(userId, content) ⇒ void

Kind: instance method of PersonalManager
Returns: void - {Promise\<void>}

ParamTypeDescription
userIdstring用户ID
contentstring消息内容

发送接收反馈

personalManager.sendAck(received) ⇒ void

Kind: instance method of PersonalManager
Returns: void - {Promise\<void>}

ParamType
receivedArray.<TextMsgDataWrapper>

获取私信消息 event

"message" ⇒ object

Kind: event emitted by PersonalManager
Returns: object - {{from: string, to: string, content: string}}

获取未读消息列表

pullManager.getUnreadMessageList([sequenceId], [totalSize]) ⇒ object

Kind: instance method of PullManager
Returns: object - {Promise<[type: string, message: string]>}

ParamTypeDefault
[sequenceId]number | Long0
[totalSize]number-1

获取错误消息 event

"error" ⇒ object

Kind: event emitted
Returns: object - {type: number, data: any, error: string}