chat_js_sdk
Updated: 2022-06-27 18:57:34
Overview
This SDK is used for integrating POLYV live streaming services on the web, including viewing web-based live streams initiated by Cloud Classroom and Live Assistant, as well as the POLYV chat room service. It is compatible with both PC and mobile devices.
DEMO URL
· demo
Example Code
Quick Start
Step 1: Import Chat Room CSS and JS
<link rel="stylesheet" href="https://player.polyv.net/jssdk/polyv-chatroom.min.css">
<script src="https://player.polyv.net/jssdk/polyv-chatroom.min.js"></script>
Step 2: Create HTML Elements for Initializing the Chat Room
<div id="wrap"></div>
Step 3: Request a Token
First, request the following API to obtain the token and mediaChannelKey, then pass them to the JS-SDK.
/live/api/channel/operate/get_chat_token
Step 4: Create an SDK Instance
var chatroom = new PolyvChatRoom({
roomId: '268682',
userId: '153075602311',
nick: '游客',
pic: 'http://livestatic.videocc.net/assets/wimages/missing_face.png',
token: token,// 请求token返回
mediaChannelKey: mediaChannelKey,// 请求token返回
version: '2.0',
container: '#wrap',
width: 300,
height: 600,
userType: '',
roomMessage: function(data) {
// TODO
// data为聊天室socket消息,当有聊天室消息时会触发此方法
console.log(data);
}
});
