李勇

增加 webRtc 相关的数据返回给客户端;

... ... @@ -59,7 +59,7 @@ export default class MessageEntrance extends Emiter {
constructor() {
super();
//sdk 信息
GlobalConfig.sdkVersion = "v2.1.17.20170902";
GlobalConfig.sdkVersion = "v2.1.22.20170904";
loger.warn("sdkVersion:" + GlobalConfig.sdkVersion);
//设置
... ... @@ -1048,6 +1048,12 @@ export default class MessageEntrance extends Emiter {
GlobalConfig.screenWidth = window.screen.width;
GlobalConfig.screenHeight = window.screen.height;
GlobalConfig.channelId = ""+GlobalConfig.siteId+"_"+GlobalConfig.classId;
GlobalConfig.userUid = GlobalConfig.nodeId;
GlobalConfig.channelKey=null;
//返回给客户端初始化成功的数据
let joinClassSuccessCallBackData = {};
... ... @@ -1110,6 +1116,14 @@ export default class MessageEntrance extends Emiter {
joinClassSuccessCallBackData.explorerVersion = GlobalConfig.explorerVersion;
joinClassSuccessCallBackData.os = GlobalConfig.os;
joinClassSuccessCallBackData.channelId =GlobalConfig.channelId ;
joinClassSuccessCallBackData.channelKey =GlobalConfig.channelKey ;
joinClassSuccessCallBackData.userUid = GlobalConfig.userUid;
joinClassSuccessCallBackData.appId = GlobalConfig.appId;
joinClassSuccessCallBackData.appCertificate = GlobalConfig.appCertificate;
joinClassSuccessCallBackData.appRecordingKey = GlobalConfig.appRecordingKey;
//设置日志上报所需的信息
LogManager.serverAndLoacTimeDistanc = GlobalConfig.serverAndLoacTimeDistanc;//本地时间和服务器时间的差值(秒)
LogManager.classId = GlobalConfig.classId;//课堂号
... ... @@ -1126,7 +1140,7 @@ export default class MessageEntrance extends Emiter {
this._emit(MessageTypes.CLASS_JOIN_SUCCESS, joinClassSuccessCallBackData);
//加入音视频通话模块
this._joinChannel({channelId:GlobalConfig.siteId+"_"+GlobalConfig.classId,uid:GlobalConfig.nodeId,info:""+GlobalConfig.userRole});
this._joinChannel({channelId:GlobalConfig.channelId,channelKey:GlobalConfig.channelKey ,uid:GlobalConfig.userUid,info:""+GlobalConfig.userRole});
}
//切换MCU ->_param->{reConnect:false} //reConnect(是否立即替换当前的ip并且重新连接)
... ... @@ -1613,6 +1627,10 @@ export default class MessageEntrance extends Emiter {
GlobalConfig.setMediaShareList(_data.sharedMediaList); //提前上传的媒体共享文件列表
GlobalConfig.appId = 'eb253cc7b40c4a8b82f0a5b6f93c2ce0';
GlobalConfig.appCertificate = "";
GlobalConfig.appRecordingKey = "";
//文档服务器地址
if (GlobalConfig.docList && GlobalConfig.docList.length > 0) {
//doc上传地址,随机获取一个
... ... @@ -1688,7 +1706,6 @@ export default class MessageEntrance extends Emiter {
} else {
//根据用户的userIp获取信息,获取服务列表选点,选点测速完成后才加入MCU
this.loadServerJsonAndgetUserIpInfo();
//初始化音视频通话sdk
this._initWebRtcSdk();
}
... ... @@ -2565,6 +2582,10 @@ export default class MessageEntrance extends Emiter {
* 初始化webRtc
* */
_initWebRtcSdk(_params){
if(GlobalConfig.deviceType==1||GlobalConfig.deviceType==2){
loger.warn("移动端不需要处理初始化webRtc");
return ;
}
if(_webRtc){
_webRtc.initApp(_params)
}
... ... @@ -2573,6 +2594,10 @@ export default class MessageEntrance extends Emiter {
* 加入视频通话
* */
_joinChannel(_params){
if(GlobalConfig.deviceType==1||GlobalConfig.deviceType==2){
loger.warn("移动端不需要处理加入视频房间");
return ;
}
if(_webRtc){
_webRtc.joinChannel(_params);
}
... ... @@ -2581,6 +2606,9 @@ export default class MessageEntrance extends Emiter {
* 离开视频通话频道
* */
_leaveChannel(_params){
if(GlobalConfig.deviceType==1||GlobalConfig.deviceType==2){
return ;
}
if(_webRtc){
_webRtc.leaveChannel(_params);
}
... ... @@ -2589,6 +2617,22 @@ export default class MessageEntrance extends Emiter {
* 发布流
* */
_publishMedia(_params){
//ios和安卓的只需要更新数据即可
if(GlobalConfig.deviceType==1||GlobalConfig.deviceType==2){
loger.log("调用webRtc推流");
GlobalConfig.openCamera = EngineUtils.creatTimestamp();
GlobalConfig.openMicrophones = GlobalConfig.openCamera;
this.userDeviecStatusChange({
nodeId: GlobalConfig.nodeId,
userRole: GlobalConfig.userRole,
userName: GlobalConfig.userName,
userId: GlobalConfig.userId,
openCamera: GlobalConfig.openCamera,
openMicrophones: GlobalConfig.openMicrophones
});
return ;
}
if(_webRtc){
_webRtc.publish(_params);
}
... ... @@ -2597,6 +2641,22 @@ export default class MessageEntrance extends Emiter {
* 停止发布流
* */
_unpublishMedia(_params){
//ios和安卓的只需要更新数据即可
if(GlobalConfig.deviceType==1||GlobalConfig.deviceType==2){
loger.log("调用webRtc停止推流");
GlobalConfig.openCamera =0;
GlobalConfig.openMicrophones =0;
this.userDeviecStatusChange({
nodeId: GlobalConfig.nodeId,
userRole: GlobalConfig.userRole,
userName: GlobalConfig.userName,
userId: GlobalConfig.userId,
openCamera: GlobalConfig.openCamera,
openMicrophones: GlobalConfig.openMicrophones
});
return ;
}
if(_webRtc){
_webRtc.unpublish(_params);
}
... ...
... ... @@ -58,6 +58,12 @@ class GlobalConfig {
classInfo.ssTunnelAppURL = this.ssTunnelAppURL;
classInfo.currentSceneTableId = this.currentSceneTableId; //文档区域的模块显示
classInfo.serverAndLoacTimeDistanc = this.serverAndLoacTimeDistanc;
classInfo.appId = this.appId;
classInfo.appCertificate = this.appCertificate;
classInfo.appRecordingKey = this.appRecordingKey;
classInfo.channelId =this.channelId ;
classInfo.channelKey =this.channelKey ;
classInfo.userUid = this.userUid;
return classInfo;
}
... ... @@ -548,5 +554,15 @@ GlobalConfig.os="未知";//系统
GlobalConfig.locationProtocol="http://";//https;或http:
GlobalConfig.websocketProtocol="ws://";//wss或ws
GlobalConfig.isHttps=false;//是否是https
//webRtc
GlobalConfig.appId = 'eb253cc7b40c4a8b82f0a5b6f93c2ce0';
GlobalConfig.appCertificate = "";
GlobalConfig.appRecordingKey = "";
GlobalConfig.channelId = "";
GlobalConfig.channelKey = null;
GlobalConfig.userUid = 0;
export default GlobalConfig;
... ...
... ... @@ -18,6 +18,7 @@ class WebRtcApe extends Emiter {
this.appCertificate = "";
this.appRecordingKey = "";
this.channelKey=null;
this.channelId = "";
this.uid = 0;
this.info = ""
... ... @@ -48,29 +49,30 @@ class WebRtcApe extends Emiter {
}
initApp(_params) {
loger.log("AgoraRTC client init");
loger.log("初始化WebRtc");
if (_params) {
this.appId = _params.appId;
}
if (this.client) {
this.client.init(this.appId, () => {
loger.log("AgoraRTC client init success");
loger.log("初始化WebRtc->成功");
}, (err)=> {
loger.error("AgoraRTC client init failed", err);
loger.error("初始化WebRtc->失败", err);
});
this.addEvent();
}
}
addEvent() {
loger.log("AgoraRTC addEvent");
loger.log("监听webRtc消息");
if (!this.client) {
loger.log("addEvent error:client is null");
return;
}
this.channelKey = "";
this.client.on('error', (err) => {
loger.log("Got error msg:", err.reason);
loger.log("WebRtc异常:", err.reason);
if (err.reason === 'DYNAMIC_KEY_TIMEOUT') {
this.client.renewChannelKey(this.channelKey, ()=> {
loger.log("Renew channel key successfully");
... ... @@ -113,12 +115,12 @@ class WebRtcApe extends Emiter {
if (stream) {
stream.stop();
$('#' + this.xdyRemote + stream.getId()).remove();
loger.log(evt.uid + " leaved from this channel");
loger.log(evt.uid + " ->离开视频通话频道");
}
});
this.client.on("active-speaker", (evt)=> {
let uid = evt.uid;
loger.log("update active speaker: client" + uid);
loger.log("当前正在讲话的uid:" + uid);
});
}
... ... @@ -126,15 +128,15 @@ class WebRtcApe extends Emiter {
this.channelId = _params.channelId||"";
this.uid = parseInt(_params.uid)||0;
this.info =_params.info || "";
let dynamic_key = null;
this.channelKey = _params.channelKey||null;
loger.log("AgoraRTC joinChannel","channelId:"+this.channelId,"uid:"+this.uid);
this.client.join(dynamic_key, ""+this.channelId, this.uid, (uid)=> {
loger.log("加入视频通话频道->channelId:"+this.channelId,"uid:"+this.uid);
this.client.join(this.channelKey , ""+this.channelId, this.uid, (uid)=> {
this.uid = uid;
loger.log("User " + uid + " join channel successfully");
loger.log("加入视频通话频道->成功->channelId:"+this.channelId,"uid:"+this.uid);
this.openLoaclStream();
}, (err)=> {
loger.log("Join channel failed", err);
loger.log("加入视频通话频道->失败->", err);
});
}
... ... @@ -156,7 +158,7 @@ class WebRtcApe extends Emiter {
}
leaveChannel() {
loger.log("AgoraRTC joinChannel");
loger.log("离开视频通话频道");
if (!this.client) {
return;
}
... ... @@ -172,11 +174,11 @@ class WebRtcApe extends Emiter {
return;
}
this.localStream.init(()=> {
loger.log("webRtc->推流: ");
let viewName = this.localViewId.replace("#", "");
loger.log("getUserMedia successfully", this.localViewId);
this.localStream.play(viewName);
this.client.publish(this.localStream, (err)=> {
loger.log("Publish local stream error: " + err);
loger.log("webRtc->推流失败: " + err);
GlobalConfig.openCamera =0;
GlobalConfig.openMicrophones =0;
});
... ... @@ -193,16 +195,17 @@ class WebRtcApe extends Emiter {
});
}, (err)=> {
loger.log("getUserMedia failed", err);
loger.log("webRtc->推流->本地流开启失败", err);
});
}
unpublish() {
loger.log("webRtc->停止推流 ");
if (!this.client||!this.localStream) {
return;
}
this.client.unpublish(this.localStream, (err)=> {
loger.log("Unpublish local stream failed" + err);
loger.log("webRtc->停止推流->失败" + err);
});
this.localStream.close();
$(this.localViewId).html("");
... ...