zby-live-sdk
Version:
This is a live SDK for weclassroom.
75 lines (71 loc) • 2.42 kB
JavaScript
/*
* @Author: your name
* @Date: 2020-12-03 16:07:40
* @LastEditTime: 2020-12-10 21:25:24
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \xiaoban_report\xbase_extension_51_demo\src\_zby_live_sdk\src\channel\zby\index.js
*/
import interactWithChannel from './interactWithChannel';
import CHANNEL from '../index';
import util from '../../util/util';
import {getApiCloudBaseUrl} from '../../config/config';
function sendChannelMsgInner(data) {
const target = data.target;
if(target) {
delete data.target;
interactWithChannel.control.sendStreamMsg('stream', JSON.stringify(data), target);
} else {
interactWithChannel.control.sendStreamMsg('stream', JSON.stringify(data));
}
}
export default {
joinRoom(args, cb) {
try {
//设置信道基础参数
interactWithChannel.entry.setConfigInfo(JSON.stringify({
'address': args.chatUrl,
'user': {
'userid': args.userId,
'username': args.userName || '',
'token': args.channelToken,
'role': args.role,
'avatar': '',
'code': '1234',
},
'language': 0,
'logmode': 0,
'channeltype': 1,
}));
} catch (error) {
window.zby_sdk_init_status_for_data_report = false;
try {
dataReport.joinRoomResult({
code: '2',
// cloud_api_response: JSON.stringify(window.zby_sdk_cloud_data),
cloud_api_response: window.zby_sdk_cloud_data,
cloud_api_url: `${getApiCloudBaseUrl()}/rtccloud/class/init`,
chat_url: args.chatUrl
});
} catch (e) {};
}
interactWithChannel.entry.enterRoom(JSON.stringify({
//向老客户端兼容,拼接institutionId,信道进房间使用拼接后的roomid
'roomid': util.getConfId(args.institutionId, args.roomId),
'classmode': 4,
'playmode': 1, //1=正常上课;2=回放
'institutionid': args.institutionId,
//51连接信道所需,区分连接来源
'conn_origin': '51plan'
}), cb);
CHANNEL.sendJoin(args);
},
leaveRoom() {
interactWithChannel.entry.leaveRoom();
},
sendChannelMsg(data, target) {
util.waitFlagToRun(() => {
return interactWithChannel.control.isInRoom;
}, sendChannelMsgInner, {...data, target});
},
};