Polyv Help Center

Help Center

Get Chat Room Online List

Updated: 2022-08-17 18:12:42

API Description

1、通过频道号,获取聊天室在线列表

API URL

https://apichat.polyv.net/front/userlistExternal

Request Method

GET

API Constraints

  1. Each API request returns a maximum of 1000 records. It is recommended to return 100 records per request and use pagination.

  2. When the returned data volume is large, the request frequency interval should be greater than 10 seconds.

  3. The data includes information about virtual audience members.

Request Parameter Description

Parameter Required Type Description
roomId true String Room ID
page false Integer Page number, default is 1
len false String Number of records per page, default is 100, maximum is 1000
toGetSubRooms false Boolean Whether to retrieve users from sub-channels, true to retrieve, false not to retrieve
callback false Function Callback function to resolve frontend cross-origin requests

Response Result Decryption:

const aesjs = require('aes-js');
const Base64 = require('js-base64');
const md5 = require('md5');
 
function decrypt(encrypted, sign) {
  const encryptedBytes = aesjs.utils.hex.toBytes(encrypted);
  const key = str2ab(sign, 16);
  const iv = key;
  const aesCfb = new aesjs.ModeOfOperation.cbc(key, iv, 8);
  const decryptedBytes = aesCfb.decrypt(encryptedBytes);
 
  const decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
  return Base64.decode(decryptedText);
  function str2ab(str, len) {
    const bytes = aesjs.utils.utf8.toBytes(str);
    const bytesLen = bytes.length;
    if (bytesLen > len) {
      return bytes.slice(0, len);
    }
    return (
      [].concat(...(new Array(Math.ceil(len / bytesLen)).fill(bytes)))
    ).slice(0, len);
  }
}
 
function createApiSign(appSecret, data = {}, type = 'upper') {
  //1、把data里的数据按字典序排列
  //2、按照key+value进行拼接,在首尾分别加上appSecret
  //3、MD5加密,默认大写,当type=lower时,为小写
  let content = appSecret;
  const temp = Object.keys(data).sort();
  temp.forEach((item) => {
    if (item === 'sign') {
      return;
    }
    const v = data[item];
    content += item + (isObject(v) ? JSON.stringify(v) : v);
  });
  content += appSecret;
  const sign = md5(content);
  return type === 'lower' ? sign : sign.toLocaleUpperCase();
}
 
function isObject(obj){
return obj !== null && obj instanceof Object;
}
// 1、第一步,访问链接地址,获取返回内容
// http://apichat.polyv.net/front/userlistExternal?roomId=412738&page=1&len=100&hide=0&toGetSubRooms=true
 
const sign = createApiSign('polyvChatSignForExternal', { roomId: '412738', page: '1', len: '100', hide: '0', toGetSubRooms: 'true' }); // 接口请求的参数的签名
//2、第二步,将第一步的返回内容赋值给encrypted进行解析
const encrypted = 'fd1206646ea5e702852157';
console.log(decrypt(encrypted, sign));

Response Parameter Description

Parameter Type Description
count Integer Total number of users
userlist Array User objects (see user object description below)

User Object Description

Parameter Type Description
actor String Identity information, e.g., teacher, teaching assistant
banned Boolean Whether the user is muted
channelId String Channel ID
clientIp String User IP address
nick String Nickname
pic String Avatar
roomId String Room ID
uid String Socket ID
userId String User ID
userSource String Information source
userType String User type
assistant: Teaching assistant
student: Regular viewer
slice: Regular viewer
dummy: Virtual audience member
teacher: Instructor
guest: Guest
attendee: Seminar participant (only available when the channel scenario is a seminar)
manager: Live stream monitoring administrator
talent: Co-host (only available when the channel scenario is MR)

JavaScript Request Example

const formData = {
    roomId: '412738',
    page: 1,
    len: 100,
    hide: 0,
    toGetSubRooms: true,
};
ajax({
  url: 'https://apichat.polyv.net/front/userlistExternal',
  formData,
  type: 'get',
}).then(console.log);
```

### Response Example

Success Example

```json
{
  "count": 1,
  "userlist": [
    {
      "banned": false,
      "channelId": "412738",
      "clientIp": "",
      "nick": "广州观众/70375",
      "param4": "",
      "param5": "",
      "pic": "http://liveimages.videocc.net/defaultImg/avatar/viewer.png",
      "roomId": "412738",
      "uid": "XXl7pssG5JvcNzhbAAAU",
      "userId": "1621838373713",
      "userType": "slice"
    }
  ]
}
```
联系客服,在线咨询