WebIM JS SDK API 文档
更新时间:2020-05-08
初始化WebIM
new WebIM({appId, appKey, [autoConnect], environment, socketUrl, timeout})
Param | Type | Default | Description |
---|---|---|---|
appId | string | appId | |
appKey | string | appKey | |
[autoConnect] | boolean | true | 设置是否自动重连 |
environment | development | production | 环境变量 | |
socketUrl | socketUrl | socket 地址 | |
timeout | number | 超时时间 |
登录
WebIM.login(userId, token) ⇒ Promise.<{userId: string, unreadMsgCount: number}>
Kind: instance method of WebIM
Param | Type | Description |
---|---|---|
userId | string | 用户ID |
token | string | 验证token |
登出
WebIM.logout() ⇒ void
Kind: instance method of WebIM
群组部分
GroupManager Kind: global class
- GroupManager
- new GroupManager()
- instance
- .create(groupName) ⇒
void
- .query(groupId) ⇒
object
- .update(groupId, groupName) ⇒
void
- .delete(groupId) ⇒
void
- .join(groupId, [userName]) ⇒
void
- .leave(groupId) ⇒
void
- .transfer(groupId, ownerId) ⇒
void
- .getUserList(groupId) ⇒
object
- .getUserGroupList([pageIndex], [pageSize]) ⇒
object
- .sendMessage(groupId, content) ⇒
void
- .sendAck(received) ⇒
void
- .create(groupName) ⇒
- static
- "message" ⇒
object
- "message" ⇒
创建群组
groupManager.create(groupName) ⇒ void
Kind: instance method of GroupManager
Returns: void
- {Promise<{groupId: string}>}
Param | Type | Description |
---|---|---|
groupName | string | 群组名称 |
查询群组
groupManager.query(groupId) ⇒ object
Kind: instance method of GroupManager
Returns: object
- {Promise<{groupId: string, groupName: string, ownerId: string}>}
Param | Type | Description |
---|---|---|
groupId | string | 群组ID |
更新群组
groupManager.update(groupId, groupName) ⇒ void
Kind: instance method of GroupManager
Returns: void
- - {Promise\<void>}
Param | Type | Description |
---|---|---|
groupId | string | 群组ID |
groupName | string | 群组名称 |
删除群组
groupManager.delete(groupId) ⇒ void
Kind: instance method of GroupManager
Returns: void
- - {Promise\<void>}
Param | Type | Description |
---|---|---|
groupId | string | 群组ID |
加入群组
groupManager.join(groupId, [userName]) ⇒ void
Kind: instance method of GroupManager
Returns: void
- - {Promise\<void>}
Param | Type | Description |
---|---|---|
groupId | string | 群组ID |
[userName] | string | 用户名 |
离开群组
groupManager.leave(groupId) ⇒ void
Kind: instance method of GroupManager
Returns: void
- - {Promise\<void>}
Param | Type | Description |
---|---|---|
groupId | string | 群组ID |
变更群主
groupManager.transfer(groupId, ownerId) ⇒ void
Kind: instance method of GroupManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
groupId | string | 群组ID |
ownerId | string | 群主ID |
获取群组中所有用户列表
groupManager.getUserList(groupId) ⇒ object
Kind: instance method of GroupManager
Returns: object
- {Promise<[{userId:string,userName:string,role:number}]>}
Param | Type | Description |
---|---|---|
groupId | string | 群组ID |
获取用户群组列表
groupManager.getUserGroupList([pageIndex], [pageSize]) ⇒ object
Kind: instance method of GroupManager
Returns: object
- {Promise<[{groupId:string,groupName:string,ownerId:string}]>}
Param | Type | Default |
---|---|---|
[pageIndex] | number | 1 |
[pageSize] | number | -1 |
发送群组消息
groupManager.sendMessage(groupId, content) ⇒ void
Kind: instance method of GroupManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
groupId | string | 群组ID |
content | string | 消息内容 |
发送接收反馈
groupManager.sendAck(received) ⇒ void
Kind: instance method of GroupManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
received | array.<{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
- new LiveroomManager()
- instance
- .create(roomId) ⇒
void
- .join(roomId) ⇒
void
- .leave(roomId) ⇒
void
- .mute(roomId, userId) ⇒
void
- .unmute(roomId, userId) ⇒
void
- .muteAll(roomId) ⇒
void
- .unmuteAll(roomId) ⇒
void
- .sendMessage(roomId, content) ⇒
void
- .create(roomId) ⇒
- static
创建房间
liveroomManager.create(roomId) ⇒ void
Kind: instance method of LiveroomManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
roomId | string | 房间ID |
加入房间
liveroomManager.join(roomId) ⇒ void
Kind: instance method of LiveroomManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
roomId | string | 房间ID |
离开房间
liveroomManager.leave(roomId) ⇒ void
Kind: instance method of LiveroomManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
roomId | string | 房间ID |
用户静音
liveroomManager.mute(roomId, userId) ⇒ void
Kind: instance method of LiveroomManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
roomId | string | 房间ID |
userId | string | 用户ID |
用户取消静音
liveroomManager.unmute(roomId, userId) ⇒ void
Kind: instance method of LiveroomManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
roomId | string | 房间ID |
userId | string | 用户ID |
房间静音
liveroomManager.muteAll(roomId) ⇒ void
Kind: instance method of LiveroomManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
roomId | string | 房间ID |
房间取消静音
liveroomManager.unmuteAll(roomId) ⇒ void
Kind: instance method of LiveroomManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
roomId | string | 房间ID |
发送直播间消息
liveroomManager.sendMessage(roomId, content) ⇒ void
Kind: instance method of LiveroomManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
roomId | string | 房间ID |
content | string | 消息内容 |
获取创建直播间消息 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
- new PersonalManager()
- instance
- .sendMessage(userId, content) ⇒
void
- .sendAck(received) ⇒
void
- .sendMessage(userId, content) ⇒
- static
- "message" ⇒
object
- "message" ⇒
发送私信
personalManager.sendMessage(userId, content) ⇒ void
Kind: instance method of PersonalManager
Returns: void
- {Promise\<void>}
Param | Type | Description |
---|---|---|
userId | string | 用户ID |
content | string | 消息内容 |
发送接收反馈
personalManager.sendAck(received) ⇒ void
Kind: instance method of PersonalManager
Returns: void
- {Promise\<void>}
Param | Type |
---|---|
received | Array.<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]>}
Param | Type | Default |
---|---|---|
[sequenceId] | number | Long | 0 |
[totalSize] | number | -1 |
获取错误消息 event
"error" ⇒ object
Kind: event emitted
Returns: object
- {type: number, data: any, error: string}