chat_js_sdk_api
Creating an Instance
var chatroom = new PolyvChatRoom({
roomId: '268682',
...
});
Related Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| roomId | true | string | Channel ID |
| userId | true | string | Unique user ID, generation suggestion |
| pic | true | string | User avatar, must be an absolute URL starting with 'http' or 'https' |
| nick | false | string | User nickname, defaults to 'Guest' |
| actor | false | string | User title, defaults to 'Student' |
| userType | false | string | User type, defaults to student. In a tri-screen scenario, students must set to slice. Regular student: student Cloud classroom student: slice Instructor: teacher Administrator: manager Teaching assistant: assistant Guest: guest |
| accountId | false | string | Live account userId, used to enable global forbidden words and image emoji message features |
| token | true | string | Verification code |
| mediaChannelKey | true | string | Co-hosting related parameters |
| version | false | string | Version number, defaults to 2.0 |
| roomMessage | false | function | Chat room message callback function |
| enableReplay | false | boolean | Enable content replay, defaults to false |
| enableRedpack | false | boolean | Whether to display red packet messages |
| handlerEvent | false | function | Callback for clicking red packet messages, (type, data) type: '', red packet event type, optional: clickRedpacket data: '' current clicked red packet data |
| customRedpackLabel | false | object | Red packet text configuration { passwordTitle: 'Enter password to receive red packet (custom)', noReceive: 'Receive red packet (custom)', normalType: 'Normal red packet (custom)', passwordType: 'Password red packet (custom)', rainType: 'Red packet rain (custom)', } |
| customRedpackImg | false | object | Red packet image configuration { normalEntranceImg: '', normal red packet cover image passwordEntranceImg: '', password red packet cover image rainEntranceImg: '', red packet rain cover image } |
| container | false | string | DOM selector, HTML element, used to embed the default chat room style |
| isMobile | false | boolean | Whether to use mobile styles, default value determines if mobile based on current UA |
Note: The following parameters only take effect when the container parameter is passed.
| Parameter Name | Required | Type | Description |
|---|---|---|---|
| width | false | number | Container width, default 300px |
| height | false | number | Container height, default 600px |
| showUserList | false | boolean | Whether to display the online user list. Enabled by default on PC, disabled by default on mobile. When disabled, the online list object in tabData will not be displayed even if present. |
| enableSetNickname | false | boolean | Whether to enable the nickname setting feature, default false |
| enableWelcome | false | boolean | Whether to enable welcome messages, default true |
| enableFlower | false | boolean | Whether to enable the flower sending feature, default true |
| enableLike | false | boolean | Whether to enable likes, default true |
| enableOnlyTeacher | false | boolean | Whether to enable the "view teacher only" feature, default true |
| enableBulletin | false | boolean | Whether to enable announcements, default true |
| enableAsk | false | boolean | Whether to enable questions, default true |
| tabData | false | array | Custom menu bar |
| customChatColor | false | object | Custom message colors |
| apiPrefix | false | object | Custom domain name |
| enableRewardAnimation | false | boolean | Whether to enable reward animation effects, default true |
| enableUpdatePageviews | false | boolean | Whether to enable page view updates, default true |
| getChatRecordBySessionIdOptions | false | object | Retrieve chat records by sessionId Description |
| getChatRecordByTimeOptions | false | object | Retrieve chat records by time Description |
| showOwnInfo | false | boolean | Whether to display own chat message avatar, title, and nickname, default false |
| enableViewBigPicture | false | boolean | Whether to support viewing large images, default false |
| customViewPicture | false | function | Custom method for viewing large images, requires enableViewBigPicture to be enabled |
| customMessageRender | false | object | Custom message rendering function object Description |
| enableBadWordsTip | false | boolean | Whether to enable prohibited word tips, default false |
| enableCustomMessage | false | boolean | Whether to display custom messages sent via HTTP API, default false |
| enableFontSize | false | boolean | Whether to enable font size settings, default false. Supports three font sizes: sm:12px, md:14px, lg:16px |
| enableReplay | false | boolean | Whether to enable quote reply, default false |
| newMsgTipText | false | string | Custom Chinese text for new message tips |
| newMsgTipTextEn | false | string | Custom English text for new message tips |
| lang | false | string | Language selection, options: 'zh_CN'|'en', default: 'zh_CN' |
| param4 | false | string | POLYV system parameter |
| param5 | false | string | POLYV system parameter |
userId Generation Recommendations
userId is the unique identifier for users in the chat room. If two users with the same userId log into the chat room, the latter will kick the former out. Therefore, the userId of different chat room users must be unique. The generation recommendations are as follows:
- If you have a user system, use the user ID from your user system as the
userIdfor logging into the chat room. - If you do not have a user system, generate a highly random value on the backend as the
userIdfor logging into the chat room, such as "timestamp + 5-digit random number", uuid, etc., and save thisuserIdto a cookie or local storage (localStorage or sessionStorage) to avoid regenerating theuserIdafter each page refresh.
Custom Menu Bar
tabData: An array of objects, each containing two properties: name and type. By default, it includes a chat tab.
name: Menu bar name
type: The type of menu bar. If it is not a built-in type, a div element with no content will be embedded into the page.
Already built-in types
| type | Description |
|---|---|
| chat | Interactive Chat |
| user-list | Online User List |
| ask | Ask a Question |
Custom Message Colors
Note: Modify the message font/background color, can be adjusted for yourself/regular users/admins/instructors/assistants/guests.
| Parameter | Required | Type | Description |
|---|---|---|---|
| selfBgColor | false | string | Background color of own messages, default is #8bc34a |
| selfColor | false | string | Color of own messages, default is #fff |
| otherBgColor | false | string | Background color of regular user messages, default is #fff |
| otherColor | false | string | Color of regular user messages, default is #546e7a |
| specialBgColor | false | string | Background color of special user messages, can uniformly set background for admin/instructor/TA/guest, default is #fff |
| specialColor | false | string | Color of special user messages, can uniformly set color for admin/instructor/TA/guest, default is #2196f3 |
| managerBgColor | false | string | Background color of admin messages |
| managerColor | false | string | Color of admin messages |
| teacherBgColor | false | string | Background color of instructor messages |
| teacherColor | false | string | Color of instructor messages |
| assistantBgColor | false | string | Background color of TA messages |
| assistantColor | false | string | Color of TA messages |
| guestBgColor | false | string | Background color of guest messages |
| guestColor | false | string | Color of guest messages |
Custom Domain
| Parameter | Required | Type | Description |
|---|---|---|---|
| socketHost | false | string | Chat room domain, default is chat.polyv.net |
| chatApi | false | string | Chat room API domain, default is apichat.polyv.net |
getChatRecordBySessionIdOptions Object Description
| Property | Required | Type | Description |
|---|---|---|---|
| enable | false | boolean | Whether to enable retrieving and displaying chat records by sessionId, defaults to false |
| sessionId | - | string | Session ID, required when enable is true |
| connect | false | boolean | Whether to connect to the chat room, defaults to false; when false, features requiring the chat room (e.g., asking questions) are unavailable |
| page | false | string | Current page number, defaults to 1 |
| size | false | string | Number of data items displayed per page, defaults to 10 |
getChatRecordByTimeOptions Object Description
| Property | Required | Type | Description |
|---|---|---|---|
| enable | false | boolean | Whether to enable retrieving chat records based on the provided start time and display them, defaults to false |
| startTime | - | number | 13-digit timestamp. Start time, required when enable is true |
| endTime | - | number | 13-digit timestamp. End time, required when enable is true |
| connect | false | boolean | Whether to connect to the chat room, defaults to false. When false, features requiring the chat room (such as asking questions) are also unavailable |
| page | false | string | Current page number, defaults to 1 |
| size | false | string | Number of data items displayed per page, defaults to 10 items per page |
customMessageRender Object Description
Format: {[type]: function(data){/** 将要渲染的内容返回给sdk内部进行渲染 */}}
type is the rendered message type, with possible values: 'custom'|'flowers'|'other'|'own'|'redpack'|'redpackResult'|'reward'|'system'
data is the message data
| Attribute Name | Description |
|---|---|
| custom | Custom message |
| flowers | Flower sending message |
| other | Other's message |
| own | Own message |
| redpack | Red packet message |
| redpackResult | Red packet claim message |
| reward | Reward message |
| system | System message |
Example
...
customMessageRender: {
custom: function(data) {
return '<div>' + data + '</div>';
}
}
...
Instance Methods
Send a quoted reply message: reply(id, content)
Description: Reply to a specific message
Example
// chatroom为此sdk实例对象
chatroom.reply('msg_id', '回复内容');
Parameters
id: String type, the ID of the message to reply to
content: String type, the content of the reply
Return Value
Returns a Promise object
Kick Out a User: kickUser(userId, sign)
Description: Kicks a user out of the chat room.
Example
chatroom.kickUser('userId', sign);
Parameters
userId: String type, the userId of the user to be kicked out
sign: String type, signature (rules)
Return Value
Returns a Promise object.
Unkick a User: unKickUser(userId, sign)
Description: Unkick a user
Example
chatroom.unKickUser('userId', sign);
Parameters
userId: String type, the userId of the user to be unkicked
sign: String type, signature (rules)
Return Value
Returns a Promise object
Others
Get the chat object
var chat = chatroom.chat;
Get Socket Object
var socket = chat.socket;
Send Chat Message
// 发送文本消息
chat.send('hello');
// 回复消息
chat.send(
'回复的消息内容',
{
id: '被回复的消息 id',
content: '被回复的消息内容',
nick: '被回复的发言者昵称'
},
);
// 发言成功后回调
chat.send('hellow', null, (id) => {
console.log('发送成功,消息 id:', id);
});
Get Chat History
Get chat history based on options such as message index position.
chat.getChatHistory({
start: 0,
end: 10,
})
.then(function (data) {
// TODO:
console.log(data);
});
Parameter Description
| Parameter | Required | Optional Values | Description |
|---|---|---|---|
| start | false | - | Start index, defaults to 0 |
| end | false | - | End index, defaults to 10 |
| getSpecialMessage | false | 0/1 | Whether to only retrieve messages from special identities; pass 1 to retrieve only messages from special identities, defaults to 0 |
// 原有获取历史消息记录接口已废弃
chat.getHistoryMessage(start, end)
.then(function (data) {
// TODO:
console.log(data);
});
Get chat history by session ID (sessionId)
chat.getHistoryMessageBySessionId({ sessionId, page , size })
.then(function(data) {
// TODO:
console.log(data);
});
Get chat history based on start time
chat.getHistoryMessageByTime({ startTime, endTime, page , size })
.then(function(data) {
// TODO:
console.log(data);
});
Parameter Description
| Parameter | Required | Description |
|---|---|---|
| start | false | Start index, default is 0 |
| end | false | End index, default is 10 |
Result Description
data is an array of objects, with the specific content as follows:
| Parameter | Type | Description |
|---|---|---|
| content | string | Text content of the message |
| id | string | ID of this record |
| time | number | Timestamp of the message, 13-digit millisecond timestamp |
| user | object | Speaker |
User Notes
| Parameter | Required | Type | Description |
|---|---|---|---|
| nick | true | string | Nickname |
| pic | true | string | Avatar |
| userId | true | string | Unique ID |
| clientIp | true | string | IP Address |
| banned | true | boolean | Is Muted |
| userType | true | string | Type |
| userSource | false | string | Source |
| actor | false | string | Title |
| roomId | true | string | Room ID |
| channelId | true | string | Channel ID |
| uid | true | string | Socket Connection Unique ID |
Note:
clientIpdefaults to empty; currently, returning a content value is not supported.Possible values for
userTypeinclude: empty,student,slice,teacher,manager,assistant,guest,viewer, etc.
Get Online List
chat.getUserList(page, len)
.then(function (data) {
// TODO
console.log(data);
});
Parameter Description
| Parameter | Required | Description |
|---|---|---|
| page | false | Page number, default 1 |
| len | false | Number of items, default 100 |
Result Description
data is an object with the following content:
| Parameter | Type | Description |
|---|---|---|
| count | number | Number of online users |
| userlist | array | Array of online student objects |
userlist Description
For detailed explanation of the userlist object array elements, please refer to the user description in the "Get Chat History" method.
Retrieve Audience Question History
chatroom.chatApi.getAskHistoryByUserId()
.then(function (data) {
// TODO
console.log(data);
});
Parameter Description
- The input parameter can be an object or omitted; if omitted, it defaults to the parameters used during SDK initialization.
- When passed as an object, it can include the following fields:
| Parameter | Required | Description |
|---|---|---|
| roomId | false | Room ID |
| userId | false | User ID |
| token | false | Chat room token |
| page | false | Page number, >= 1 |
| size | false | Items per page, >= 1 and <= 100 |
Result Description
data is an object with the following content:
| Parameter | Type | Description |
|---|---|---|
| page | number | Page number |
| size | number | Records per page |
| totalPage | number | Total pages |
| totalCount | number | Total records |
| list | array | List of questions |
list Description
| Parameter | Type | Description |
|---|---|---|
| content | string | Message content |
| id | string | Message ID |
| time | number | Message time |
| user | object | Refer to the user description in the "Get Chat History" method |
sendMessage
Note: This message is triggered after you speak. It will be returned in roomMessage and can also be monitored through the chat object.
Example:
chat.on(chat.events.SEND_MESSAGE, (event, data) => {
// TODO
});
Return Data
EVENT: "sendMessage"
content: "自己发言"
currentUser: true
custom: false
formatTime: "2019-04-25 18:06"
imgchat: false
mySelfSend: true
reward: false
time: 1556186781080
user: {
nick: "polyv",
pic: "http://livestatic.videocc.net/assets/wimages/missing_face.png",
userId: "1530756023116",
roomId: "",
channelId: ""
}
Interactive Feature Socket Message Description
Login Message
LOGIN:
登录消息,登录房间的时候服务器会广播这一消息
Callback data returned by the listener:
{
"EVENT":"LOGIN",
"onlineUserNumber":3,
"user": {
"clientIp":"59.42.43.28",
"nick":"广州观众/32199",
"pic":"//livestatic.videocc.net/v_60/assets/wimages/missing_face.png",
"roomId":"100781",
"uid":"CxJj8Ap3C9jN1UHKAJ_V",
"userId":"1499917692338"
"userType": ""
}
}
Description
| Parameter | Type | Description |
|---|---|---|
| onlineUserNumber | number | Current total number of online users in the room |
| clientIp | string | User IP |
| nick | string | User nickname |
| pic | string | User avatar |
| roomId | string | Room ID |
| uid | string | ID assigned by socket |
| userId | string | Unique user identifier |
| userType | string | User type. Currently includes: 'teacher' Teacher 'assistant' Teaching Assistant 'manager' Administrator 'slice' Cloud Classroom Student |
Logout Message
LOGOUT
说明:登出消息,有人离开房间(包括刷新页面)时服务器会广播这一消息
Monitor callback returns data:
EVENT: "LOGOUT",
onlineUserNumber: 3,
uid: "I_o3f4sHDzAHM4LVAJTX"
| Parameter | Type | Description |
|---|---|---|
| onlineUserNumber | number | Total online users in the room |
| uid | string | Socket.id of the leaving user |
Receiving Messages from Others
SPEAK:
说明:发言,接收别人的发言消息(不包括自己)
Send:
socket.emit('message', JSON.stringify({
EVENT: 'SPEAK',
values: [value], //发言内容
roomId: roomId //当前房间号
}));
Field Description:
| Name | Required | Type | Description |
|---|---|---|---|
| EVENT | Yes | string | Event name |
| values | Yes | array | Speech content; the submitted speech is the first element of the array |
| roomId | Yes | string | Corresponding channel ID |
Callback data returned:
{
"EVENT": "SPEAK",
"id": "f1e4a960-6abc-11e7-ac0a-379e251bb30e",
"time": 1500274540278,
"user": {
"clientIp": "59.42.40.89",
"nick": "rururu",
"pic":"//livestatic.videocc.net/v_60/assets/wimages/missing_face.png",
"roomId": "100781",
"uid": "yP-HnXTEZyToxP0TAGCS",
"userId": "1500274526077",
"userType": ""
},
"values": ["sadasd"]
}
| Parameter | Description |
|---|---|
| id | Unique message ID |
| time | Timestamp |
| user | Speaker |
| values | Message content |
System Announcement
GONGGAO:
说明:当管理员发言时,服务器会将管理员的消息做为公告处理,当重新进入页面时,如有公告,服务器会广播这一消息。
Data returned by the listener callback:
{
"EVENT": "GONGGAO",
"content": "POLYV保利威视"
}
| Parameter | Description |
|---|---|
| content | Announcement content |
General Announcement
BULLETIN
说明:后台设置的公告消息,当重新进入页面时,如有公告,服务器会广播这一消息。
Callback data returned:
EVENT: "BULLETIN",
content: "???/",
roomId: "105240"
| Parameter | Type | Description |
|---|---|---|
| content | string | Announcement content |
| roomId | number/string | Current room ID (this message may not include roomId when re-entering the room) |
Flower Sending Message
FLOWERS:
说明:送花
The number returned by the listener callback
{
"EVENT":"FLOWERS",
"nick":"广州观众/81366",
"uimg":"//livestatic.videocc.net/v_60/assets/wimages/missing_face.png"
}
| Name | Description |
|---|---|
| nick | Sender's nickname |
| uimg | Sender's avatar (new) |
Like Notification
LIKES:
说明: 点赞
Data returned by the listener callback:
{
"EVENT":"LIKES",
"count":160,
"nick":"广州观众/81366"
}
| Parameter | Description |
|---|---|
| count | Current total number of likes. If this attribute is not passed when the message occurs, this attribute is not returned. |
| nick | Nickname of the person who liked. |
Mute
SHIELD:
说明: 禁言
Data returned by the listener callback:
Note: Only one of userId or ip will be returned.
{
EVENT: 'ADD_SHIELD',
value: '', // 被禁言用户userId值或ip值
data: {
banType: 'userId/ip', // 禁言类型 userId/ip
userId: '', // 被禁言用户userId值
ip:'', // 被禁言用户ip值
}
}
Unmute
REMOVE_SHIELD:
说明: 解除禁言
Callback data returned:
解除userId
{
EVENT: 'REMOVE_SHIELD',
value: '', // 被禁言用户userId值
data: {
banType: 'userId', // 禁言类型
userId: '' // 被禁言用户userId值
}
}
解除ip
{
EVENT: 'REMOVE_SHIELD',
value: '',// 被禁言用户ip值
data: {
banType 'ip', // 禁言类型
ip: '' // 被禁言用户ip值
}
}
Kick User
KICK:
说明: 踢人
Callback return data:
{
"EVENT":"KICK",
"user": {
"clientIp":"59.42.40.89",
"nick":"林林林",
"pic":"//livestatic.videocc.net/v_60/assets/wimages/missing_face.png",
"roomId":"100781",
"uid":"118GWVRA24PR14coA3bz",
"userId":"1500275476199",
"userType":""
}
}
| Parameter | Description |
|---|---|
| user | Kicked user object |
Unban/Kick Removal
UNKICK:
说明: 解除踢人
Callback data returned by the listener:
解除userId
{
"EVENT":"UNKICK",
"kickType": "userId"
"userId": "1500275476199" //踢出值
}
解除ip
{
"EVENT":"UNKICK",
"kickType": "ip"
"ip": "127.0.0.1" //踢出值
}
| Parameter | Description |
|---|---|
| kickType | Kick method |
| ip | Kick IP |
| userId | Kick userId |
Delete a Chat Record
REMOVE_CONTENT:
说明:删除某条聊天记录,需要通过HTTP接口调用
Callback data returned:
{
"EVENT":"REMOVE_CONTENT",
"content":"asd",
"id":"54b04e90-6acd-11e7-abcd-a985dda00975",
"roomId":"100781"
}
| Parameter | Description |
|---|---|
| content | Deleted content |
| id | ID of the deleted content |
| roomId | Room ID |
Clear Chat History
REMOVE_HISTORY:
说明:清空聊天记录
Callback data returned:
{
"EVENT":"REMOVE_HISTORY"
}
Close Chat Room
CLOSEROOM:
说明:关闭聊天室
Callback data returned:
{
"EVENT":"CLOSEROOM",
"value": {
"closed":true,
"roomId":"100781"
}
}
| Parameter | Description |
|---|---|
| closed | true for closed, false for open |
| roomId | Room ID |
Close Danmaku
CLOSE_DANMU:
说明:关闭弹幕
Callback data returned:
{
"EVENT": "CLOSE_DANMU",
"isClose": true
}
| Parameter | Description |
|---|---|
| isClose | true for closed, false for open |
Send Custom Message via Interface
Note: Send custom messages via the API interface Send Custom Message
Custom Message Reception Event
CUSTOMER_MESSAGE:
Note: Custom message receiving event
Callback data returned:
{
"EVENT" : "CUSTOMER_MESSAGE",
"id":"30764b70-33cb-11ed-b2d4-85c1d25442a0",
"roomId" : 100781,
"image":"http://livestatic.videocc.net/assets/wimages/pc_images/logo.png",
"content" : "这是一条自定义消息" ,
"user" : {}
}
| Parameter | Description |
|---|---|
| roomId | Room ID |
| image | Message image (determined by whether the sent message contains an image) |
| content | Message content |
Answer Sheet
Note: The answer sheet includes two functions: "Quick Q&A" and "Answer Sheet".
GET_TEST_QUESTION_CONTENT
Description: Retrieve the content of answer sheet questions and options.
Response:
| Parameter | Type | Description |
|---|---|---|
| questionId | string | Question ID |
| itemType | string | Answer type, 1 for quick Q&A, 0 for answer sheet |
| type | string | Question type (not applicable for quick Q&A) R for single choice C for multiple choice S for rating |
| answer | string | Question answer; multiple answers are concatenated directly, e.g., if A and B are selected, return AB |
| option1 | string | Option 1, minimum 2 options, maximum 5. Note: When importing questions via "Import Question Bank", 5 additional options (option6~option10) are added, all with null values |
| option2 | string | Option 2 |
| option3 | string | Option 3 |
| option4 | string | Option 4 |
| option5 | string | Option 5 |
| title | string | Question title |
| hash | string | Checksum |
| ts | string | Timestamp |
| tips1 | string | Prompt 1, only available when the question type is rating |
| tips2 | string | Prompt 2 |
| tips3 | string | Prompt 3 |
| tips4 | string | Prompt 4 |
| tips5 | string | Prompt 5 |
GET_TEST_QUESTION_RESULT
Description: Get the answer sheet results.
Response:
| Parameter | Type | Description |
|---|---|---|
| questionId | string | Question ID |
| result | object | Answer result |
| content | object | Question details |
Answer Result Attribute Description:
| Parameter | Type | Description |
|---|---|---|
| singleResult | array | Number of times each option was selected |
| total | number | Total number of respondents |
| answer | string | Answer |
| rightUser | array | Users who answered correctly |
| faultUser | array | Users who answered incorrectly |
| itemType | string | Question type, 1 for quick quiz, 0 for answer sheet |
| type | string | Question type (not applicable for quick quiz) R for single choice C for multiple choice S for rating |
ANSWER_TEST_QUESTION
Note: Send the answer.
Request:
socket.emit('message', JSON.stringify({
EVENT: 'ANSWER_TEST_QUESTION',
roomId: channelId,
nick: nick,
userId: userId,
option: result,
questionId: questionId
}));
Field Description:
| Parameter | Required | Type | Description |
|---|---|---|---|
| EVENT | true | string | Event name |
| roomId | true | string | Room ID |
| nick | true | string | Nickname |
| userId | true | string | Student ID |
| option | true | string | Selected answer; for multiple choice, concatenate answers directly. For example, if A and B are selected, the option is AB |
| questionId | true | string | Question ID |
Consultation Questions
S_QUESTION
Note: Content of student questions
Response:
{
EVENT: 'S_QUESTION',
roomId: roomId,
user: {
nick: nick,
pic: pic,
userId: userId,
userType: 'student'
},
content: value
}
Field Description:
| Parameter | Description |
|---|---|
| EVENT | Event name |
| roomId | Room ID |
| user | User info |
| content | Question content |
User Information Description
| Parameter | Description |
|---|---|
| nick | Nickname |
| pic | Avatar |
| userId | Student ID |
| userType | Type |
T_ANSWER
Note: Teacher/Administrator/Teaching Assistant replies to questions
Response:
{
EVENT: 'T_ANSWER',
roomId: roomId,
user: {
nick: nick,
pic: pic,
userId: userId,
userType: 'teacher',
actor: actor
},
s_userId: s_userId
content: value
}
Field Description:
| Parameter | Description |
|---|---|
| EVENT | Event name |
| roomId | Room ID |
| user | User info |
| s_userId | ID of the replied student |
| content | Reply content |
User Information Description
| Parameter | Description |
|---|---|
| nick | Nickname |
| pic | Avatar |
| userId | Instructor/Assistant/Admin ID |
| userType | Type: teacher/assistant/manager |
| actor | Title |
Survey
START_QUESTIONNAIRE
Note: Start the survey
Response:
| Parameter Name | Type | Description |
|---|---|---|
| questionnaireId | string | Questionnaire ID |
| content | object | Questionnaire content |
Questionnaire Content Description
| Parameter Name | Type | Description |
|---|---|---|
| questionnaireId | string | Questionnaire ID |
| questionnaireTitle | string | Questionnaire Title |
| createdTime | number | Questionnaire creation time, 13-digit millisecond timestamp |
| status | string | Questionnaire status: saved, published, forbidden |
| questions | array | Question information, an array of objects |
Problem Information Description
| Parameter | Type | Description |
|---|---|---|
| questionId | string | Question ID |
| name | string | Question title |
| type | string | Question type, R: Single choice, C: Multiple choice, Q: Open-ended, X: Star rating (5 stars), S: Score rating (10 points), J: True/False |
| answer | string | Question answer |
| required | string | Whether required, Y: Yes, N: No |
| scoreEnabled | string | Whether it is a scored question, Y: Yes, N: No |
| score | number | Score |
| option1 | string | Question option |
| option2 | string | Question option |
| option3 | string | Question option |
| option4 | string | Question option |
| option5 | string | Question option |
| option6 | string | Question option |
| option7 | string | Question option |
| option8 | string | Question option |
| option9 | string | Question option |
| option10 | string | Question option |
ANSWER_QUESTIONNAIRE
Description: Students submit questionnaire answers.
Request:
socket.emit('message', JSON.stringify({
EVENT: 'ANSWER_QUESTIONNAIRE',
roomId: roomId,
nick: nick,
userId: userId,
questionnaireId: questionnaireId,
answer: [
{
questionId: 'f8bbo3rhrq',
answer: 'A'
},
{
questionId: 'f8bbo3rhlw',
answer: "BC"
},
{
questionId: 'f8bbo3rhht',
answer: 'polyv'
}
]
}));
Field Description:
| Parameter | Required | Type | Description |
|---|---|---|---|
| EVENT | true | string | Event name |
| roomId | true | string | Room ID |
| nick | true | string | Student nickname |
| userId | true | string | User ID corresponding to the student |
| questionId | true | string | Question ID |
| answer | true | array | Student's answer, an array of objects |
Answer Field Description:
| Parameter | Type | Description |
|---|---|---|
| questionId | string | Question ID |
| answer | string | Answer. For multiple-choice questions, it is A, B, C, or D; for essay questions, it is the content entered by the student in the input field. |
Supplement: More Question Types - Answer Format Please Refer to
STOP_QUESTIONNAIRE
Note: The teacher has stopped the survey.
Response:
| Parameter Name | Type | Description |
|---|---|---|
| questionnaireId | string | Questionnaire ID |
QUESTIONNAIRE_ACHIEVEMENT
Note: When the instructor clicks the "Send Survey Results" button, if a student has responded to the survey, that student will receive a survey ranking result event on their viewing end.
Response:
| Name | Type | Description |
|---|---|---|
| EVENT | string | Value is QUESTIONNAIRE_ACHIEVEMENT |
| roomId | string | Room ID |
| totalScore | number | Total score of the student for this questionnaire |
| userId | string | User ID of the student |
| timestamp | number | Timestamp when the student submitted the questionnaire answers |
| questionnaireId | string | Questionnaire ID |
| ranking | number | Ranking of the student's score in this questionnaire, starting from 1 |
Custom Messages
Note: Customers can define their own messages to broadcast based on their business needs.
Request
socket.emit('customMessage', JSON.stringify({
EVENT: 'myMessage',
version: '1.0',
emitMode: 1,
roomId: roomId,
data: {
company: 'polyv'
},
tip: '我的自定义消息',
}));
Field Description:
| Parameter | Required | Type | Description |
|---|---|---|---|
| EVENT | true | string | Custom message type, event character length not exceeding 20 |
| version | true | number | Custom message version |
| emitMode | false | number | Whether to broadcast to self: 0 means broadcast to everyone including self, 1 means broadcast to everyone except self, 2 means send only to self |
| roomId | true | number | Corresponding channel ID |
| data | true | object | Custom message content, defined by the client |
| tip | true | string | Prompt message |
Response:
| Parameter | Type | Description |
|---|---|---|
| EVENT | string | Custom message type, event character length not exceeding 20 |
| version | number | Custom message version |
| emitMode | number | Whether to broadcast to self: 0 means broadcast to everyone including self, 1 means broadcast to everyone except self, 2 means send only to self |
| roomId | number | Corresponding channel ID |
| id | string | Message ID |
| user | object | User information |
| time | number | Timestamp |
| data | object | Custom message content, defined by the client |
| tip | string | Prompt text |
Check-in
SIGN_IN
Description: Initiate Check-in
Response:
| Parameter | Type | Description |
|---|---|---|
| EVENT | string | Value is SIGN_IN |
| roomId | string | Channel ID |
| data | object | Contains four properties: message: check-in text; limitTime: check-in duration (in seconds); sessionId: live session ID; checkinId: check-in session ID |
STOP_SIGN_IN
Note: End check-in
Response:
| Parameter | Type | Description |
|---|---|---|
| EVENT | string | Value is STOP_SIGN_IN |
| roomId | string | Channel ID |
TO_SIGN_IN
Description: Student Check-in
Response:
| Name | Type | Description |
|---|---|---|
| EVENT | string | Value is TO_SIGN_IN |
| roomId | string | Channel ID |
| checkinId | string | Check-in session ID |
| user | object | Check-in student info, containing two properties: nick: student nickname, userId: student ID |
Lottery Draw
Note: The lottery is initiated via an HTTP interface. The following messages are broadcast from the server to the page.
LotteryStart
Note: Start the lottery
Response:
| Parameter | Type | Description |
|---|---|---|
| EVENT | string | Value is LotteryStart |
| channelId | string | Channel ID |
| sessionId | string | Current live session ID |
| lotteryId | string | Current lottery session ID |
LotteryEnd
Note: End the lottery
Response:
| Parameter | Type | Description |
|---|---|---|
| EVENT | string | Value is LotteryEnd |
| channelId | string | Channel ID |
| sessionId | string | Current live session ID |
| lotteryId | string | Current lottery session ID |
| prize | string | Gift name |
| data | array | Winners, including basic winner information and the winning code winnerCode. If no winner, it is an empty array |
Example:
{
"EVENT":"LotteryEnd",
"channelId":"",
"sessionId":"fajrsh0uqj",
"lotteryId":"fapcpw06l2",
"prize":"耳机",
"data":[
{
"banned":false,
"channelId":"",
"clientIp":"",
"nick":"广州观众/97375",
"pic":"//livestatic.videocc.net/v_268/assets/wimages/missing_face.png",
"roomId":"",
"uid":"lbcCDoikWTniMk1pAMkI",
"userId":"1553597220784",
"userType":"student",
"winnerCode":"xXYMNZJR"
}
]
}
Others
To submit winner information, you need to call the HTTP interface. For details, see Lottery - Submit Winner Information.
Tip
Note: Tipping must be triggered via an HTTP interface. For details, see Tipping - Send Tipping Message.
REWARD
Note: Tipping
Response:
| Parameter | Type | Description |
|---|---|---|
| EVENT | string | Value: REWARD |
| roomId | string | Room ID |
| content | object | Reward content |
Donation Content Description:
| Parameter | Type | Description |
|---|---|---|
| unick | string | Nickname of the tipper |
| uimg | string | Avatar of the tipper |
| rewardContent | string | Reward content: gift name for gift tips, amount for cash tips |
| gimg | string | Gift image for gift tips, empty for cash tips |
Signature Generation Rules
md5(key+roomId)
For the value of key, please consult customer service.
