connection

connection

new connection(options) → {Class}

Class connection, Used to initialize the SDK
Example
const connt new connection({appKey: 'yourAppKey', isHttpDNS: true, https: true, autoReconnectNumMax: 5, delivery: false})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
url String URL of websocket server(Required when ishttpdns is false)
apiUrl String URL of API server(Required when ishttpdns is false)
isHttpDNS Boolean Prevent domain name hijacking
isMultiLoginSessions Boolean If it is true, the same account can log in to multiple web pages at the same time (multi tag login, not open by default, please contact business if necessary). If it is false, the same account can only log in to one web page
https Boolean Enable HTTPS.
autoReconnectNumMax Number Maximum number of reconnections after disconnection
delivery Boolean Send delivered ack
deviceId Boolean device ID, default can not be passed, if passed a fixed value, in the case of not enabled multi-terminal login, the same account will be kicked
Returns:
Connection instance
Type
Class

Methods

acceptInvitation(to)

Accepting friend request
Example
connection.acceptInvitation('user1')
Parameters:
Name Type Description
to String The user ID of the other party
Returns:
Void

addContact(to, message)

add friend
Example
connection.addContact('user1', 'I am Bob')
Parameters:
Name Type Description
to String The user ID of the other party
message String Validation message (not required)
Returns:
Void

addToBlackList(options)

Add friends to your blacklist
Example
connection.addToBlackList({name: 'user1'}) | addToBlackList({name: ['user1', 'user2']})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
name Array.<Object> User ID, add one as a single user ID; Bulk add as an array of user IDs, such as ["user1","user2"]
Returns:
Void

addUsersToChatRoom()

Add chat room members
Example
connection.addUsersToChatRoom({chatRoomId: "chatRoomId", users:['user1', 'user2']})
Parameters:
Name Type Description
opt.chatRoomId string Chat room id
opt.users Array.<string> User ID array
opt.success function
opt.error function
Returns:
Promise

addUsersToChatRoomWhitelist(opt)

