Instant Messaging
Web
Quick Start
Product Introduction
Overview
Features
Limits
Features
Account integration and login
Messaging
Team Chat
Chat Room
Chat Room Tags
Multi-device Login
Statistics Monitoring
Development Integration
Integration
Initializing the SDK
Login and Logout
Recent Chats
User Profile Hosting
Friends Data Hosting
User Relationship Data Hosting
Online Status Subscription
Superteam
Chat Room
High availability of domain name
Extension Features
Tools
API Reference
Status Code

Chat room

Update time: 2021/12/06 16:03:54

Please refer to Integration mode to download and introduce SDK file.

Overview

  • Creating or dismissing a chat room with SDK API is now unavailable.
  • If a user enters a chat room, new connection must be created. If the user leaves or is removed from the chat room, connection will be disabled. If the user is disconnected from a chat room, automatic re-connection will be executed. Developers need to monitor connection status of a chat room to make correct API action.
  • The number of online members in a chat room is not limited.
  • Users can enter a chat room manually and can not invitations.
  • A user is allowed to enter multiple chat rooms and create multiple connections.
  • After disconnecting from a chat room, the user will no longer receive messages related to the chat room from the server.
  • Before any operation, a user needs to first enter the chat room. That is to say, the user must first initialize chat room and get the callback onconnect.
  • When a user enters a chat room, the user will not receive push notification history from the chat room. If the message history is required, he can call The API Query messages.

Get the server address of a chat room

Before initializing a chat room, you need to first get the server address of chat room by the following two methods.

  • If developers have NIM instances, the server address of chat room can be acquired from IM connection, with the sample code shown as below:
