正在显示
3 个修改的文件
包含
243 行增加
和
200 行删除
| @@ -62,7 +62,7 @@ export default class MessageEntrance extends Emiter { | @@ -62,7 +62,7 @@ export default class MessageEntrance extends Emiter { | ||
| 62 | constructor() { | 62 | constructor() { |
| 63 | super(); | 63 | super(); |
| 64 | //sdk 信息 | 64 | //sdk 信息 |
| 65 | - GlobalConfig.sdkVersion = "v2.12.8.20170926"; | 65 | + GlobalConfig.sdkVersion = "v2.12.14.20170927"; |
| 66 | loger.warn("sdkVersion:" + GlobalConfig.sdkVersion); | 66 | loger.warn("sdkVersion:" + GlobalConfig.sdkVersion); |
| 67 | 67 | ||
| 68 | //设置 | 68 | //设置 |
| @@ -1209,9 +1209,17 @@ export default class MessageEntrance extends Emiter { | @@ -1209,9 +1209,17 @@ export default class MessageEntrance extends Emiter { | ||
| 1209 | 1209 | ||
| 1210 | if(GlobalConfig.appId&&!GlobalConfig.openFlash){ | 1210 | if(GlobalConfig.appId&&!GlobalConfig.openFlash){ |
| 1211 | setTimeout(()=>{ | 1211 | setTimeout(()=>{ |
| 1212 | + /* //加入之前先设置旁录地址,只有直播支持旁路 | ||
| 1213 | + if(_webRtc){ | ||
| 1214 | + let publishData=this._getVideoPublishPath(); | ||
| 1215 | + loger.log("加入之前先设置旁录地址",publishData); | ||
| 1216 | + if(publishData&&publishData.code==0){ | ||
| 1217 | + _webRtc.setConfigPublisherUrl(publishData.publishUrl); | ||
| 1218 | + } | ||
| 1219 | + }*/ | ||
| 1212 | //加入音视频通话模块,延迟一秒处理,因为视频需要根据用户列表信息来判断放的位置,太早的话用户列表没有数据 | 1220 | //加入音视频通话模块,延迟一秒处理,因为视频需要根据用户列表信息来判断放的位置,太早的话用户列表没有数据 |
| 1213 | this._joinChannel({channelId:GlobalConfig.channelId,channelKey:GlobalConfig.channelKey ,uid:GlobalConfig.userUid,info:""+GlobalConfig.userRole}); | 1221 | this._joinChannel({channelId:GlobalConfig.channelId,channelKey:GlobalConfig.channelKey ,uid:GlobalConfig.userUid,info:""+GlobalConfig.userRole}); |
| 1214 | - },1000); | 1222 | + },1600); |
| 1215 | } | 1223 | } |
| 1216 | } | 1224 | } |
| 1217 | 1225 | ||
| @@ -2740,6 +2748,7 @@ export default class MessageEntrance extends Emiter { | @@ -2740,6 +2748,7 @@ export default class MessageEntrance extends Emiter { | ||
| 2740 | }); | 2748 | }); |
| 2741 | } | 2749 | } |
| 2742 | } | 2750 | } |
| 2751 | + | ||
| 2743 | /* | 2752 | /* |
| 2744 | * 加入视频通话 | 2753 | * 加入视频通话 |
| 2745 | * */ | 2754 | * */ |
| @@ -2798,6 +2807,7 @@ export default class MessageEntrance extends Emiter { | @@ -2798,6 +2807,7 @@ export default class MessageEntrance extends Emiter { | ||
| 2798 | _webRtc.publish(_params); | 2807 | _webRtc.publish(_params); |
| 2799 | } | 2808 | } |
| 2800 | } | 2809 | } |
| 2810 | + | ||
| 2801 | /* | 2811 | /* |
| 2802 | * 停止发布流 | 2812 | * 停止发布流 |
| 2803 | * */ | 2813 | * */ |
| @@ -143,7 +143,7 @@ class MediaModule { | @@ -143,7 +143,7 @@ class MediaModule { | ||
| 143 | txTime=txTime.toString(16); | 143 | txTime=txTime.toString(16); |
| 144 | let txSecret= MD5(publishSuffix + streamId+txTime); | 144 | let txSecret= MD5(publishSuffix + streamId+txTime); |
| 145 | //rtmp://11220.livepush.myqcloud.com/live/11220_c5a1ea0bce?bizid=11220&txSecret=b1d8af72bf62366eef31cbb5dc5c8778&txTime=59C5337F | 145 | //rtmp://11220.livepush.myqcloud.com/live/11220_c5a1ea0bce?bizid=11220&txSecret=b1d8af72bf62366eef31cbb5dc5c8778&txTime=59C5337F |
| 146 | - newUrl=url +"?bizid=11220&txSecret="+txSecret+"&txTime="+txTime+"&record=hls&record_interval=5400"; | 146 | + newUrl=url +"?bizid=11220&txSecret="+txSecret+"&txTime="+txTime+"&record=hls|flv&record_interval=5400"; |
| 147 | loger.log("生成的推流地址->"+newUrl); | 147 | loger.log("生成的推流地址->"+newUrl); |
| 148 | return newUrl; | 148 | return newUrl; |
| 149 | } | 149 | } |
| @@ -343,10 +343,14 @@ class MediaModule { | @@ -343,10 +343,14 @@ class MediaModule { | ||
| 343 | } | 343 | } |
| 344 | loger.log("获取空闲的通道", "mediaChannels", this.mediaChannels, "counter:", counter); | 344 | loger.log("获取空闲的通道", "mediaChannels", this.mediaChannels, "counter:", counter); |
| 345 | //loger.log(this.mediaChannels); | 345 | //loger.log(this.mediaChannels); |
| 346 | + if(this.maxMediaChannel>0){ | ||
| 346 | if (counter < this.maxMediaChannel) { | 347 | if (counter < this.maxMediaChannel) { |
| 347 | return this.MEDIA_OBJ_TABLE_ID + (counter); | 348 | return this.MEDIA_OBJ_TABLE_ID + (counter); |
| 348 | } | 349 | } |
| 349 | return 0;//没有空闲的 | 350 | return 0;//没有空闲的 |
| 351 | + }else { | ||
| 352 | + return this.MEDIA_OBJ_TABLE_ID + (counter); | ||
| 353 | + } | ||
| 350 | } | 354 | } |
| 351 | 355 | ||
| 352 | //获取准备推流的频道信息 | 356 | //获取准备推流的频道信息 |
| @@ -14,18 +14,20 @@ let loger = Loger.getLoger('WebRtcApe'); | @@ -14,18 +14,20 @@ let loger = Loger.getLoger('WebRtcApe'); | ||
| 14 | class WebRtcApe extends Emiter { | 14 | class WebRtcApe extends Emiter { |
| 15 | constructor() { | 15 | constructor() { |
| 16 | super(); | 16 | super(); |
| 17 | - this.nameDisplay="block";//默认显示名字 | 17 | + this.nameDisplay = "block";//默认显示名字 |
| 18 | this.appId = ''; | 18 | this.appId = ''; |
| 19 | this.appCertificate = ""; | 19 | this.appCertificate = ""; |
| 20 | this.appRecordingKey = ""; | 20 | this.appRecordingKey = ""; |
| 21 | 21 | ||
| 22 | - this.channelKey=null; | 22 | + this.configPublisherUrl = "";//旁路地址; |
| 23 | + | ||
| 24 | + this.channelKey = null; | ||
| 23 | this.channelId = ""; | 25 | this.channelId = ""; |
| 24 | this.uid = 0; | 26 | this.uid = 0; |
| 25 | this.info = "" | 27 | this.info = "" |
| 26 | 28 | ||
| 27 | - this.reAddRemoteStreamDelay=0;//重连远程视频的计时器 | ||
| 28 | - this.rePublishDelay=0;//重新推流的间隔 | 29 | + this.reAddRemoteStreamDelay = 0;//重连远程视频的计时器 |
| 30 | + this.rePublishDelay = 0;//重新推流的间隔 | ||
| 29 | 31 | ||
| 30 | this.mode = "interop"; | 32 | this.mode = "interop"; |
| 31 | this.client = null; | 33 | this.client = null; |
| @@ -35,40 +37,40 @@ class WebRtcApe extends Emiter { | @@ -35,40 +37,40 @@ class WebRtcApe extends Emiter { | ||
| 35 | this.curCameraId = ""; | 37 | this.curCameraId = ""; |
| 36 | this.curMicrophoneId = ""; | 38 | this.curMicrophoneId = ""; |
| 37 | 39 | ||
| 38 | - this.remoteVideoList={};//记录远程视频流 | 40 | + this.remoteVideoList = {};//记录远程视频流 |
| 39 | 41 | ||
| 40 | this.videoResolution = "240P"; | 42 | this.videoResolution = "240P"; |
| 41 | this.isOpenVideo = true; | 43 | this.isOpenVideo = true; |
| 42 | 44 | ||
| 43 | - this.isPublish=false;//当前是否正在推流 | 45 | + this.isPublish = false;//当前是否正在推流 |
| 44 | 46 | ||
| 45 | - this.normalRemoteViewId =""; | ||
| 46 | - this.normalRemoteStyle =""; | ||
| 47 | - this.normalRemoteVideoWidth=320; | ||
| 48 | - this.normalRemoteVideoHeight=240; | 47 | + this.normalRemoteViewId = ""; |
| 48 | + this.normalRemoteStyle = ""; | ||
| 49 | + this.normalRemoteVideoWidth = 320; | ||
| 50 | + this.normalRemoteVideoHeight = 240; | ||
| 49 | 51 | ||
| 50 | this.localViewId = ""; | 52 | this.localViewId = ""; |
| 51 | this.localStyle = ""; | 53 | this.localStyle = ""; |
| 52 | - this.localVideoWidth=320; | ||
| 53 | - this.localVideoHeight=240; | 54 | + this.localVideoWidth = 320; |
| 55 | + this.localVideoHeight = 240; | ||
| 54 | 56 | ||
| 55 | this.hostRemoteViewId = ""; | 57 | this.hostRemoteViewId = ""; |
| 56 | this.hostRemoteStyle = ""; | 58 | this.hostRemoteStyle = ""; |
| 57 | - this.hostRemoteVideoWidth=320; | ||
| 58 | - this.hostRemoteVideoHeight=240; | 59 | + this.hostRemoteVideoWidth = 320; |
| 60 | + this.hostRemoteVideoHeight = 240; | ||
| 59 | 61 | ||
| 60 | - this.invisibleViewId =""; | ||
| 61 | - this.invisibleStyle =""; | ||
| 62 | - this.invisibleVideoWidth=320; | ||
| 63 | - this.invisibleVideoHeight=240; | 62 | + this.invisibleViewId = ""; |
| 63 | + this.invisibleStyle = ""; | ||
| 64 | + this.invisibleVideoWidth = 320; | ||
| 65 | + this.invisibleVideoHeight = 240; | ||
| 64 | this.xdyRemote = "xdy_remote"; | 66 | this.xdyRemote = "xdy_remote"; |
| 65 | //webRtc sdk | 67 | //webRtc sdk |
| 66 | this.client = AgoraRTC.createClient({mode: this.mode}); | 68 | this.client = AgoraRTC.createClient({mode: this.mode}); |
| 67 | 69 | ||
| 68 | - this.getDevices(null,(devices)=>{ | 70 | + this.getDevices(null, (devices)=> { |
| 69 | if (this.cameras && this.cameras.length > 0) { | 71 | if (this.cameras && this.cameras.length > 0) { |
| 70 | this.curCameraId = this.cameras[0].deviceId || ""; | 72 | this.curCameraId = this.cameras[0].deviceId || ""; |
| 71 | - GlobalConfig.curCamera =this.cameras[0].label || ""; | 73 | + GlobalConfig.curCamera = this.cameras[0].label || ""; |
| 72 | } | 74 | } |
| 73 | if (this.microphones && this.microphones.length > 0) { | 75 | if (this.microphones && this.microphones.length > 0) { |
| 74 | this.curMicrophoneId = this.microphones[0].deviceId || ""; | 76 | this.curMicrophoneId = this.microphones[0].deviceId || ""; |
| @@ -77,7 +79,7 @@ class WebRtcApe extends Emiter { | @@ -77,7 +79,7 @@ class WebRtcApe extends Emiter { | ||
| 77 | }); | 79 | }); |
| 78 | } | 80 | } |
| 79 | 81 | ||
| 80 | - initApp(_params,_callback) { | 82 | + initApp(_params, _callback) { |
| 81 | loger.log("初始化WebRtc"); | 83 | loger.log("初始化WebRtc"); |
| 82 | if (_params) { | 84 | if (_params) { |
| 83 | this.appId = _params.appId; | 85 | this.appId = _params.appId; |
| @@ -85,13 +87,13 @@ class WebRtcApe extends Emiter { | @@ -85,13 +87,13 @@ class WebRtcApe extends Emiter { | ||
| 85 | if (this.client) { | 87 | if (this.client) { |
| 86 | this.client.init(this.appId, () => { | 88 | this.client.init(this.appId, () => { |
| 87 | loger.log("初始化WebRtc->成功"); | 89 | loger.log("初始化WebRtc->成功"); |
| 88 | - if(_callback){ | ||
| 89 | - _callback({isSuccess:true}); | 90 | + if (_callback) { |
| 91 | + _callback({isSuccess: true}); | ||
| 90 | } | 92 | } |
| 91 | }, (err)=> { | 93 | }, (err)=> { |
| 92 | loger.error("初始化WebRtc->失败", err); | 94 | loger.error("初始化WebRtc->失败", err); |
| 93 | - if(_callback){ | ||
| 94 | - _callback({isSuccess:false,error:err}); | 95 | + if (_callback) { |
| 96 | + _callback({isSuccess: false, error: err}); | ||
| 95 | } | 97 | } |
| 96 | }); | 98 | }); |
| 97 | this.addEvent(); | 99 | this.addEvent(); |
| @@ -116,8 +118,8 @@ class WebRtcApe extends Emiter { | @@ -116,8 +118,8 @@ class WebRtcApe extends Emiter { | ||
| 116 | } | 118 | } |
| 117 | }); | 119 | }); |
| 118 | this.client.on('stream-published', (evt)=> { | 120 | this.client.on('stream-published', (evt)=> { |
| 119 | - loger.log("webRtc->推流成功->",new Date().getTime()); | ||
| 120 | - this.isPublish=true; | 121 | + loger.log("webRtc->推流成功->", new Date().getTime()); |
| 122 | + this.isPublish = true; | ||
| 121 | GlobalConfig.openCamera = EngineUtils.creatTimestamp(); | 123 | GlobalConfig.openCamera = EngineUtils.creatTimestamp(); |
| 122 | GlobalConfig.openMicrophones = GlobalConfig.openCamera; | 124 | GlobalConfig.openMicrophones = GlobalConfig.openCamera; |
| 123 | this._emit(MessageTypes.USER_DEVICE_STATUS_CHAANGE, { | 125 | this._emit(MessageTypes.USER_DEVICE_STATUS_CHAANGE, { |
| @@ -188,7 +190,7 @@ class WebRtcApe extends Emiter { | @@ -188,7 +190,7 @@ class WebRtcApe extends Emiter { | ||
| 188 | 190 | ||
| 189 | this.client.on('stream-removed', (evt)=> { | 191 | this.client.on('stream-removed', (evt)=> { |
| 190 | let stream = evt.stream; | 192 | let stream = evt.stream; |
| 191 | - if(stream){ | 193 | + if (stream) { |
| 192 | stream.stop(); | 194 | stream.stop(); |
| 193 | $('#' + this.xdyRemote + stream.getId()).remove(); | 195 | $('#' + this.xdyRemote + stream.getId()).remove(); |
| 194 | loger.log("远程视频流已经断开:" + stream.getId()); | 196 | loger.log("远程视频流已经断开:" + stream.getId()); |
| @@ -210,109 +212,116 @@ class WebRtcApe extends Emiter { | @@ -210,109 +212,116 @@ class WebRtcApe extends Emiter { | ||
| 210 | }); | 212 | }); |
| 211 | 213 | ||
| 212 | } | 214 | } |
| 213 | - addRemoetStreamView(stream){ | ||
| 214 | - if(stream){ | 215 | + |
| 216 | + addRemoetStreamView(stream) { | ||
| 217 | + if (stream) { | ||
| 215 | //let viewDiv=`<div id="${this.xdyRemote + stream.getId()}" style="width:${this.hostRemoteVideoWidth}px;height:${this.hostRemoteVideoHeight}px;"></div>`; | 218 | //let viewDiv=`<div id="${this.xdyRemote + stream.getId()}" style="width:${this.hostRemoteVideoWidth}px;height:${this.hostRemoteVideoHeight}px;"></div>`; |
| 216 | - let uid=stream.getId(); | ||
| 217 | - let user=GlobalConfig.getUserInfoFromeNodeId(uid); | ||
| 218 | - let userName=""; | ||
| 219 | - let userRole="" | ||
| 220 | - if(user){ | ||
| 221 | - userName=user.name||"unknow"; | ||
| 222 | - userRole=user.userRole; | 219 | + let uid = stream.getId(); |
| 220 | + let user = GlobalConfig.getUserInfoFromeNodeId(uid); | ||
| 221 | + let userName = ""; | ||
| 222 | + let userRole = "" | ||
| 223 | + if (user) { | ||
| 224 | + userName = user.name || "unknow"; | ||
| 225 | + userRole = user.userRole; | ||
| 223 | } | 226 | } |
| 224 | - let nameDiv=`<div style="width:98%;height:20px; position: absolute; z-index: 1;left: 4px;overflow:hidden;font-size: 14px; color: #cccccc;display:${this.nameDisplay}">${userName}</div>`; | 227 | + let nameDiv = `<div style="width:98%;height:20px; position: absolute; z-index: 1;left: 4px;overflow:hidden;font-size: 14px; color: #cccccc;display:${this.nameDisplay}">${userName}</div>`; |
| 225 | 228 | ||
| 226 | - if(userRole==ApeConsts.invisible){ | 229 | + if (userRole == ApeConsts.invisible) { |
| 227 | //把远程视频添加到监课列表 | 230 | //把远程视频添加到监课列表 |
| 228 | - loger.log("获取远程视频流成功->监课:"+userName+"->" + uid,new Date().getTime()); | ||
| 229 | - let viewDiv=`<div id="${this.xdyRemote + uid}" style="width:${this.invisibleVideoWidth}px;height:${this.invisibleVideoHeight}px;float: left;margin-right: 1px;pointer-events: none;">${nameDiv}</div>`; | 231 | + loger.log("获取远程视频流成功->监课:" + userName + "->" + uid, new Date().getTime()); |
| 232 | + let viewDiv = `<div id="${this.xdyRemote + uid}" style="width:${this.invisibleVideoWidth}px;height:${this.invisibleVideoHeight}px;float: left;margin-right: 1px;pointer-events: none;">${nameDiv}</div>`; | ||
| 230 | $(this.invisibleViewId).append(viewDiv); | 233 | $(this.invisibleViewId).append(viewDiv); |
| 231 | - }else if(userRole==ApeConsts.host){ | 234 | + } else if (userRole == ApeConsts.host) { |
| 232 | //把远程视图添加到老师列表 | 235 | //把远程视图添加到老师列表 |
| 233 | - loger.log("获取远程视频流成功->老师:"+userName+"->" + uid,new Date().getTime()); | ||
| 234 | - let viewDiv=`<div id="${this.xdyRemote + uid}" style="width:${this.hostRemoteVideoWidth}px;height:${this.hostRemoteVideoHeight}px;float: left;margin-right: 1px;pointer-events: none;">${nameDiv}</div>`; | 236 | + loger.log("获取远程视频流成功->老师:" + userName + "->" + uid, new Date().getTime()); |
| 237 | + let viewDiv = `<div id="${this.xdyRemote + uid}" style="width:${this.hostRemoteVideoWidth}px;height:${this.hostRemoteVideoHeight}px;float: left;margin-right: 1px;pointer-events: none;">${nameDiv}</div>`; | ||
| 235 | $(this.hostRemoteViewId).append(viewDiv); | 238 | $(this.hostRemoteViewId).append(viewDiv); |
| 236 | - }else { | 239 | + } else { |
| 237 | //把视图添加到学生列表 | 240 | //把视图添加到学生列表 |
| 238 | - loger.log("获取远程视频流成功->学生:"+userName+"->" +uid,new Date().getTime()); | ||
| 239 | - let viewDiv=`<div id="${this.xdyRemote + uid}" style="width:${this.normalRemoteVideoWidth}px;height:${this.normalRemoteVideoHeight}px;float: left;margin-right: 1px;pointer-events: none;">${nameDiv}</div>`; | 241 | + loger.log("获取远程视频流成功->学生:" + userName + "->" + uid, new Date().getTime()); |
| 242 | + let viewDiv = `<div id="${this.xdyRemote + uid}" style="width:${this.normalRemoteVideoWidth}px;height:${this.normalRemoteVideoHeight}px;float: left;margin-right: 1px;pointer-events: none;">${nameDiv}</div>`; | ||
| 240 | $(this.normalRemoteViewId).append(viewDiv); | 243 | $(this.normalRemoteViewId).append(viewDiv); |
| 241 | } | 244 | } |
| 242 | //播放视频,隐藏控制条 | 245 | //播放视频,隐藏控制条 |
| 243 | - try{ | ||
| 244 | - $("bar_"+stream.getId()).hide(); | 246 | + try { |
| 247 | + $("bar_" + stream.getId()).hide(); | ||
| 245 | stream.play(this.xdyRemote + stream.getId()); | 248 | stream.play(this.xdyRemote + stream.getId()); |
| 246 | - }catch (err){ | 249 | + } catch (err) { |
| 247 | } | 250 | } |
| 248 | - if(user&&(user.deviceType==1||user.deviceType==2)){ | ||
| 249 | - this.remoteVideoList[user.nodeId]=stream; | 251 | + if (user && (user.deviceType == 1 || user.deviceType == 2)) { |
| 252 | + this.remoteVideoList[user.nodeId] = stream; | ||
| 250 | } | 253 | } |
| 251 | - console.log("移动端远程视频流集合->",this.remoteVideoList); | 254 | + console.log("移动端远程视频流集合->", this.remoteVideoList); |
| 252 | } | 255 | } |
| 253 | } | 256 | } |
| 254 | 257 | ||
| 255 | //重新添加远程视频 | 258 | //重新添加远程视频 |
| 256 | - reAddRemoteStream(_stream){ | ||
| 257 | - if(!_stream){ | 259 | + reAddRemoteStream(_stream) { |
| 260 | + if (!_stream) { | ||
| 258 | return; | 261 | return; |
| 259 | } | 262 | } |
| 260 | - let user=GlobalConfig.getUserRoleFromeNodeId(_stream.getId()); | ||
| 261 | - if(user.openCamera<=0){ | ||
| 262 | - loger.log("远程流已经停止,不需要再连接: " + _stream.getId(),new Date().getTime()); | 263 | + let user = GlobalConfig.getUserRoleFromeNodeId(_stream.getId()); |
| 264 | + if (user.openCamera <= 0) { | ||
| 265 | + loger.log("远程流已经停止,不需要再连接: " + _stream.getId(), new Date().getTime()); | ||
| 263 | return; | 266 | return; |
| 264 | } | 267 | } |
| 265 | - loger.log("添加一个远程视频流: " + _stream.getId(),new Date().getTime()); | 268 | + loger.log("添加一个远程视频流: " + _stream.getId(), new Date().getTime()); |
| 266 | this.client.subscribe(_stream, (err)=> { | 269 | this.client.subscribe(_stream, (err)=> { |
| 267 | //clearTimeout(this.reAddRemoteStreamDelay); | 270 | //clearTimeout(this.reAddRemoteStreamDelay); |
| 268 | - if(err=="INVALID_REMOTE_STREAM"){ | 271 | + if (err == "INVALID_REMOTE_STREAM") { |
| 269 | //流已经无效,不需要再重连 | 272 | //流已经无效,不需要再重连 |
| 270 | loger.warn("流已经无效->不需要再重连", err); | 273 | loger.warn("流已经无效->不需要再重连", err); |
| 271 | return; | 274 | return; |
| 272 | } | 275 | } |
| 273 | - if(err=="PEERCONNECTION_FAILED"){ | ||
| 274 | - setTimeout(()=>{ | ||
| 275 | - loger.warn("连接远程的流失败->尝试重新连接",err); | 276 | + if (err == "PEERCONNECTION_FAILED") { |
| 277 | + setTimeout(()=> { | ||
| 278 | + loger.warn("连接远程的流失败->尝试重新连接", err); | ||
| 276 | this.reAddRemoteStream(_stream); | 279 | this.reAddRemoteStream(_stream); |
| 277 | - },1400); | ||
| 278 | - }else { | ||
| 279 | - loger.warn("添加一个远程视频流->失败", err); } | 280 | + }, 1400); |
| 281 | + } else { | ||
| 282 | + loger.warn("添加一个远程视频流->失败", err); | ||
| 283 | + } | ||
| 280 | }); | 284 | }); |
| 281 | } | 285 | } |
| 286 | + | ||
| 282 | //尝试添加远程的移动设备视频流 | 287 | //尝试添加远程的移动设备视频流 |
| 283 | - tryAddMobileStream(nodeId){ | ||
| 284 | - let stream=this.remoteVideoList[nodeId]; | ||
| 285 | - if(!stream){ | 288 | + tryAddMobileStream(nodeId) { |
| 289 | + let stream = this.remoteVideoList[nodeId]; | ||
| 290 | + if (!stream) { | ||
| 286 | return; | 291 | return; |
| 287 | } | 292 | } |
| 288 | - let remoteView=document.getElementById(this.xdyRemote +nodeId); | ||
| 289 | - console.log("remoteView->",remoteView) | ||
| 290 | - if(remoteView){ | ||
| 291 | - let player=document.getElementById("player_" +nodeId); | ||
| 292 | - if(player){ | ||
| 293 | - loger.log(nodeId+" 流已经添加显示,不需要再处理"); | 293 | + let remoteView = document.getElementById(this.xdyRemote + nodeId); |
| 294 | + console.log("remoteView->", remoteView) | ||
| 295 | + if (remoteView) { | ||
| 296 | + let player = document.getElementById("player_" + nodeId); | ||
| 297 | + if (player) { | ||
| 298 | + loger.log(nodeId + " 流已经添加显示,不需要再处理"); | ||
| 294 | return; | 299 | return; |
| 295 | - }else { | ||
| 296 | - loger.log(nodeId+" 删除无效的视图->创建新的视图remoteView"); | 300 | + } else { |
| 301 | + loger.log(nodeId + " 删除无效的视图->创建新的视图remoteView"); | ||
| 297 | remoteView.remove(); | 302 | remoteView.remove(); |
| 298 | } | 303 | } |
| 299 | } | 304 | } |
| 300 | - if(stream) { | 305 | + if (stream) { |
| 301 | loger.log("收到移动端推流的消息,主动添加一个远程视频流"); | 306 | loger.log("收到移动端推流的消息,主动添加一个远程视频流"); |
| 302 | this.addRemoetStreamView(stream); | 307 | this.addRemoetStreamView(stream); |
| 303 | } | 308 | } |
| 304 | } | 309 | } |
| 305 | 310 | ||
| 306 | joinChannel(_params) { | 311 | joinChannel(_params) { |
| 307 | - this.channelId = _params.channelId||""; | ||
| 308 | - this.uid = parseInt(_params.uid)||0; | ||
| 309 | - this.info =_params.info || ""; | ||
| 310 | - this.channelKey = _params.channelKey||null; | 312 | + if (!this.client) { |
| 313 | + loger.warn("入视频通话频道->失败->未初始化对象"); | ||
| 314 | + return; | ||
| 315 | + } | ||
| 316 | + this.channelId = _params.channelId || ""; | ||
| 317 | + this.uid = parseInt(_params.uid) || 0; | ||
| 318 | + this.info = _params.info || ""; | ||
| 319 | + this.channelKey = _params.channelKey || null; | ||
| 311 | 320 | ||
| 312 | - loger.log("开始加入视频通话频道->channelId:"+this.channelId,"uid:"+this.uid); | ||
| 313 | - this.client.join(this.channelKey , ""+this.channelId, this.uid, (uid)=> { | 321 | + loger.log("开始加入视频通话频道->channelId:" + this.channelId, "uid:" + this.uid); |
| 322 | + this.client.join(this.channelKey, "" + this.channelId, this.uid, (uid)=> { | ||
| 314 | this.uid = uid; | 323 | this.uid = uid; |
| 315 | - loger.log("加入视频通话频道->成功->channelId:"+this.channelId,"uid:"+this.uid); | 324 | + loger.log("加入视频通话频道->成功->channelId:" + this.channelId, "uid:" + this.uid); |
| 316 | this._emit(MessageTypes.WEB_RTC_JOIN_SUCCESS); | 325 | this._emit(MessageTypes.WEB_RTC_JOIN_SUCCESS); |
| 317 | this.openLoaclStream(); | 326 | this.openLoaclStream(); |
| 318 | }, (err)=> { | 327 | }, (err)=> { |
| @@ -320,19 +329,20 @@ class WebRtcApe extends Emiter { | @@ -320,19 +329,20 @@ class WebRtcApe extends Emiter { | ||
| 320 | this._emit(MessageTypes.WEB_RTC_JOIN_FAILED); | 329 | this._emit(MessageTypes.WEB_RTC_JOIN_FAILED); |
| 321 | }); | 330 | }); |
| 322 | } | 331 | } |
| 332 | + | ||
| 323 | //重新获取摄像头和麦克风并重新推流 | 333 | //重新获取摄像头和麦克风并重新推流 |
| 324 | - reGetLoaclStream(){ | ||
| 325 | - if(this.isPublish){ | 334 | + reGetLoaclStream() { |
| 335 | + if (this.isPublish) { | ||
| 326 | loger.log("重新获取摄像头和麦克风并重新推流"); | 336 | loger.log("重新获取摄像头和麦克风并重新推流"); |
| 327 | //this.changePublishStatusAndServerRecord(WebRtcApe.RECORD_STATUS_0); | 337 | //this.changePublishStatusAndServerRecord(WebRtcApe.RECORD_STATUS_0); |
| 328 | this.unpublish(); | 338 | this.unpublish(); |
| 329 | this.openLoaclStream(); | 339 | this.openLoaclStream(); |
| 330 | //切换设备后自动重推流 | 340 | //切换设备后自动重推流 |
| 331 | - this.rePublishDelay=setTimeout(()=>{ | 341 | + this.rePublishDelay = setTimeout(()=> { |
| 332 | this.publish(); | 342 | this.publish(); |
| 333 | - },1200); | 343 | + }, 1200); |
| 334 | //this.publish(); | 344 | //this.publish(); |
| 335 | - }else { | 345 | + } else { |
| 336 | this.openLoaclStream(); | 346 | this.openLoaclStream(); |
| 337 | } | 347 | } |
| 338 | } | 348 | } |
| @@ -369,60 +379,76 @@ class WebRtcApe extends Emiter { | @@ -369,60 +379,76 @@ class WebRtcApe extends Emiter { | ||
| 369 | }); | 379 | }); |
| 370 | } | 380 | } |
| 371 | 381 | ||
| 372 | - closeRemoteVideoView(_data){ | ||
| 373 | - if(!_data){ | 382 | + closeRemoteVideoView(_data) { |
| 383 | + if (!_data) { | ||
| 374 | return; | 384 | return; |
| 375 | } | 385 | } |
| 376 | //根据nodeId查找视频 | 386 | //根据nodeId查找视频 |
| 377 | - try{ | 387 | + try { |
| 378 | loger.log("立即删除停止推流人员的视图"); | 388 | loger.log("立即删除停止推流人员的视图"); |
| 379 | $('#' + this.xdyRemote + _data.nodeId).remove(); | 389 | $('#' + this.xdyRemote + _data.nodeId).remove(); |
| 380 | - }catch (err){ | 390 | + } catch (err) { |
| 381 | 391 | ||
| 382 | } | 392 | } |
| 383 | 393 | ||
| 384 | } | 394 | } |
| 395 | + | ||
| 396 | + /* | ||
| 397 | + * 设置旁录地址 | ||
| 398 | + * */ | ||
| 399 | + setConfigPublisherUrl(_publishUrl){ | ||
| 400 | + loger.warn("设置旁路地址->",_publishUrl); | ||
| 401 | + this.configPublisherUrl=_publishUrl; | ||
| 402 | + if(this.client&& this.configPublisherUrl){ | ||
| 403 | + this.client.configPublisher( | ||
| 404 | + {width: 320, height: 240, framerate: 15, bitrate: 200, publishUrl: this.configPublisherUrl} | ||
| 405 | + ); | ||
| 406 | + }else { | ||
| 407 | + loger.warn("设置旁路地址->失败->为初始化或旁路地址无效",_publishUrl); | ||
| 408 | + } | ||
| 409 | + } | ||
| 410 | + | ||
| 385 | publish(_params) { | 411 | publish(_params) { |
| 386 | - if (!this.client||!this.localStream) { | 412 | + if (!this.client || !this.localStream) { |
| 387 | return; | 413 | return; |
| 388 | } | 414 | } |
| 389 | this.localStream.init(()=> { | 415 | this.localStream.init(()=> { |
| 390 | - let viewName='localVideoBox_'+this.uid; | ||
| 391 | - let videoBox=document.createElement("div"); | ||
| 392 | - videoBox.id=viewName; | ||
| 393 | - videoBox.style.width=this.localVideoWidth+'px'; | ||
| 394 | - videoBox.style.height=this.localVideoHeight+'px'; | ||
| 395 | - videoBox.style.float='left'; | ||
| 396 | - videoBox.style.marginRight="1px"; | ||
| 397 | - videoBox.style.pointerEvents='none'; | 416 | + let viewName = 'localVideoBox_' + this.uid; |
| 417 | + let videoBox = document.createElement("div"); | ||
| 418 | + videoBox.id = viewName; | ||
| 419 | + videoBox.style.width = this.localVideoWidth + 'px'; | ||
| 420 | + videoBox.style.height = this.localVideoHeight + 'px'; | ||
| 421 | + videoBox.style.float = 'left'; | ||
| 422 | + videoBox.style.marginRight = "1px"; | ||
| 423 | + videoBox.style.pointerEvents = 'none'; | ||
| 398 | //自己的视图往前添加 | 424 | //自己的视图往前添加 |
| 399 | $(this.localViewId).prepend(videoBox); | 425 | $(this.localViewId).prepend(videoBox); |
| 400 | - $("#"+viewName).css("transform", 'rotateY(180deg)'); | 426 | + $("#" + viewName).css("transform", 'rotateY(180deg)'); |
| 401 | 427 | ||
| 402 | //显示自己的名字 | 428 | //显示自己的名字 |
| 403 | - let user=GlobalConfig.getUserInfoFromeNodeId(this.uid); | ||
| 404 | - let userName=""; | ||
| 405 | - if(user){ | ||
| 406 | - userName=user.name||""; | 429 | + let user = GlobalConfig.getUserInfoFromeNodeId(this.uid); |
| 430 | + let userName = ""; | ||
| 431 | + if (user) { | ||
| 432 | + userName = user.name || ""; | ||
| 407 | } | 433 | } |
| 408 | - let nameDiv=`<div id="${"videoOwnerName_"+this.uid}" style="width:98%;height:20px; position: absolute; z-index: 1;left: 4px;overflow:hidden;font-size: 14px; color: #cccccc;display:${this.nameDisplay}">${userName}</div>`; | 434 | + let nameDiv = `<div id="${"videoOwnerName_" + this.uid}" style="width:98%;height:20px; position: absolute; z-index: 1;left: 4px;overflow:hidden;font-size: 14px; color: #cccccc;display:${this.nameDisplay}">${userName}</div>`; |
| 409 | $(this.localViewId).prepend(nameDiv); | 435 | $(this.localViewId).prepend(nameDiv); |
| 410 | 436 | ||
| 411 | - loger.log("webRtc->推流->",viewName,new Date().getTime()); | 437 | + loger.log("webRtc->推流->", viewName, new Date().getTime()); |
| 412 | this.localStream.play(viewName); | 438 | this.localStream.play(viewName); |
| 413 | this.client.publish(this.localStream, (err)=> { | 439 | this.client.publish(this.localStream, (err)=> { |
| 414 | loger.log("webRtc->推流失败: " + err); | 440 | loger.log("webRtc->推流失败: " + err); |
| 415 | - GlobalConfig.openCamera =0; | ||
| 416 | - GlobalConfig.openMicrophones =0; | ||
| 417 | - this.isPublish=false; | 441 | + GlobalConfig.openCamera = 0; |
| 442 | + GlobalConfig.openMicrophones = 0; | ||
| 443 | + this.isPublish = false; | ||
| 418 | this.unpublish(); | 444 | this.unpublish(); |
| 419 | }); | 445 | }); |
| 420 | }, (err)=> { | 446 | }, (err)=> { |
| 421 | loger.warn("webRtc->推流->本地流开启失败", err); | 447 | loger.warn("webRtc->推流->本地流开启失败", err); |
| 422 | - this.isPublish=false; | 448 | + this.isPublish = false; |
| 423 | this.clearLocalView(); | 449 | this.clearLocalView(); |
| 424 | - this._emit(MessageTypes.WEB_RTC_PUBLISH_FAILED,err); | ||
| 425 | - if(err&&err.msg=="STREAM_ALREADY_INITIALIZED"){ | 450 | + this._emit(MessageTypes.WEB_RTC_PUBLISH_FAILED, err); |
| 451 | + if (err && err.msg == "STREAM_ALREADY_INITIALIZED") { | ||
| 426 | this.unpublish(); | 452 | this.unpublish(); |
| 427 | } | 453 | } |
| 428 | }); | 454 | }); |
| @@ -430,8 +456,8 @@ class WebRtcApe extends Emiter { | @@ -430,8 +456,8 @@ class WebRtcApe extends Emiter { | ||
| 430 | 456 | ||
| 431 | unpublish() { | 457 | unpublish() { |
| 432 | clearTimeout(this.rePublishDelay); | 458 | clearTimeout(this.rePublishDelay); |
| 433 | - loger.log("webRtc->停止推流 ",new Date().getTime()); | ||
| 434 | - if (!this.client||!this.localStream) { | 459 | + loger.log("webRtc->停止推流 ", new Date().getTime()); |
| 460 | + if (!this.client || !this.localStream) { | ||
| 435 | return; | 461 | return; |
| 436 | } | 462 | } |
| 437 | this.client.unpublish(this.localStream, (err)=> { | 463 | this.client.unpublish(this.localStream, (err)=> { |
| @@ -439,9 +465,9 @@ class WebRtcApe extends Emiter { | @@ -439,9 +465,9 @@ class WebRtcApe extends Emiter { | ||
| 439 | }); | 465 | }); |
| 440 | this.localStream.close(); | 466 | this.localStream.close(); |
| 441 | this.clearLocalView(); | 467 | this.clearLocalView(); |
| 442 | - this.isPublish=false; | ||
| 443 | - GlobalConfig.openCamera =0; | ||
| 444 | - GlobalConfig.openMicrophones =0; | 468 | + this.isPublish = false; |
| 469 | + GlobalConfig.openCamera = 0; | ||
| 470 | + GlobalConfig.openMicrophones = 0; | ||
| 445 | this._emit(MessageTypes.USER_DEVICE_STATUS_CHAANGE, { | 471 | this._emit(MessageTypes.USER_DEVICE_STATUS_CHAANGE, { |
| 446 | nodeId: GlobalConfig.nodeId, | 472 | nodeId: GlobalConfig.nodeId, |
| 447 | userRole: GlobalConfig.userRole, | 473 | userRole: GlobalConfig.userRole, |
| @@ -451,21 +477,23 @@ class WebRtcApe extends Emiter { | @@ -451,21 +477,23 @@ class WebRtcApe extends Emiter { | ||
| 451 | openMicrophones: GlobalConfig.openMicrophones | 477 | openMicrophones: GlobalConfig.openMicrophones |
| 452 | }); | 478 | }); |
| 453 | } | 479 | } |
| 480 | + | ||
| 454 | //清除本地视图 | 481 | //清除本地视图 |
| 455 | - clearLocalView(){ | 482 | + clearLocalView() { |
| 456 | $('#localVideoBox_' + this.uid).remove(); | 483 | $('#localVideoBox_' + this.uid).remove(); |
| 457 | - $("#videoOwnerName_"+this.uid).remove(); | 484 | + $("#videoOwnerName_" + this.uid).remove(); |
| 458 | } | 485 | } |
| 486 | + | ||
| 459 | /* | 487 | /* |
| 460 | * 设置本地回显视图 | 488 | * 设置本地回显视图 |
| 461 | * */ | 489 | * */ |
| 462 | setLoaclView(_params) { | 490 | setLoaclView(_params) { |
| 463 | loger.log("设置自己本地回显视图"); | 491 | loger.log("设置自己本地回显视图"); |
| 464 | - this.localViewId = _params.divId||""; | ||
| 465 | - this.localStyle = _params.styleStr||""; | ||
| 466 | - this.localVideoWidth=parseInt(_params.width)||320; | ||
| 467 | - this.localVideoHeight=parseInt(_params.height)||240; | ||
| 468 | - this.nameDisplay=_params.nameDisplay||"block"; | 492 | + this.localViewId = _params.divId || ""; |
| 493 | + this.localStyle = _params.styleStr || ""; | ||
| 494 | + this.localVideoWidth = parseInt(_params.width) || 320; | ||
| 495 | + this.localVideoHeight = parseInt(_params.height) || 240; | ||
| 496 | + this.nameDisplay = _params.nameDisplay || "block"; | ||
| 469 | } | 497 | } |
| 470 | 498 | ||
| 471 | /* | 499 | /* |
| @@ -473,10 +501,10 @@ class WebRtcApe extends Emiter { | @@ -473,10 +501,10 @@ class WebRtcApe extends Emiter { | ||
| 473 | * */ | 501 | * */ |
| 474 | setHostRemoteMediaView(_params) { | 502 | setHostRemoteMediaView(_params) { |
| 475 | loger.log("设置老师视图容器"); | 503 | loger.log("设置老师视图容器"); |
| 476 | - this.hostRemoteViewId = _params.divId||""; | ||
| 477 | - this.hostRemoteStyle = _params.styleStr||""; | ||
| 478 | - this.hostRemoteVideoWidth=parseInt(_params.width)||320; | ||
| 479 | - this.hostRemoteVideoHeight=parseInt(_params.height)||240; | 504 | + this.hostRemoteViewId = _params.divId || ""; |
| 505 | + this.hostRemoteStyle = _params.styleStr || ""; | ||
| 506 | + this.hostRemoteVideoWidth = parseInt(_params.width) || 320; | ||
| 507 | + this.hostRemoteVideoHeight = parseInt(_params.height) || 240; | ||
| 480 | } | 508 | } |
| 481 | 509 | ||
| 482 | /* | 510 | /* |
| @@ -484,10 +512,10 @@ class WebRtcApe extends Emiter { | @@ -484,10 +512,10 @@ class WebRtcApe extends Emiter { | ||
| 484 | * */ | 512 | * */ |
| 485 | setNormalRemoteMediaView(_params) { | 513 | setNormalRemoteMediaView(_params) { |
| 486 | loger.log("设置学生视图容器"); | 514 | loger.log("设置学生视图容器"); |
| 487 | - this.normalRemoteViewId = _params.divId||""; | ||
| 488 | - this.normalRemoteStyle = _params.styleStr||""; | ||
| 489 | - this.normalRemoteVideoWidth=parseInt(_params.width)||320; | ||
| 490 | - this.normalRemoteVideoHeight=parseInt(_params.height)||240; | 515 | + this.normalRemoteViewId = _params.divId || ""; |
| 516 | + this.normalRemoteStyle = _params.styleStr || ""; | ||
| 517 | + this.normalRemoteVideoWidth = parseInt(_params.width) || 320; | ||
| 518 | + this.normalRemoteVideoHeight = parseInt(_params.height) || 240; | ||
| 491 | } | 519 | } |
| 492 | 520 | ||
| 493 | /* | 521 | /* |
| @@ -495,80 +523,81 @@ class WebRtcApe extends Emiter { | @@ -495,80 +523,81 @@ class WebRtcApe extends Emiter { | ||
| 495 | * */ | 523 | * */ |
| 496 | setInvisibleMediaView(_params) { | 524 | setInvisibleMediaView(_params) { |
| 497 | loger.log("设置监课视图容器"); | 525 | loger.log("设置监课视图容器"); |
| 498 | - this.invisibleViewId = _params.divId||""; | ||
| 499 | - this.invisibleStyle = _params.styleStr||""; | ||
| 500 | - this.invisibleVideoWidth=parseInt(_params.width)||320; | ||
| 501 | - this.invisibleVideoHeight=parseInt(_params.height)||240; | 526 | + this.invisibleViewId = _params.divId || ""; |
| 527 | + this.invisibleStyle = _params.styleStr || ""; | ||
| 528 | + this.invisibleVideoWidth = parseInt(_params.width) || 320; | ||
| 529 | + this.invisibleVideoHeight = parseInt(_params.height) || 240; | ||
| 502 | } | 530 | } |
| 531 | + | ||
| 503 | /* | 532 | /* |
| 504 | * 切换当前使用的设备 | 533 | * 切换当前使用的设备 |
| 505 | * */ | 534 | * */ |
| 506 | - changeDevices(_params){ | ||
| 507 | - loger.log("切换设备->",_params); | ||
| 508 | - if(!_params){ | 535 | + changeDevices(_params) { |
| 536 | + loger.log("切换设备->", _params); | ||
| 537 | + if (!_params) { | ||
| 509 | return; | 538 | return; |
| 510 | } | 539 | } |
| 511 | //设置摄像头 | 540 | //设置摄像头 |
| 512 | - if(_params.curCamera){ | ||
| 513 | - for(let k in this.cameras){ | ||
| 514 | - let item=this.cameras[k]; | ||
| 515 | - if(item&&item.label==_params.curCamera){ | ||
| 516 | - this.curCameraId=item.deviceId; | ||
| 517 | - GlobalConfig.curCamera=_params.curCamera; | 541 | + if (_params.curCamera) { |
| 542 | + for (let k in this.cameras) { | ||
| 543 | + let item = this.cameras[k]; | ||
| 544 | + if (item && item.label == _params.curCamera) { | ||
| 545 | + this.curCameraId = item.deviceId; | ||
| 546 | + GlobalConfig.curCamera = _params.curCamera; | ||
| 518 | break; | 547 | break; |
| 519 | } | 548 | } |
| 520 | } | 549 | } |
| 521 | } | 550 | } |
| 522 | //设置麦克风 | 551 | //设置麦克风 |
| 523 | - if(_params.curMicrophone){ | ||
| 524 | - for(let k in this.microphones){ | ||
| 525 | - let item=this.microphones[k]; | ||
| 526 | - if(item&&item.label==_params.curMicrophone){ | ||
| 527 | - this.curMicrophoneId=item.deviceId; | ||
| 528 | - GlobalConfig.curMicrophone=_params.curMicrophone; | 552 | + if (_params.curMicrophone) { |
| 553 | + for (let k in this.microphones) { | ||
| 554 | + let item = this.microphones[k]; | ||
| 555 | + if (item && item.label == _params.curMicrophone) { | ||
| 556 | + this.curMicrophoneId = item.deviceId; | ||
| 557 | + GlobalConfig.curMicrophone = _params.curMicrophone; | ||
| 529 | break; | 558 | break; |
| 530 | } | 559 | } |
| 531 | } | 560 | } |
| 532 | } | 561 | } |
| 533 | //分辨率 | 562 | //分辨率 |
| 534 | - if(_params.videoResolution){ | ||
| 535 | - this.videoResolution=_params.videoResolution||"240P";//默认是240P 20 320x240 15 200 | 563 | + if (_params.videoResolution) { |
| 564 | + this.videoResolution = _params.videoResolution || "240P";//默认是240P 20 320x240 15 200 | ||
| 536 | } | 565 | } |
| 537 | 566 | ||
| 538 | clearTimeout(this.changeDevicesDelay); | 567 | clearTimeout(this.changeDevicesDelay); |
| 539 | - this.changeDevicesDelay=setTimeout(()=>{ | 568 | + this.changeDevicesDelay = setTimeout(()=> { |
| 540 | this.changePublishStatusAndServerRecord(WebRtcApe.RECORD_STATUS_0); | 569 | this.changePublishStatusAndServerRecord(WebRtcApe.RECORD_STATUS_0); |
| 541 | //重新获取本地视图流 | 570 | //重新获取本地视图流 |
| 542 | this.reGetLoaclStream(); | 571 | this.reGetLoaclStream(); |
| 543 | - },1400); | 572 | + }, 1400); |
| 544 | } | 573 | } |
| 545 | 574 | ||
| 546 | /* | 575 | /* |
| 547 | * 获取设备信息 | 576 | * 获取设备信息 |
| 548 | * */ | 577 | * */ |
| 549 | - getDevices(_params,_callback) { | 578 | + getDevices(_params, _callback) { |
| 550 | AgoraRTC.getDevices((devices)=> { | 579 | AgoraRTC.getDevices((devices)=> { |
| 551 | //下面的数组存的是对象 | 580 | //下面的数组存的是对象 |
| 552 | - this.microphones=[]; | ||
| 553 | - this.cameras=[]; | 581 | + this.microphones = []; |
| 582 | + this.cameras = []; | ||
| 554 | 583 | ||
| 555 | //选的数组存的是设备名称 | 584 | //选的数组存的是设备名称 |
| 556 | - GlobalConfig.cameras=[]; | ||
| 557 | - GlobalConfig.microphones=[]; | 585 | + GlobalConfig.cameras = []; |
| 586 | + GlobalConfig.microphones = []; | ||
| 558 | 587 | ||
| 559 | loger.log("devices", devices) | 588 | loger.log("devices", devices) |
| 560 | for (let i = 0; i < devices.length; i++) { | 589 | for (let i = 0; i < devices.length; i++) { |
| 561 | let device = devices[i]; | 590 | let device = devices[i]; |
| 562 | //{"deviceId":"default","kind":"audiooutput","label":"默认","groupId":"cf49a03ca26700235629fc13d3e6630bd34407c66438d157056a34dd3ae03ef5"} | 591 | //{"deviceId":"default","kind":"audiooutput","label":"默认","groupId":"cf49a03ca26700235629fc13d3e6630bd34407c66438d157056a34dd3ae03ef5"} |
| 563 | if (device.kind == 'audioinput') { | 592 | if (device.kind == 'audioinput') { |
| 564 | - if(!device.label){ | ||
| 565 | - device.label="麦克风_"+i; | 593 | + if (!device.label) { |
| 594 | + device.label = "麦克风_" + i; | ||
| 566 | } | 595 | } |
| 567 | this.microphones.push(device); | 596 | this.microphones.push(device); |
| 568 | GlobalConfig.microphones.push(device.label); | 597 | GlobalConfig.microphones.push(device.label); |
| 569 | } else if (device.kind == 'videoinput') { | 598 | } else if (device.kind == 'videoinput') { |
| 570 | - if(!device.label){ | ||
| 571 | - device.label="摄像头_"+i; | 599 | + if (!device.label) { |
| 600 | + device.label = "摄像头_" + i; | ||
| 572 | } | 601 | } |
| 573 | this.cameras.push(device); | 602 | this.cameras.push(device); |
| 574 | GlobalConfig.cameras.push(device.label); | 603 | GlobalConfig.cameras.push(device.label); |
| @@ -576,31 +605,31 @@ class WebRtcApe extends Emiter { | @@ -576,31 +605,31 @@ class WebRtcApe extends Emiter { | ||
| 576 | loger.warn('其他设备: ', device); | 605 | loger.warn('其他设备: ', device); |
| 577 | } | 606 | } |
| 578 | } | 607 | } |
| 579 | - let _deviceData={cameras:GlobalConfig.cameras,microphones:GlobalConfig.microphones}; | ||
| 580 | - if(_callback){ | 608 | + let _deviceData = {cameras: GlobalConfig.cameras, microphones: GlobalConfig.microphones}; |
| 609 | + if (_callback) { | ||
| 581 | _callback(_deviceData); | 610 | _callback(_deviceData); |
| 582 | } | 611 | } |
| 583 | - this._emit(MessageTypes.GET_DEVICES_SUCCESS,_deviceData); | 612 | + this._emit(MessageTypes.GET_DEVICES_SUCCESS, _deviceData); |
| 584 | }); | 613 | }); |
| 585 | } | 614 | } |
| 586 | 615 | ||
| 587 | //组织数据,发送给服务器,控制录制和开启录制-推流和停止推流 status:0 停止推流 1:开始推流(同时开启录制),2:停止录制(同时停止推流) | 616 | //组织数据,发送给服务器,控制录制和开启录制-推流和停止推流 status:0 停止推流 1:开始推流(同时开启录制),2:停止录制(同时停止推流) |
| 588 | - packMediaInfoData(_status){ | ||
| 589 | - let curTimestamp= new Date().getTime(); | ||
| 590 | - let data=`appId=${GlobalConfig.appId}&channel=${GlobalConfig.channelId}&channelKey=${GlobalConfig.appCertificate}&uid=${GlobalConfig.userUid}&status=${_status}&userId=${GlobalConfig.userId}&userName=${GlobalConfig.userName}&userRole=${GlobalConfig.userRole}×tamp=${curTimestamp}&recordTimestamp=${GlobalConfig.recordTimestamp}`; | 617 | + packMediaInfoData(_status) { |
| 618 | + let curTimestamp = new Date().getTime(); | ||
| 619 | + let data = `appId=${GlobalConfig.appId}&channel=${GlobalConfig.channelId}&channelKey=${GlobalConfig.appCertificate}&uid=${GlobalConfig.userUid}&status=${_status}&userId=${GlobalConfig.userId}&userName=${GlobalConfig.userName}&userRole=${GlobalConfig.userRole}×tamp=${curTimestamp}&recordTimestamp=${GlobalConfig.recordTimestamp}`; | ||
| 591 | 620 | ||
| 592 | //mcu记录一份数据 | 621 | //mcu记录一份数据 |
| 593 | this._emit(MessageTypes.MEDIA_PUBLISH_STATUS_CHANGE, { | 622 | this._emit(MessageTypes.MEDIA_PUBLISH_STATUS_CHANGE, { |
| 594 | - appId:GlobalConfig.appId, | ||
| 595 | - channel:GlobalConfig.channelId, | ||
| 596 | - channelKey:GlobalConfig.appCertificate, | ||
| 597 | - uid:GlobalConfig.userUid, | ||
| 598 | - status:_status, | ||
| 599 | - userId:GlobalConfig.userId, | ||
| 600 | - userName:GlobalConfig.userName, | ||
| 601 | - userRole:GlobalConfig.userRole, | ||
| 602 | - timestamp:curTimestamp, | ||
| 603 | - recordTimestamp:GlobalConfig.recordTimestamp | 623 | + appId: GlobalConfig.appId, |
| 624 | + channel: GlobalConfig.channelId, | ||
| 625 | + channelKey: GlobalConfig.appCertificate, | ||
| 626 | + uid: GlobalConfig.userUid, | ||
| 627 | + status: _status, | ||
| 628 | + userId: GlobalConfig.userId, | ||
| 629 | + userName: GlobalConfig.userName, | ||
| 630 | + userRole: GlobalConfig.userRole, | ||
| 631 | + timestamp: curTimestamp, | ||
| 632 | + recordTimestamp: GlobalConfig.recordTimestamp | ||
| 604 | }); | 633 | }); |
| 605 | return data; | 634 | return data; |
| 606 | } | 635 | } |
| @@ -608,13 +637,13 @@ class WebRtcApe extends Emiter { | @@ -608,13 +637,13 @@ class WebRtcApe extends Emiter { | ||
| 608 | //调用服务端接口 | 637 | //调用服务端接口 |
| 609 | //调用推流/停止推流->并且告诉服务器端开启录制 | 638 | //调用推流/停止推流->并且告诉服务器端开启录制 |
| 610 | //status:0 停止推流 1:开始推流(同时开启录制),2:停止录制(同时停止推流) | 639 | //status:0 停止推流 1:开始推流(同时开启录制),2:停止录制(同时停止推流) |
| 611 | - changePublishStatusAndServerRecord(_status){ | ||
| 612 | - if(!GlobalConfig.recordInterfaces){ | 640 | + changePublishStatusAndServerRecord(_status) { |
| 641 | + if (!GlobalConfig.recordInterfaces) { | ||
| 613 | loger.log("调用服务器端开启录制->失败->接口地址无效"); | 642 | loger.log("调用服务器端开启录制->失败->接口地址无效"); |
| 614 | return; | 643 | return; |
| 615 | } | 644 | } |
| 616 | - let url=GlobalConfig.locationProtocol+GlobalConfig.recordInterfaces; | ||
| 617 | - let data=this.packMediaInfoData(_status); | 645 | + let url = GlobalConfig.locationProtocol + GlobalConfig.recordInterfaces; |
| 646 | + let data = this.packMediaInfoData(_status); | ||
| 618 | fetch(encodeURI(url), { | 647 | fetch(encodeURI(url), { |
| 619 | method: 'POST', | 648 | method: 'POST', |
| 620 | headers: { | 649 | headers: { |
| @@ -633,7 +662,7 @@ class WebRtcApe extends Emiter { | @@ -633,7 +662,7 @@ class WebRtcApe extends Emiter { | ||
| 633 | }) | 662 | }) |
| 634 | .then(ret => { | 663 | .then(ret => { |
| 635 | if (ret) { | 664 | if (ret) { |
| 636 | - loger.log('调用服务器端开启录制完成',ret); | 665 | + loger.log('调用服务器端开启录制完成', ret); |
| 637 | } else { | 666 | } else { |
| 638 | loger.warn('调用服务器端开启录制 失败.', ret); | 667 | loger.warn('调用服务器端开启录制 失败.', ret); |
| 639 | } | 668 | } |
| @@ -644,14 +673,14 @@ class WebRtcApe extends Emiter { | @@ -644,14 +673,14 @@ class WebRtcApe extends Emiter { | ||
| 644 | } | 673 | } |
| 645 | 674 | ||
| 646 | //调用媒体服务停止录制 | 675 | //调用媒体服务停止录制 |
| 647 | - stopRecordingMedia(){ | 676 | + stopRecordingMedia() { |
| 648 | //192.168.31.8:3000/recordInfo/stopRecording/ | 677 | //192.168.31.8:3000/recordInfo/stopRecording/ |
| 649 | - if(!GlobalConfig.stopRecordingInterfaces){ | 678 | + if (!GlobalConfig.stopRecordingInterfaces) { |
| 650 | loger.log("调用服务器端开启录制->失败->接口地址无效"); | 679 | loger.log("调用服务器端开启录制->失败->接口地址无效"); |
| 651 | return; | 680 | return; |
| 652 | } | 681 | } |
| 653 | - let url=GlobalConfig.locationProtocol+GlobalConfig.stopRecordingInterfaces; | ||
| 654 | - let data=this.packMediaInfoData(WebRtcApe.RECORD_STATUS_2); | 682 | + let url = GlobalConfig.locationProtocol + GlobalConfig.stopRecordingInterfaces; |
| 683 | + let data = this.packMediaInfoData(WebRtcApe.RECORD_STATUS_2); | ||
| 655 | fetch(encodeURI(url), { | 684 | fetch(encodeURI(url), { |
| 656 | method: 'POST', | 685 | method: 'POST', |
| 657 | headers: { | 686 | headers: { |
| @@ -670,7 +699,7 @@ class WebRtcApe extends Emiter { | @@ -670,7 +699,7 @@ class WebRtcApe extends Emiter { | ||
| 670 | }) | 699 | }) |
| 671 | .then(ret => { | 700 | .then(ret => { |
| 672 | if (ret) { | 701 | if (ret) { |
| 673 | - loger.log('调用服务器端开启录制完成',ret); | 702 | + loger.log('调用服务器端开启录制完成', ret); |
| 674 | } else { | 703 | } else { |
| 675 | loger.warn('调用服务器端开启录制 失败.', ret); | 704 | loger.warn('调用服务器端开启录制 失败.', ret); |
| 676 | } | 705 | } |
| @@ -680,9 +709,9 @@ class WebRtcApe extends Emiter { | @@ -680,9 +709,9 @@ class WebRtcApe extends Emiter { | ||
| 680 | }); | 709 | }); |
| 681 | } | 710 | } |
| 682 | } | 711 | } |
| 683 | -WebRtcApe.prototype.RECORD_STATUS_0 = WebRtcApe.RECORD_STATUS_0 =0; //停止推流 | ||
| 684 | -WebRtcApe.prototype.RECORD_STATUS_1 = WebRtcApe.RECORD_STATUS_1 =1; //开始推流 | ||
| 685 | -WebRtcApe.prototype.RECORD_STATUS_2 = WebRtcApe.RECORD_STATUS_2 =2; //停止录制 | 712 | +WebRtcApe.prototype.RECORD_STATUS_0 = WebRtcApe.RECORD_STATUS_0 = 0; //停止推流 |
| 713 | +WebRtcApe.prototype.RECORD_STATUS_1 = WebRtcApe.RECORD_STATUS_1 = 1; //开始推流 | ||
| 714 | +WebRtcApe.prototype.RECORD_STATUS_2 = WebRtcApe.RECORD_STATUS_2 = 2; //停止录制 | ||
| 686 | export default new WebRtcApe; | 715 | export default new WebRtcApe; |
| 687 | 716 | ||
| 688 | 717 |
-
请 注册 或 登录 后发表评论