Add group whitelist member, Operation authority: Group admin or above
Example
connection.addUsersToGroupWhitelist({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
users Array User id array
success function
error function
Returns:
Promise

addUsersToGroupWhitelist(opt)

Add group whitelist member, Members of the white list can continue to speak after the group bans. Operation authority: Group admin or above, Users added to the whitelist will receive type: 'addusertogroupwhitelist' in the callback of onPresence
Example
connection.addUsersToGroupWhitelist({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
users Array User id array
success function
error function
Returns:
Promise

agreeInviteIntoGroup(opt)

Agree to group invitation. Other people invite you to join the group, you can call this API to agree. The inviter will receive type: 'invite_accept' in the callback of onPresence, After joining successfully, group members will receive type: 'memberjoinpublicgroupsuccess' in the callback of onPresence
Example
connection.agreeInviteIntoGroup({invitee: 'myUserId', groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
invitee string User id of the invitee
groupId Object Group id
success function
error function
Returns:
Promise

agreeJoinGroup(opt)

Allow users to join the group. Group owner or administrator permissions are required. Users who join the group will receive type: 'joinpublicgroupsuccess' in the callback of onPresence
Example
connection.agreeJoinGroup({applicant: 'user1', groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
applicant string The ID of the user who applied to join the group
groupId Object Group id
success function
error function
Returns:
Promise

blockGroup(opt)

Since:
  • 1.4.11
Block group messages, Only valid for mobile terminal
Example
connection.blockGroup({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

changeOwner(opt)

To transfer a group, you need the permission of the group owner. Group members will receive type: 'changeowner' in the onpresence callback
Example
connection.changeOwner({groupId: 'groupId', newOwner: 'user1'})
Parameters:
Name Type Description
opt Object
Properties
Name Type Description
groupId String Group id
newOwner String New group owner userId
success function
error function
Returns:
Promise

chatRoomBlockMulti(opt)

Batch add users to the chat room blacklist, Administrator rights required
Example
connection.chatRoomBlockMulti({usernames: ['user1', 'user2'], chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
usernames Array.<string> User id array
chatRoomId string Chat room id
success function
error function
Returns:
Promise

chatRoomBlockSingle(opt)

Add single user to chat room blacklist, Administrator rights required
Example
connection.chatRoomBlockSingle({chatRoomId: 'chatRoomId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat roo id
username stirng User id
success function
error function
Returns:
Promise

close()

Disconnect
Example
connection.close()
Returns:
void

createChatRoom(options)

Create a chat room
Example
connection.createChatRoom({name: 'myChatRoom', description: 'this is my chatroom', maxusers: 200, members; ['user1']}):Promise
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
name String Chat room name
description String Chat room description
maxusers String The maximum number of chat room members (including the chat room creator) is a numeric type. The default value is 200 and the maximum value is 5000
members Array Chat room member, this property is optional, but if this item is added, there will be at least one element in the array
success function
error function
Returns:
Promise

createGroupNew(opt)

Since:
  • 1.4.11
Create group
Example
connection.createGroupNew({
 data: {
     groupname: 'groupname',
     desc: 'this is my group',
     members: ['user1', 'user2'],
     public: true,
     approval: false,
     allowinvites: true,
     inviteNeedConfirm: false
 }
})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
data Object Group information
Properties
Name Type Description
groupname string Group name
desc string Group description
members Array.<string> User ID array, These users will be pulled directly into the group and receive type: 'direct_joined in the onpresence callback'
public Boolean Whether it is public group or not: the group that others can query by calling 'listgroups'
approval Boolean premise: opt.data.public=true, Is approval required for group addition
allowinvites Boolean premise: opt.data.public=false, Are members allowed to invite others into the group
inviteNeedConfirm Boolean If you want to join a group, whether the invited person needs to confirm. If it is true, it means that the invitation to join the group needs to be confirmed by the invitee; If it is false, it means that the invited person will be directly added to the group without confirmation. The default value for this field is true
success function
error function
Returns:
Promise

declineInvitation(to)

Reject Friend Request
Example
connection.declineInvitation('user1')
Parameters:
Name Type Description
to String The user ID of the other party
Returns:
Void

deleteChatRoomSharedFile(options)

Delete chat room shared files
Example
connection.deleteChatRoomSharedFile({roomId: 'roomId', fileId: 'fileId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
roomId Object Chat room id
fileId Object File id
success function
error function
Returns:
Promise

deleteContact(to)

Delete friend
Example
connection.deleteContact('user1')
Parameters:
Name Type Description
to String The user ID of the other party
Returns:
Void

deleteGroupSharedFile(options)

Delete group shared files
Example
connection.deleteGroupSharedFile({groupId: 'groupId', fileId: 'fileId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
groupId Object Group id
fileId Object File id
success function
error function
Returns:
Promise

destroyChatRoom(options)

Deletes the chat room
Example
connection.destroyChatRoom({chatRoomId: 'chatRoomId'}):Promise
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
chatRoomId String Chat room id
success function
error function
Returns:
Promise

disableSendChatRoomMsg(opt)

All chat room members are prohibited from speaking. Operation permissions: group admin or above identity
Example
connection.disableSendChatRoomMsg({chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
success function
error function
Returns:
Promise

disableSendGroupMsg(opt)

All group members are prohibited from speaking, Operation permissions: group admin or above identity, Group members will receive type: 'muteGroup' in the onPresence callback.
Example
connection.disableSendGroupMsg({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

dissolveGroup(opt)

To dissolve a group, you need the permission of the group owner. Group members will receive type: 'deletegroupchat' in the callback of onPrenscence
Example
connection.dissolveGroup({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

downloadChatRoomSharedFile(options)

Download the chat room to share files
Example
connection.downloadChatRoomSharedFile({roomId: 'roomId', fileId: 'fileId', onFileDownloadComplete: onFileDownloadComplete, onFileDownloadError: onFileDownloadError})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
roomId Object Chat room id
fileId Object File id
onFileDownloadComplete Object Callback for successful file download
onFileDownloadError Object Callback for file download failure
Returns:
Void

downloadGroupSharedFile(options)

Download the group shared file
Example
connection.downloadGroupSharedFile({groupId: 'groupId', fileId: 'fileId', onFileDownloadComplete: onFileDownloadComplete, onFileDownloadError: onFileDownloadError})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
groupId Object Group id
fileId Object File id
onFileDownloadComplete Object Callback for successful file download
onFileDownloadError Object Callback for file download failure
Returns:
Void

enableSendChatRoomMsg(opt)

Remove chat room bans. Operation permissions: chat room admin or above identity
Example
connection.enableSendChatRoomMsg({chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
success function
error function
Returns:
Promise

enableSendGroupMsg(opt)

Remove group bans. Operation permissions: group admin or above identity, Group members will receive type: 'rmgroupmute' in the callback of onpresence
Example
connection.enableSendGroupMsg({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

fetchChatRoomAnnouncement(options)

Get chat announcement
Example
connection.fetchChatRoomAnnouncement({roomId: 'roomId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
roomId Object Chat room id
success function
error function
Returns:
Promise

fetchChatRoomSharedFileList(options)

Gets a list of shared files in the chat room
Example
connection.fetchChatRoomSharedFileList({roomId: 'roomId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
roomId Object Chat room id
success function
error function
Returns:
Promise

fetchGroupAnnouncement(options)

Get group announcement
Example
connection.fetchGroupAnnouncement({groupId: 'groupId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
groupId Object Group id
success function
error function
Returns:
Promise

fetchGroupSharedFileList(options)

Gets a list of group shared files
Example
connection.fetchGroupSharedFileList({groupId: 'groupId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
groupId Object Group id
success function
error function
Returns:
Promise

fetchHistoryMessages(options)

Get historical messages
Example
connection.fetchHistoryMessages({queue:'user1', count: 20}):Promise
Parameters:
Name Type Description
options Object
Properties
Name Type Description
queue String Opposite user Id
count Number Pull number
isGroup Boolean Whether it is group chat or not, the default is false
success function
fail Funciton
Returns:
Promise

fetchUserInfoById(userId)

Query user information
Example
connection.fetchUserInfoById('user1') | fetchUserInfoById(['user1', 'user2'])
Parameters:
Name Type Description
userId String | Array User id
Returns:
Promise

getBlacklist(options)

Get friends blacklist
Example
connection.getBlacklist()
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
success function
error function
Returns:
Promise

getChatRoomAdmin(opt)

Get all administrators in chat room
Example
connection.getChatRoomAdmin({chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
success function
error function
Returns:
Promise

getChatRoomBlacklistNew(opt)

Get chat room blacklist
Example
connection.getChatRoomBlacklistNew({chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
success function
error function
Returns:
Promise

getChatRoomDetails(options)

Gets the chat room details
Example
connection.getChatRoomDetails({chatRoomId: 'chatRoomId'}):Promise
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
chatRoomId String Chat room id
success function
error function
Returns:
Promise

getChatRoomMuted(opt)

Get all members banned in the chat room
Example
connection.getChatRoomMuted({chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
success function
error function
Returns:
Promise

getChatRooms(options)

Get chat room list (paging)
Example
connection.getChatRooms({pagenum: 1, pagesize: 20}):Promise
Parameters:
Name Type Description
options Object
Properties
Name Type Description
pagenum Number Page number, default 1
pagesize Number The number of pages is 20 by default
success function
error function
Returns:
Promise

getChatRoomWhitelist(opt)

Get white chat room white list, Operation authority: admin or above
Example
connection.getChatRoomWhitelist({chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
success function
error function
Returns:
Promise

getGroup(opt)

Since:
  • 1.4.11
Lists all the groups a user has joined
Example
connection.getGroup()
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
success function
error function
Returns:
Promise

getGroupAdmin(opt)

Since:
  • 1.4.11
Get all administrators in the group
Example
connection.getGroupAdmin({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

getGroupBlacklistNew(opt)

Get group blacklist
Example
connection.getGroupBlacklistNew({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

getGroupInfo(opt)

Since:
  • 1.4.11
Get group details
Example
connection.getGroupInfo({groupId: groupId})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

getGroupMsgReadUser(options)

Query which users have read group message [Value-added function] needs to be opened separately
Example
connection.getGroupMsgReadUser({groupId: 'groupId', msgId: 'msgId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
groupId String Group id
msgId String Message id
success function
error function
Returns:
Promise

getGroupWhitelist(opt)

Get group white list, Operation authority: admin or above
Example
connection.getGroupWhitelist({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

getMuted(opt)

Get all banned members of the group
Example
connection.getMuted({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

getRoster(options)

Get contacts
Example
connection.getRoster()
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
success function
error function
Returns:
Promise

getSessionList()

Get the session list
Example
connection.getSessionList()
Parameters:
Name Type Description
options.success function 成功之后的回调,默认为空
options.error function 失败之后的回调,默认为空
Returns:
Promise

getUniqueId() → {Number}

Randomly generate an ID for the message ID
Example
const msgid = connection.getUniqueId()
Returns:
id
Type
Number

groupBlockMulti(opt)

Batch add users to the group blacklist, Administrator rights required,Users added to the blacklist will receive type: 'removedFromGroup' in the onPresence callback.
Example
connection.groupBlockMulti({usernames: ['user1', 'user2'], groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
usernames Array.<string> User id array
groupId string Group id
success function
error function
Returns:
Promise

groupBlockSingle(opt)

Add a single user to the group blacklist, Group owner or administrator permissions are required, Users added to the blacklist will receive type: 'removedFromGroup' in the onPresence callback.
Example
connection.groupBlockSingle({groupId: 'groupId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
username stirng User id
success function
error function
Returns:
Promise

inviteToGroup(opt)

Invite group members. The invited user will receive type: 'invite' in the callback of onPresence
Example
connection.inviteToGroup({groupId: 'groupId', users: ['user1', 'user2']})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
users Array.<string> Invited user id array
success function
error function
Returns:
Promise

isGroupWhiteUser(opt)

Query whether group members are white list users, Operation permission: app admin can query all users; App users can query themselves
Example
connection.isGroupWhiteUser({groupId: 'groupId', userName: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
userName string User id
success function
error function
Returns:
Promise

joinChatRoom(options)

Join chat room, After joining successfully, others will receive type: 'memberjoinchatroomsuccess' in the onPresence callback
Example
connection.joinChatRoom({roomId: 'roomId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
roomId String Chat room id
opt.message stirng Reason, optional (not enabled in chat room)
options.success function
options.error function
Returns:
Promise

joinGroup(opt)

Since:
  • 1.4.11
Apply for group membership, The group owner and administrator receive type: 'joingroupnotifications' in the onPresence callback
Example
connection.joinGroup({groupId: 'groupId', message: 'I want to join the group'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId String Group id
message String Request information
success function
error function
Returns:
Promise

listChatRoomMember(opt)

List all chat room members (paginated)
Example
connection.listChatRoomMember({pageNum: 1, pageSize: 20, chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
pageNum Number Page number, default 1
pageSize Number Maximum number of group members per page, Maximum 1000
chatRoomId string Chat room id
success function
error function
Returns:
Promise

listen(options)

Register listener function
Example
connection.listen({onOpened: onOpened, ...})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
onOpened connection~onOpened Callback for successful login
onTextMessage connection~onTextMessage A callback that receives a text message
onEmojiMessage connection~onEmojiMessage A callback that receives a emoji message
onPictureMessage connection~onPictureMessage A callback that receives a picture message
onAudioMessage connection~onAudioMessage A callback that receives a audio message
onVideoMessage connection~onVideoMessage A callback that receives a video message
onFileMessage connection~onFileMessage A callback that receives a file message
onLocationMessage connection~onLocationMessage A callback that receives a location message
onCmdMessage connection~onCmdMessage A callback that receives a command message
onCustomMessage connection~onCustomMessage A callback that receives a custom message
onPresence connection~onPresence A callback that receives a presence message
onError connection~onError A callback that receives an error
onReceivedMessage connection~onReceivedMessage A callback that receives a received message
onDeliverdMessage connection~onDeliverdMessage A callback that receives a deliverd message
onReadMessage connection~onReadMessage A callback that receives a read message
onRecallMessage connection~onRecallMessage A callback that receives a recall message
onMutedMessage connection~onMutedMessage A callback that receives a muted message
onOffline connection~onOffline Callback of network disconnection
onOnline connection~onOnline Callback of network connection
Returns:
Void

listGroupMember(opt)

Lists all members of the group (paginated)
Example
connection.listGroupMember({pageNum: 1, pageSize: 20, groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
pageNum Number Page number, default 1
pageSize Number Maximum number of group members per page, Maximum 1000
groupId string Group id
success function
error function
Returns:
Promise

listGroups(opt)

Since:
  • 1.4.11
Get public groups (paginated)
Example
connection.listGroups({limit: 20, cursor: null})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Default Description
limit Number Maximum number of groups per page
cursor string null Cursor. If the data has a next page, the API return value will contain this field. Pass this field to get the data of the next page. If it is null, get the data of the first page
success function
error function
Returns:
Promise

modifyChatRoom(options)

Modify chat room details
Example
connection.modifyChatRoom({chatRoomId: 'chatRoomId', chatRoomName: 'chatRoomName', description:'description', maxusers: 5000})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
chatRoomId String Chat room id
chatRoomName String Chat room name
description String Chat room description
maxusers Number Maximum number of chat room
success function
error function
Returns:
Promise

modifyGroup(opt)

Modify group information,Administrator rights required
Example
connection.modifyGroup({groupId: 'groupId', groupName: 'groupName', description:'description'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
groupName string Group name
description string Group description
success function
error function
Returns:
Promise

mute(opt)

Since:
  • 1.4.11
Group user is not allowed to speak,Group owner or administrator permissions are required,Forbidden users and other users will receive type: 'addmute' in the onPresence callback
Example
connection.mute({username: 'user1', muteDuration: '-1000', groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
username string The ID of the banned group member
muteDuration Number The duration of being forbidden, in ms. if it is "- 1000", it means permanent
groupId string group id
success function
error function
Returns:
Promise

muteChatRoomMember(opt)

Since:
  • 1.4.11
Chat room users are prohibited from speaking, Administrator rights required, Forbidden users and other users will receive type: 'addmute' in the onPresence callback
Example
connection.muteChatRoomMember({username: 'user1', muteDuration: -1000, chatRoomId: 'chatRoomId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
username string The ID of the member of the banned chat room
muteDuration Number The duration of being forbidden, in ms. if it is "- 1000", it means permanent
chatRoomId string Chat room id
success function
error function
Returns:
Promise

open(options)

Login
Example
connection.open({user: 'user1', pwd: '123456', appKey: 'yourAppKey'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
user String User id
pwd String password, (Choose one from the token)
accessToken String Token,(Choose one from the password)
appKey String Appkey
success function
error function
Returns:
Void

quitChatRoom(options)

Exit chat room, others will receive type: 'leaveChatRoom' in the onPresence callback
Example
connection.quitChatRoom({roomId: 'roomId'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
roomId String Chat room id
success function
error function
Returns:
Promise

quitGroup(opt)

Leave the group, group members will receive type: 'leavegroup' in the callback of onPresence
Example
connection.quitGroup({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
success function
error function
Returns:
Promise

recallMessage(option)

Recall a message
Example
connection.recallMessage({mid: 'messageId', to: 'user1', type: 'chat', success: success, fail: fail})
Parameters:
Name Type Description
option Object -
Properties
Name Type Description
mid Object The ID of the message that needs to be recalled
to Object The receiver of the message
type Object chat(Single chat) groupchat(Group Chat) chatroom(Chat room chat)
success function Send successful callback
fail function Send failed callback, Possible reasons for failure type:504 , beyond revocable time
Returns:
Void

registerUser(options)

Register new user
Example
registerUser({username: 'user1', password: '123456', nickname: 'Tom'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
username String The user name is the user ID
password String Password
nickname String Nickname, it is used to display when the mobile terminal is pushing
success function
error function
Returns:
Promise

rejectInviteIntoGroup(opt)

Refuse group invitation, Other user invite you to join the group, you can call this API to refuse
Example
connection.rejectInviteIntoGroup({invitee: 'myUserId', groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
invitee string User id of the invitee
groupId Object Group id
success function
error function
Returns:
Promise

rejectJoinGroup(opt)

Refuse user to join the group, Group owner or administrator permissions are required
Example
connection.rejectJoinGroup({applicant: 'user1', groupId: 'groupId', reason: 'I do not like you'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
applicant string The ID of the user who applied to join the group
groupId Object Group id
reason Object Reasons for rejection
success function
error function
Returns:
Promise

removeAdmin(opt)

To cancel the group administrator, you need the permission of the group master. The user whose administrator is canceled will receive type: 'removeadmin' in the callback of onPresence
Example
connection.removeAdmin({gorupId: 'gorupId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
gorupId string Group id
username string User id
success function
error function
Returns:
Promise

removeChatRoomAdmin(opt)

To cancel the chat room administrator, you need the permission of APP admin. The user whose administrator is canceled will receive type: 'removeadmin' in the callback of onPresence
Example
connection.removeChatRoomAdmin({chatRoomId: 'chatRoomId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
username string User id
success function
error function
Returns:
Promise

removeChatRoomBlockMulti(opt)

Batch remove users from chat room blacklist, Administrator rights required
Example
connection.removeChatRoomBlockMulti({chatRoomId: 'chatRoomId', usernames: ['user1', 'user2']})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
usernames string User id array
success function
error function
Returns:
Promise

removeChatRoomBlockSingle(opt)

Remove individual user from chat room blacklist,Administrator rights required
Example
connection.removeChatRoomBlockSingle({chatRoomId: 'chatRoomId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
username string User id
success function
error function
Returns:
Promise

removeFromBlackList(options)

Remove friends from your blacklist
Example
connection.removeFromBlackList({name: 'user1'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
name Array.<Object> Delete one as a single user ID, such as "user1"; Delete into array of user IDs, such as ["user1","user2"]
Returns:
Void

removeGroupBlockMulti(opt)

Batch to remove users from group blacklists, Group owner or administrator permissions are required, Users who have been removed from the blacklist will receive type: 'allow' in the onPresence callback
Example
connection.removeGroupBlockMulti({groupId: 'groupId', usernames: ['user1', 'user2']})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
usernames string User id array
success function
error function
Returns:
Promise

removeGroupBlockSingle(opt)

Remove single user from group blacklist, Administrator rights required, Users who have been removed from the blacklist will receive type: 'allow' in the onPresence callback
Example
connection.removeGroupBlockSingle({groupId: 'groupId'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
username string User id
success function
error function
Returns:
Promise

removeMultiChatRoomMember(opt)

Delete multiple chat room members
Example
connection.removeMultiChatRoomMember({chatRoomId: 'chatRoomId', users: ['user1', 'user2']})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
users Array.<string> User ID array
success function
error function
Returns:
Promise

removeMultiGroupMember(opt)

Delete multiple group members. Group owner or administrator permissions are required. The removed users will receive type: 'removedfromgroup' in the callback of onPresence, and other group members will receive type: 'leavegroup' in the callback of onPresence
Example
connection.removeMultiGroupMember({groupId: 'groupId', users: ['user1', 'user2']})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
users Array.<string> User ID array
success function
error function
Returns:
Promise

removeMute(opt)

Since:
  • 1.4.11
Remove the ban on group member, Group owner or administrator permissions are required. Users who have been released and other users will receive type: 'removemute' in the callback of onPresence
Example
connection.removeMute({groupId: 'groupId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
username string The unbanned group user id
success function
error function
Returns:
Promise

removeMuteChatRoomMember(opt)

Since:
  • 1.4.11
Remove the ban on chat room member, Administrator rights required, Unbanned users and other users will receive type: 'removeMute' in the onPresence callback
Example
connection.removeMuteChatRoomMember({chatRoomId: 'chatRoomId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
username string The unbanned chat room user id
success function
error function
Returns:
Promise

removeSingleChatRoomMember(opt)

Delete individual chat room members
Example
connection.removeSingleChatRoomMember({chatRoomId: 'chatRoomId', username: 'username'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
username string User id
success function
error function
Returns:
Promise

removeSingleGroupMember()

Delete individual group member. Group owner or administrator permissions are required. The removed user will receive type: 'removedfromgroup' in the callback of onPresence, and other group members will receive type: 'leavegroup' in the callback of onPresence
Example
connection.removeSingleGroupMember({groupId: 'groupId', username: 'user1'})
Parameters:
Name Type Description
opt.groupId string Group id
opt.username string User id
opt.success function
opt.error function
Returns:
Promise

rmUsersFromChatRoomWhitelist(opt)

Remove chatroom whitelist members, Operation permissions: ADMIN and above identity, Deleted white list of users will be received in onPresence callback type: 'rmUserFromChatRoomWhiteList'
Example
connection.rmUsersFromChatRoomWhitelist({chatRoomId: 'chatRoomId', userName: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
userName string User id
success function
error function
Returns:
Promise

rmUsersFromGroupWhitelist(opt)

Remove group whitelist members, Operation permissions: group admin or above identity, The user whose whitelist is removed will receive type:'rmUserFromGroupWhiteList' in the onPresence callback.
Example
connection.rmUsersFromGroupWhitelist({groupId: 'groupId', userName: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
userName string User id
success function
error function
Returns:
Promise

send(messageSource)

Send message
Example
let deliverMessage = new WebIM.message('delivery', msgId);
deliverMessage.set({
  id: msgId, 
  to: msg.from
});
connection.send(deliverMessage.body);
Parameters:
Name Type Description
messageSource Object Generated by Class Message
Returns:
Void

setAdmin(opt)

Set up group administrator, need group owner authority. Users who are set as administrators will receive type: 'addadmin' in the onPresence callback
Example
connection.setAdmin({groupId: 'groupId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
groupId string Group id
username string user id
success function
error function
Returns:
Promise

setChatRoomAdmin(opt)

Setting up chat room administrator needs app admin permission. Users who are set as administrators will receive type: 'addadmin' in the onPresence callback
Example
connection.setChatRoomAdmin({chatRoomId: 'chatRoomId', username: 'user1'})
Parameters:
Name Type Description
opt Object -
Properties
Name Type Description
chatRoomId string Chat room id
username string User id
success function
error function
Returns:
Promise

updateChatRoomAnnouncement(options)

Update chat room announcement
Example
connection.updateChatRoomAnnouncement({roomId: 'roomId', announcement: 'hello'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
roomId Object Chat room id
announcement Object Announcement
success function
error function
Returns:
Promise

updateCurrentUserNick(nick)

When registering, you can set a nickname, which is used to display when pushing messages. You can call the following API to modify the nickname
Example
connection.updateCurrentUserNick('Tom')
Parameters:
Name Type Description
nick String 昵称
Returns:
Promise

updateGroupAnnouncement(options)

Update group announcement
Example
connection.updateGroupAnnouncement({groupId: 'groupId', announcement: 'hello'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
groupId Object Group id
announcement Object Announcement
success function
error function
Returns:
Promise

updateOwnUserInfo(options)

Update own information
Example
connection.updateOwnUserInfo({nickname: 'Tom', avatarurl: 'avatarurl', mail: 'abc@gmail,com', ext: JSON.stringify({hobby: 'football'})})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
nickname Object nickname
avatarurl Object Avatar url
mail Object Email
phone Object The phone number
gender Object Gender
sign Object Sign
birth Object Birth
ext Object Extension
Returns:
Promise

uploadChatRoomSharedFile(options)

Upload chat rooms to share files
Example
connection.uploadChatRoomSharedFile({roomId: 'roomId', file: 'file object', onFileUploadProgress: onFileUploadProgress, onFileUploadComplete: onFileUploadComplete,onFileUploadError:onFileUploadError,onFileUploadCanceled:onFileUploadCanceled})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
roomId Object Chat room id
file Object file object
onFileUploadProgress Object Callback of upload progress
onFileUploadComplete Object Callback of upload completed
onFileUploadError Object Upload failed callback
onFileUploadCanceled Object Upload canceled callbacks
Returns:
Void

uploadGroupSharedFile(options)

Upload group shared files
Example
connection.uploadGroupSharedFile({groupId: 'groupId', file: 'file object', onFileUploadProgress: onFileUploadProgress, onFileUploadComplete: onFileUploadComplete,onFileUploadError:onFileUploadError,onFileUploadCanceled:onFileUploadCanceled})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
groupId Object Group id
file Object file object
onFileUploadProgress Object Callback of upload progress
onFileUploadComplete Object Callback of upload completed
onFileUploadError Object Upload failed callback
onFileUploadCanceled Object Upload canceled callbacks
Returns:
Void

uploadToken(options)

If you use the SDK on a native client and integrate third-party push functionality, you can call this method to upload the Token to the server
Example
connection.uploadToken({deviceId: 'deviceId', deviceToken: 'deviceToken', notifierName: 'notifierName'})
Parameters:
Name Type Description
options Object -
Properties
Name Type Description
deviceId Object Device ID, which can be defined by yourself, is generally used to identify the same device
deviceToken Object Push token
notifierName Object Push service appId, senderID for FCM, "appId+#+AppKey" for Vivo
success function
error function
Returns:
Promise