nim.getChatroomAddress({
  chatroomId: 'chatroomId',
  done: getChatroomAddressDone
});
function getChatroomAddressDone(error, obj) {
  console.log('get chat room address' + (!error?'succeeded':'failed’), error, obj);
}

Initialize a chat room

  • Before initializing chat room, you need to Get the server address of a chat room.
  • The API is set as singleton mode. For the same account, it always returns the same instance. For example, only the first invocation will initialize one instance.
  • The initialized instance will be returned in subsequent invocation of The API. The API Update chat room configurations is also invoked to update input configurations.
  • When The API is invoked subsequently, if connection is disabled, automatic connection will be enabled.
  • If disconnection occurs, the SDK will re-connect automatically.
  • If you get the callback onconnect, it means that you have entered a chat room successfully and now can execute other operations.
  • Anonymous login
    • The SDK allows users to visit chat room as guests, i.e. the parameter isAnonymous is set to "true" to realize.
    • For anonymous login for the first time (creating instance), it is not necessary to fill in the parameter "account" , but it requires to get the parameter generated by the SDK from chat room instance after login.
    • Anonymous login requires a nickname of a user. For non-anonymous login, the nickname is optional. We recommend filling in photo profiles.
    • In order to avoid creating new instance for a chat room, we recommend inputting the previous account with the parameter at the time of update or second getInstance if they need to update chat room configurations (anonymous mode).

Sample codes

// Note that you may need to call The API by SDK.Chatroom.getInstance if you are introducing different SDK files
// Non-anonymous login
var chatroom = Chatroom.getInstance({
  appKey: 'appKey',
  account: 'account',
  token: 'token',
  chatroomId: 'chatroomId',
  chatroomAddresses: [
    'address1',
    'address2'
  ],
  onconnect: onChatroomConnect,
  onerror: onChatroomError,
  onwillreconnect: onChatroomWillReconnect,
  ondisconnect: onChatroomDisconnect,
  // Message
  onmsgs: onChatroomMsgs
});
function onChatroomConnect(obj) {
  console.log('enter chat room', obj);
  // Send messages after successful connection
  var msg = chatroom.sendText({
    text: 'hello',
    done: function sendChatroomMsgDone (msgObj) {
    }
  })
}
function onChatroomWillReconnect(obj) {
  // Indicate that the `SDK` has been disconnected, the developer should inform the users that it is disconnected and connection is reestablished on The API
  console.log('Reconnect immediately', obj);
}
function onChatroomDisconnect(error) {
  // Indicate that the `SDK` is disconnected, and the developer should give the appropriate error message based on the error code, and jump to the login page
  console.log('disconnect', error);
  if (error) {
    switch (error.code) {
    // Wrong account or password, please jump to the login page with an error message
    case 302:
      break;
    // Removed, please jump to the login page after giving an error tip
    case 'kicked':
      break;
    default:
      break;
    }
  }
}
function onChatroomError(error, obj) {
  console.log('error', error, obj);
}
function onChatroomMsgs(msgs) {
  console.log('receive chat room message', msgs);
}
// Anonymous login
var chatroom = Chatroom.getInstance({
  appKey: 'appKey',
  // account: account not required
  // token: account not required
  chatroomId: 'chatroomId',
  chatroomAddresses: [
    'address1',
    'address2'
  ],
  chatroomNick: 'chatroomNick',
  chatroomAvatar: 'chatroomAvatar',
  isAnonymous: true,
  onconnect: onChatroomConnect,
  // ...
});

function onChatroomConnect (obj) {
  // chatrom is a globally generated instance
  window.account = chatroom.account
}

Parameter description

  • appKey: appKey for viewing app at CommsEase console.
  • account: Account, unique in app.
  • token: token of account, used for creating connection.
  • nosScene: nos storage scene. The value is chat room by default.
  • nosSurvivalTime: Valid time of nos storage scene. The value is Infinity by default.
  • chatroomId: Chat room ID
  • chatroomAddresses: List of chat room addresses
  • chatroomNick: Nickname shown in chat room. If it is not configured and user profile is hosted, nickname in user profile will be used.
  • chatroomAvatar: Avatar shown in chat room. If it is not configured and user profile is hosted, avatar in user profile will be used.
  • chatroomCustom: Extension field. If it is configured, the information of chat room members acquired with The API "Get a list of chat room members" will include this field.
    • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
  • chatroomEnterCustom: Extension field. If it is not empty, this field will be the value of attach.custom in Chat room notification message that is received by other members.
    • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
  • onconnect: It is a callback after creating connection, which will input Chat room information.
  • onwillreconnect: A callback for re-connection
    • Now, the SDK has disconnected from a chat room. Developers shall prompt users at The API that the chat room is disconnected and it is trying to re-connect.
    • The callback will get an object which includes extra information, with fields shown as below:
      • duration: Duration for re-connection
      • retryCount: Retry count
  • ondisconnect: Callback returned after disconnection
    • Now, the SDK has disconnected from a chat room. Developers shall prompt related error information based on error code and skip to login page.
    • The callback will get an object which includes error information, with fields shown as below:
      • code: Error code for any error. It may be empty.
        • 302: Account or password error
        • 'kicked': Kicked out
    • If code is 'kicked', the object will include fields as shown below:
      • reason: Reason of being kicked out
        • chatroomClosed: Chat room is closed.
        • managerKick: Kicked out by manager
        • samePlatformKick: An account is not allowed to login to the same chat room repeatedly.
      • message: Description about reason of being kicked out
  • onerror: It is a callback of an error, error object will be input.
  • onmsgs: It is a callback for receiving message, array of Chat room message object will be input.

Leave a chat room

  • If you have completed Initialize a chat room and got the callbackonconnect, it means that you have entered the chat room.
  • After getting the callbackonconnect, you can invokechatroom.disconnect(); to leave the chat room.
  • After leaving the chat room, you can invokechatroom.connect(); to enter the chat room again.

Switch a chat room

If you need to switch chat room, you can:

Update chat room configurations

The chat room is set as singleton mode. If the current chat room configurations shall be updated, this API can be invoked. The parameter list and format shall be consistent with Chat room.getInstance. Updating token is taken as an example.

// Disconnect chat room
chatroom.disconnect()
// Update token
chatroom.setOptions({
  token: 'newToken'
});
// Reconnect
chatroom.connect()

Clear a chat room instance

SDK for Web connection instances are set as singleton mode, but related API can be invoked to clear instances in memory, i.e. connection is disabled to clear message history and timestamp in memory, so that developers can re-connect clearly.

  var chatroom = Chatroom.getInstance({...})
  // Clear instance
  chatroom.destroy({
    done: function (err) {
      console.log('instance has been fully cleared')
    }
  })

Chat room information object

The chat room information object contains fields as below:

  • id: Chat room ID
  • name: Chat room name
  • announcement: Chat room announcement
  • broadcastUrl: Live broadcast address
  • custom: The third-party extension field
    • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
  • createTime: Creation time
  • updateTime: Update time
  • creator: Creator's account
  • onlineMemberNum: Number of current online users
  • mute: It determines whether to mute. instead of creator and manager, ordinary team members cannot send any message under mute status.

Get chat room information

chatroom.getChatroom({
  done: getChatroomDone
});
function getChatroomDone(error, obj) {
  console.log('get chat room information' + (!error?'succeeded':'failed’), error, obj);
}

Update chat room information

Updatable fields include:

  • chatroom: Intrinsic attribute of chat room
    • chatroom.name: Chat room name
    • chatroom.announcement: Chat room announcement
    • chatroom.broadcastUrl: Live broadcast address
    • chatroom.custom: The third-party extension field
    • chatroom.queuelevelQueue management permission: 0: Everyone can modify the queue, 1: Only the anchor manager can modify the queue.

Other parameters:

  • needNotify: It determines whether it is required to issue related notification message.
  • custom: Extension field. of corresponding notification message
  • needSave: (Optional). It determines whether to support persistence of the field nick, avator and custom (valid for fixed members). The default value is "false".
  • done: It is the callback that is returned after completing update.
  chatroom.updateChatroom({
    chatroom: {
      name: 'newName',
      announcement: 'newAnnouncement',
      broadcastUrl: 'newBroadcastUrl',
      custom: 'newCustom'
    },
    needNotify: true,
    custom: 'biu',
    needSave: true, 
    done: updateChatroomDone
  })
  function updateChatroomDone () {
    console.log('update chat room information' + (!error?'succeeded':'failed’), error, obj);
  }

Update my profile in chat room

Updatable fields include:

  • 'nick'Nickname shown in chat room
  • 'avatar'Photo profiles shown in chat room
  • 'custom': The third-party extension field
  chatroom.updateMyChatroomMemberInfo({
    member: {
    nick: 'newNick',
    avatar: 'newAvatar',
    custom: 'newCustom',
    },
    needNotify: true,
    custom: 'biu',
    done: updateMyChatroomMemberInfoDone
  })

  function updateMyChatroomMemberInfoDone (error, obj) {
    console.log('update information in chat room' + (!error?'succeeded':'failed’), error, obj);
  }

Chat room message

Chat room message object

The chat room message object contains fields shown as below:

  • chatroomId: Chat room ID
  • idClient: ID of SDK generated message. It will be returned to developers after the message is sent. Developers can determine sending status (successful or failed) of related message in the callback for sending message based on the ID, and then update UI of the page based on the status. If a message is not sent successfully, it can be re-sent.
  • from: Message sender, account
  • fromNick: Nickname of message sender
  • fromAvatar: Avatar of message sender
  • fromCustom: Extension field of message sender
  • fromClientType: Device type of sender
  • type: Type of chat room message
  • flow: Flow of message
    • 'in' means that the message is the received message.
    • 'out' means that the message is the sent message.
  • text: Content of text message. Please refer to Send chat room text message.
  • file: File object of file message. For detailed fields, see Image object, Audio object, Video object, File object. Please refer to Send chat room file message.
  • geo: Geographical location object of geographical location message. Please refer to Send chat room geographical location message.
  • tip: Content of tip message. Please refer to Send chat room tip message.
  • content: Content of custom message. Developer can extend it independently. We recommend packing it into JSON character string. Please refer to Send chat room custom message.
  • attach: Attached information for Chat room notification message. Please refer to Type of chat room notification message to view detailed explanation.
  • custom: Extension field.
    • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
  • resend: It determines whether the message is re-sent or not.
  • time: Timestamp

Chat room message types

  • 'text' (Text)
  • 'image' (Image)
  • 'audio' (Audio)
  • 'video' (Video)
  • 'file' (File)
  • 'geo' (Geographical location)
  • 'custom' (Custom message)
  • 'tip' (Tip message)
    • The tip message is used to remind status in session, for example, welcome message in session, or prompt message when the session contains sensitive.
  • 'notification' (Chat room notification message)

Types of chat room notification messages

Send chat room messages

There are APIs as below:

Send text messages

var msg = chatroom.sendText({
  text: 'hello',
  done: sendChatroomMsgDone
});
console.log('sending chat room text message, id=' + msg.idClient);
function sendChatroomMsgDone(error, msg) {
  console.log('send chat room' + msg.type + 'message' + (!error?'succeeded':'failed’) + ', id=' + msg.idClient, error, msg);
}

Preview files

  • Developers can preview the file. Several scenes are available:
    • A file is input with the parameter fileInput to select DOM node or node ID.
    • Blob object is input with the parameter blob.
    • The data URL that contains MIME type and base64 is input with the parameter dataURL. This method requires that explorer supports window.Blob.
  • SDK will upload the file to file server and then transfer acquired file object to developers in the callback done. There are several file objects as below:
  • After getting the file object, developers can invoke "Send chat room file message" to send file message.
  • File size limit is 100M max.
    • The advanced explorer will check file size before the file is uploaded.
    • IE8/IE9 will check file size after the file is uploaded (v5.0.0 and below support IE8).
chatroom.previewFile({
  type: 'image',
  fileInput: fileInput,
  uploadprogress: function(obj) {
    console.log('total file size: ' + obj.total + 'bytes');
    console.log('uploaded size: ' + obj.loaded + 'bytes');
    console.log('upload progress: ' + obj.percentage);
    console.log('upload progress text: ' + obj.percentageText);
  },
  done: function(error, file) {
    console.log('upload image' + (!error?'succeeded:'failed'));
    // show file to the user
    if (!error) {
      var msg = chatroom.sendFile({
        scene: 'p2p',
        to: 'account',
        file: file,
        done: sendChatroomMsgDone
      });
      console.log('sending chat room image message, id=' + msg.idClient);
    }
  }
});

Send file messages

  • File message is one type of Chat room messages.
  • Developers can send file message.
    • Several scenes are available:
      • A file is input with the parameter fileInput to select DOM node or node ID.
      • Blob object is input with the parameter blob.
      • The data URL that contains MIME type and base64 is input with the parameter dataURL. This method requires that explorer supports window.Blob.
    • SDK will upload the file to file server and then transfer acquired file object to users in the callback uploaddone, and edit it into file message to send out.
  • Developers can also Preview chat room file to get file object and then invoke The API to send file message.
  • If the file message is sent, SDK generated idClient will be input in the callback beforesend. If you preview the file and then send it out, The API will return idClient.
  • The parameter type designates file type to be sent, including image, audio file, video and common file, with corresponding value 'image', 'audio', 'video' and 'file' respectively. If it is not input, the value is 'file' by default.
  • The difference among image, audio file, video and common file is that detailed file information is different. For detailed fields, see:
  • File size limit is 100M max.
    • The advanced explorer will check file size before the file is uploaded.
    • IE8/IE9 will check file size after the file is uploaded (v5.0.0 and below support IE8).
chatroom.sendFile({
  type: 'image',
  fileInput: fileInput,
  uploadprogress: function(obj) {
    console.log('total file size: ' + obj.total + 'bytes');
    console.log('uploaded size: ' + obj.loaded + 'bytes');
    console.log('upload progress: ' + obj.percentage);
    console.log('upload progress text: ' + obj.percentageText);
  },
  uploaddone: function(error, file) {
    console.log('upload' + (!error?'succeeded':'failed’), error, file);
  },
  beforesend: function(msg) {
    console.log('sending chat room image message, id=' + msg.idClient);
  },
  done: sendChatroomMsgDone
});

Send location messages

var msg = chatroom.sendGeo({
  scene: 'p2p',
  to: 'account',
  geo: {
    lng: '116.3833',
    lat: '39.9167',
    title: 'Beijing'
  },
  done: sendChatroomMsgDone
});
console.log('sending chat room geo message, id=' + msg.idClient);

Send tip messages

  • Tip message is one type of Chat room messages.
  • The tip message is used to remind status in session, for example, welcome message in session, or prompt message when the session contains sensitive.
var msg = chatroom.sendTipMsg({
  scene: 'p2p',
  to: 'account',
  tip: 'tip content',
  done: sendChatroomMsgDone
});
console.log('sending chat room tip message, id=' + msg.idClient);

Send custom messages

var value = Math.ceil(Math.random()*3);
var content = {
  type: 1,
  data: {
    value: value
  }
};
var msg = chatroom.sendCustomMsg({
  content: JSON.stringify(content),
  done: sendChatroomMsgDone
});
console.log('sending chat room custom message, id=' + msg.idClient);

Send configuration options of chat room messages

  • The above APIs for sending message can be configured with extra options to meet developers' custom demands for server.

    • custom: Extension field.
      • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
    • skipHistory: It determines whether to skip cloud storage. This message will not be included when message history is acquired.
    • yidunEnable: It designates whether it is necessary to use custom anti-spam field, i.e. antiSpamContent. The default value is false which means that it is not required.
    • antiSpamUsingYidun: It determines whether GuideEase anti-spam is enabled for a single message. false means that GuideEase anti-spam is disabled when GuideEase is enabled.
    • antiSpamContent: When yidunEnable is enabled, developers customize anti-spam field with json format {"type": 1, "data": "custom content"}. Notes: type: 1. Text; 2. Image, 3. Video; data content: text or image address or video address.
  • We take an example of sending file message here. The API for sending other messages is similar.

var msg = chatroom.sendText({
  text: 'hello',
  custom: '{}',
  done: sendChatroomMsgDone
});
console.log('sending chat room text message, id=' + msg.idClient);

Get the message history

  • timetag: Several data before corresponding time point of timetag is acquired.
  • If it is not timetag, it will be current server time by default.
  • limit: If it is empty, the value is 100 by default.
  • reverse: The default false means to query message history forward from timetag; true means to query message history backward from timetag.
  • msgTypes is character string or array. You can select to acquire message type of history. If it is empty, type is not distinguished and all messages are acquired.
    • text: Filter text message
    • image: Filter image message
    • audio: Filter audio message
    • video: Filter video message
    • geo: Filter geographical location message
    • notification: Filter notification message
    • file: Filter file message
    • tip: Filter tip message
    • custom: Filter custom message
  chatroom.getHistoryMsgs({
    timetag: 1451393192478,
    limit: 100,
    msgTypes: ['text', 'image'],
    done: getHistoryMsgsDone
  })

  function getHistoryMsgsDone(error, obj) {
    console.log('get chat room history' + (!error?'succeeded':'failed’), obj.msgs);
  }

Chat room members

Chat room member object

The chat room member object contains fields shown as below:

  • chatroomId: Chat room ID
  • account: Account
  • nick: Nickname shown in chat room
  • avatar: Avatar shown in chat room
  • type: Type of chat room member
  • guest: It determines whether a user is guest.
  • blacked: It determines whether a user is added to blacklist.
  • gaged: It determines whether a user is muted
  • level: Level
  • online: It determines online status. The fixed members can be offline, but guests can be online only.
  • enterTime: Time of entering chat room. If it is offline, the field is not available.
  • custom: Extension field.
    • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
  • updateTime: Update time
  • tempMuted: It determines whether a user is muted temporarily.
  • tempMuteDuration: Remaining duration of temporary mute.

Types of chat room members

The chat room members include fixed members and guests. The fixed members include owner, manager, ordinary member and restricted member. The users who are muted and added to blocklistare restricted users.

  • 'owner' (Owner)
  • 'manager' (Manager)
  • 'restricted' (Restricted, added to blocklistor muted)
  • 'common' (ordinary member)
  • 'guest' (Guest)

Get a list of chat room members

  • guest: true is to get guest; false is to get non-guest member.
    • In the list of guests, they are sorted in descending order by the time of entering chat room.
    • In the list of non-guests (i.e. fixed members), they are sorted in descending order by the time of becoming fixed members.
  • If guest=false is configured to get non-guest members, all fixed members will be acquired by default, including offline fixed members. onlyOnline=true can be configured to get online fixed members.
  • "time" is used for paging to query members before the timestamp.
    • The default value 0 is current server time.
    • If a guest is acquired, the field is enterTime of the last guest who was acquired last time.
    • If a non-guest is acquired, the field is updateTime of the last guest who was acquired last time.
  • "limit" is used for paging. The default value is 100.
chatroom.getChatroomMembers({
  guest: false,
  limit: 100,
  done: getChatroomMembersDone
});
function getChatroomMembersDone(error, obj) {
  console.log('get chat room members' + (!error?'succeeded':'failed’), error, obj.members);
}

Get information of chat room members

  • accounts: List of accounts to be queried. At most 20 accounts can be queried each time.
chatroom.getChatroomMembersInfo({
  accounts: ['account1', 'account2'],
  done: getChatroomMembersInfoDone
});
function getChatroomMembersInfoDone(error, obj) {
  console.log('get chat room member information' + (!error?'succeeded':'failed’), error, obj);
}

Manage chat room members

There are APIs as below:

Designate an administrator

chatroom.markChatroomManager({
  account: 'account',
  isAdd: true,
  done: markChatroomManagerDone
});
function markChatroomManagerDone(error, obj) {
  console.log('add chat room manager' + (!error?'succeeded':'failed'), error, obj.member);
}

Designate ordinary members

chatroom.markChatroomCommonMember({
  account: 'account',
  level: 1,
  done: markChatroomCommonMemberDone
});
function markChatroomCommonMemberDone(error) {
  console.log('set chat room ordinary members' + (!error?'succeeded':'failed’), error);
}

Set a blocklist of a chat room

  • The member who is added to a blocklist cannot enter the chat room.
  • account: Account to be configured
  • isAdd: true is to add; false is to remove.
  • custom: Extension field. If it is not empty, this field will be the value of attach.custom in Chat room notification message that is received by other members.
  • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
chatroom.markChatroomBlacklist({
  account: 'account',
  isAdd: true,
  done: markChatroomBlacklistDone
});
function markChatroomBlacklistDone(error, obj) {
  console.log('add chat room blacklist' + (!error?'succeeded':'failed’), error, obj.member);
}

Specify the list of members who are muted in a chat room

  • The member who is added to mute list cannot send message in the chat room.
  • account: Account to be configured
  • isAdd: true is to add; false is to remove.
  • custom: Extension field. If it is not empty, this field will be the value of attach.custom in Chat room notification message that is received by other members.
  • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
chatroom.markChatroomGaglist({
  account: 'account',
  isAdd: true,
  done: markChatroomGaglistDone
});
function markChatroomGaglistDone(error, obj) {
  console.log('add chat room mute list' + (!error?'succeeded':'failed'), error, obj.member);
}

Temporarily mute members in a chat room

  • When a user is Temporarily mute members in a chat room, all members will receive a Chat room notification message of 'addTempMute' or 'removeTempMute' type.
  • account: Account
  • duration: Mute duration, unit: second. 0 is to unmute.
  • needNotify: It determines whether it is required to issue related notification message.
  • custom: Extension field. of corresponding notification message
chatroom.updateChatroomMemberTempMute({
  account: 'account',
  duration: 60,
  needNotify: true,
  custom: 'biu',
  done: updateChatroomMemberTempMuteDone
})
function updateChatroomMemberTempMuteDone(error, obj) {
  console.log('set Temporary mute + (!error?'succeeded':'failed’), error, obj);
}

Remove a chat room member

  • account: Account to be kicked out
  • custom: Extension field. If it is not empty, this field will be the value of attach.custom in Chat room notification message that is received by other members, as well as value of the parameter custom returned to the callback ondisconnect that is received by removed member.
  • We recommend creating user profile in JSON format. If it is not JSON format, other clients may abandon the information, although Web client will receive it ordinaryly.
  • When a user is kicked out of chat room, all members will receive a Chat room notification message of 'kickMember' type.
chatroom.kickChatroomMember({
  account: 'account',
  done: kickChatroomMemberDone
});
function kickChatroomMemberDone(error, obj) {
  console.log('remove members' + (!error?'succeeded':'failed’), error, obj);
}

Chat room queue service

Add elements to chat room queue

  • Method name: queueOffer
  • Parameter:
    • elementKey: string type, element key name
    • elementValue: string type, element content
    • transient: boolean type. It determines that added element is deleted after account is offline or leave the chat room.
    • done: Callback function returned after completion. The first parameter is error.
  • Example:
  chatroom.queueOffer({
    elementKey: `account`,
    elementValue: JSON.stringify({
      nick: `nickname`,
      webrtc: 1
    }),
    transient: true,
    done (err, obj, content) {
      if (err) {
        console.error(err)
      }
    }
  })

Delete elements in chat room queue

  • Method name: queuePoll. If it is empty, the first element is taken.
  • Parameters:
    • elementKey: string type, element key name to be deleted
    • done: Callback function returned after completion. The first parameter is error.
  • Example:
  chatroom.queuePoll({
    elementKey: `account`,
    done (err, obj, content) {
      if (err) {
        console.error(err)
      }
    }
  })

Get a list of chat room queue

  • Method name: queueList
  • Parameters:
    • done: Callback function returned after completion. The first parameter is error. The third parameter is the returned result.
  • Example:
  chatroom.queueList({
    done (err, obj, content) {
    if (err) {
      console.error(err)
    }
    console.log(content)
    if (content && content.queueList) {
      queueCount = 0
      for (let i = 0; i < content.queueList.length; i++) {
        let queue = content.queueList[i]
        console.log(queue)
        queueCount++
      }
    }
    }
  })

Update chat room queue in batches

If the element is added by user A and later updated by user B, the element is owned by user B.

  • Method name: queueChange
  • Parameters:
    • elementMap: object type. It is to update key-value pair (i.e. elementKey & elementValue, with max. 128 bytes for elementKey and max. 4096 bytes for elementValue) of element in batches. At most 100 pairs are updated for once.
    • needNotify: boolean type. It determines whether it is required to send broadcast notification.
    • notifyExt: string type, custom field in notification, with length limit of 2048.
    • done: Callback function returned after completion. The first parameter is error. The second is input parameter. The third parameter is returned result (without elementKey list).
  • Example:
  chatroom.queueOffer({
    elementMap: {
      elementKey1: elementValue2,
      elementKey3: elementValue4,
    },
    needNotify: true,
    notifyExt: 'Update queue in batch',
    done (err, obj, content) {
      if (err) {
        console.error(err)
      }
    }
  })

View the first element in chat room queue

  • Method name: peak
  • Parameters:
    • done: Callback function returned after completion. The first parameter is error. The third parameter is the returned result.
  • Example:
  chatroom.peak({
    done (err, obj, content) {
    if (err) {
      console.error(err)
    }
    console.log(content)
    }
  })

Clear chat room queue

  • Method name: drop
  • Parameters:
    • done: Callback function returned after completion. The first parameter is error.
  • Example:
  chatroom.drop({
    done (err, obj, content) {
    if (err) {
    console.error(err)
    }
    }
  })

Chat room queue notification

The alteration in chat room queue will be notified in the chat room notification message.

  function onChatroomMsgs (msgs) {
  let self = this
  msgs.forEach(msg => {
    if (msg.type === 'notification') {
    let attach = msg.attach
    let qc = attach.queueChange || {}
    switch (attach.type) {
    case 'updateQueue':
      if (qc.type === 'OFFER') {
      console.log(qc)
      } else if (qc.type === 'POLL') {
      console.log(qc)
      } else if (qc.type === 'DROP') {
      console.log(qc)
      } else if (qc.type === 'PARTCLEAR') {
      console.log(qc)
      }
      break
    case 'batchUpdateQueue':
      console.log(qc)
    }
    break
    }
  })
  }
Was this topic helpful?
Yes
No
  • Overview
  • Get the server address of a chat room
  • Initialize a chat room
  • Leave a chat room
  • Switch a chat room
  • Update chat room configurations
  • Clear a chat room instance
  • Chat room information object
  • Get chat room information
  • Update chat room information
  • Update my profile in chat room
  • Chat room message
  • Chat room message object
  • Chat room message types
  • Types of chat room notification messages
  • Send chat room messages
  • Send text messages
  • Preview files
  • Send file messages
  • Send location messages
  • Send tip messages
  • Send custom messages
  • Send configuration options of chat room messages
  • Get the message history
  • Chat room members
  • Chat room member object
  • Types of chat room members
  • Get a list of chat room members
  • Get information of chat room members
  • Manage chat room members
  • Designate an administrator
  • Designate ordinary members
  • Set a blocklist of a chat room
  • Specify the list of members who are muted in a chat room
  • Temporarily mute members in a chat room
  • Remove a chat room member
  • Chat room queue service
  • Add elements to chat room queue
  • Delete elements in chat room queue
  • Get a list of chat room queue
  • Update chat room queue in batches
  • View the first element in chat room queue
  • Clear chat room queue
  • Chat room queue notification