1.新增MCU断线重连、MCU动态选点的功能(断线重连3次,间隔5秒);2.MS动态选点功能(在开始上课状态下每15秒动态获取一次MS);3.动态选点的两个接口(MS,MCU)
正在显示
7 个修改的文件
包含
135 行增加
和
55 行删除
此 diff 太大无法显示。
| @@ -27,7 +27,7 @@ import Server from "config/Server"; | @@ -27,7 +27,7 @@ import Server from "config/Server"; | ||
| 27 | import UTF8 from 'utf-8'; | 27 | import UTF8 from 'utf-8'; |
| 28 | 28 | ||
| 29 | let loger = Loger.getLoger('McuClient'); | 29 | let loger = Loger.getLoger('McuClient'); |
| 30 | -let _sdkInfo = {"version": "v1.9.14.20170420", "author": "www.3mang.com"}; | 30 | +let _sdkInfo = {"version": "v1.9.15.20170420", "author": "www.3mang.com"}; |
| 31 | 31 | ||
| 32 | //APE | 32 | //APE |
| 33 | let _sass; | 33 | let _sass; |
| @@ -78,7 +78,7 @@ export default class MessageEntrance extends Emiter { | @@ -78,7 +78,7 @@ export default class MessageEntrance extends Emiter { | ||
| 78 | _mcu = Mcu; | 78 | _mcu = Mcu; |
| 79 | _mcu.on('*', (type, data) => this._emit(type, data)); | 79 | _mcu.on('*', (type, data) => this._emit(type, data)); |
| 80 | _mcu.on(MessageTypes.CLASS_JOIN_MCU_SUCCESS, this._mcuJoinMCUClassSuccessHandler.bind(this));//加入MCU课堂完成 | 80 | _mcu.on(MessageTypes.CLASS_JOIN_MCU_SUCCESS, this._mcuJoinMCUClassSuccessHandler.bind(this));//加入MCU课堂完成 |
| 81 | - _mcu.on(MessageTypes.CHANGE_MCU_IP, this._changeMcuIpHandler.bind(this));//切换MCU,重新选点 | 81 | + _mcu.on(MessageTypes.SWITCH_MCU_IP, this._switchMcuIpHandler.bind(this));//切换MCU,重新选点 |
| 82 | 82 | ||
| 83 | //录制回放 | 83 | //录制回放 |
| 84 | _recordPlayback = RecordPlayBackParse; | 84 | _recordPlayback = RecordPlayBackParse; |
| @@ -96,6 +96,8 @@ export default class MessageEntrance extends Emiter { | @@ -96,6 +96,8 @@ export default class MessageEntrance extends Emiter { | ||
| 96 | _confer_ape.on(MessageTypes.CLASS_NONENTITY_ROSTER, this._onClassNonentityRoster.bind(this));//当前课堂中视频或音频占用channel的nodeId ,在人员列表中不存在 | 96 | _confer_ape.on(MessageTypes.CLASS_NONENTITY_ROSTER, this._onClassNonentityRoster.bind(this));//当前课堂中视频或音频占用channel的nodeId ,在人员列表中不存在 |
| 97 | _confer_ape.on(MessageTypes.CLASS_RECORD_START, this._onClassRecordStart.bind(this));//课堂开始录制 | 97 | _confer_ape.on(MessageTypes.CLASS_RECORD_START, this._onClassRecordStart.bind(this));//课堂开始录制 |
| 98 | _confer_ape.on(MessageTypes.CLASS_RECORD_SUCCESS, this._onClassRecordSuccess.bind(this));//课堂开启录制成功 | 98 | _confer_ape.on(MessageTypes.CLASS_RECORD_SUCCESS, this._onClassRecordSuccess.bind(this));//课堂开启录制成功 |
| 99 | + _confer_ape.on(MessageTypes.SWITCH_MS_IP, this._switchMsIpHandler.bind(this));//MS动态选点 | ||
| 100 | + | ||
| 99 | 101 | ||
| 100 | _chat_ape = new ChatApe(); | 102 | _chat_ape = new ChatApe(); |
| 101 | _chat_ape.on('*', (type, data) => this._emit(type, data)); | 103 | _chat_ape.on('*', (type, data) => this._emit(type, data)); |
| @@ -149,7 +151,6 @@ export default class MessageEntrance extends Emiter { | @@ -149,7 +151,6 @@ export default class MessageEntrance extends Emiter { | ||
| 149 | this.stopPublishVideo = this.unPublishVideo = this._stopPublishVideo.bind(this); | 151 | this.stopPublishVideo = this.unPublishVideo = this._stopPublishVideo.bind(this); |
| 150 | this.sendVideoBroadcastMsg = this._sendVideoBroadcastMsg.bind(this); | 152 | this.sendVideoBroadcastMsg = this._sendVideoBroadcastMsg.bind(this); |
| 151 | 153 | ||
| 152 | - | ||
| 153 | //audioApe | 154 | //audioApe |
| 154 | //this.getAudioPlayPath = this._getPlayAudioPath.bind(this); | 155 | //this.getAudioPlayPath = this._getPlayAudioPath.bind(this); |
| 155 | this.getAudioPublishPath = this._getPublishAudioPath.bind(this); | 156 | this.getAudioPublishPath = this._getPublishAudioPath.bind(this); |
| @@ -180,8 +181,10 @@ export default class MessageEntrance extends Emiter { | @@ -180,8 +181,10 @@ export default class MessageEntrance extends Emiter { | ||
| 180 | this.getDocFullAddress = this._getDocFullAddress.bind(this);//获取文档资源地址 | 181 | this.getDocFullAddress = this._getDocFullAddress.bind(this);//获取文档资源地址 |
| 181 | 182 | ||
| 182 | 183 | ||
| 183 | - this.setDebuger = this._setDebuger.bind(this);//debug | 184 | + //this.setDebuger = this._setDebuger.bind(this);//debug |
| 184 | this.setMessageDelay = this._setMessageDelay.bind(this);//设置是否延迟消息 | 185 | this.setMessageDelay = this._setMessageDelay.bind(this);//设置是否延迟消息 |
| 186 | + this.switchServer = this._switchMcuIpHandler.bind(this);//切换mcu服务器 | ||
| 187 | + this.switchMediaServer = this._switchMsIpHandler.bind(this);//切换ms服务器 | ||
| 185 | } | 188 | } |
| 186 | 189 | ||
| 187 | _setDebuger(_data) { | 190 | _setDebuger(_data) { |
| @@ -291,7 +294,7 @@ export default class MessageEntrance extends Emiter { | @@ -291,7 +294,7 @@ export default class MessageEntrance extends Emiter { | ||
| 291 | //{"classId":"1653304953","portal":"112.126.80.182:80","userRole":"normal","userId":0} | 294 | //{"classId":"1653304953","portal":"112.126.80.182:80","userRole":"normal","userId":0} |
| 292 | //判断传入的参数是否存在 | 295 | //判断传入的参数是否存在 |
| 293 | if (_param == null || EngineUtils.isEmptyObject(_param)) { | 296 | if (_param == null || EngineUtils.isEmptyObject(_param)) { |
| 294 | - loger.error('初始化课堂失败->参数错误',_param); | 297 | + loger.error('初始化课堂失败->参数错误', _param); |
| 295 | this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_CLASS_INIT_PARAM); | 298 | this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_CLASS_INIT_PARAM); |
| 296 | return; | 299 | return; |
| 297 | } | 300 | } |
| @@ -453,7 +456,7 @@ export default class MessageEntrance extends Emiter { | @@ -453,7 +456,7 @@ export default class MessageEntrance extends Emiter { | ||
| 453 | let index = parseInt(Math.random() * _data.mcuList.length); | 456 | let index = parseInt(Math.random() * _data.mcuList.length); |
| 454 | GlobalConfig.MCUServerIP = _data.mcuList[index].ip || ""; | 457 | GlobalConfig.MCUServerIP = _data.mcuList[index].ip || ""; |
| 455 | GlobalConfig.MCUServerPort = _data.mcuList[index].port || ""; | 458 | GlobalConfig.MCUServerPort = _data.mcuList[index].port || ""; |
| 456 | - loger.log('初始->MCU->.', GlobalConfig.MCUServerIP , GlobalConfig.MCUServerPort ); | 459 | + loger.log('初始->MCU->.', GlobalConfig.MCUServerIP, GlobalConfig.MCUServerPort); |
| 457 | } | 460 | } |
| 458 | 461 | ||
| 459 | //上课中视频推流播流地址 | 462 | //上课中视频推流播流地址 |
| @@ -465,7 +468,7 @@ export default class MessageEntrance extends Emiter { | @@ -465,7 +468,7 @@ export default class MessageEntrance extends Emiter { | ||
| 465 | let index = parseInt(Math.random() * _data.msList.length); | 468 | let index = parseInt(Math.random() * _data.msList.length); |
| 466 | GlobalConfig.MSServerIP = _data.msList[index].ip || ""; | 469 | GlobalConfig.MSServerIP = _data.msList[index].ip || ""; |
| 467 | GlobalConfig.MSServerPort = _data.msList[index].port || ""; | 470 | GlobalConfig.MSServerPort = _data.msList[index].port || ""; |
| 468 | - loger.log('初始->MS->.', GlobalConfig.MSServerIP , GlobalConfig.MSServerPort ); | 471 | + loger.log('初始->MS->.', GlobalConfig.MSServerIP, GlobalConfig.MSServerPort); |
| 469 | } | 472 | } |
| 470 | 473 | ||
| 471 | //录制回放时m3u8播流地址 | 474 | //录制回放时m3u8播流地址 |
| @@ -474,10 +477,10 @@ export default class MessageEntrance extends Emiter { | @@ -474,10 +477,10 @@ export default class MessageEntrance extends Emiter { | ||
| 474 | //GlobalConfig.RSServerIP = _data.rsList[0].ip || ""; | 477 | //GlobalConfig.RSServerIP = _data.rsList[0].ip || ""; |
| 475 | //GlobalConfig.RSServerPort = _data.rsList[0].port || ""; | 478 | //GlobalConfig.RSServerPort = _data.rsList[0].port || ""; |
| 476 | 479 | ||
| 477 | - let index = parseInt(Math.random() * _data.msList.length); | 480 | + let index = parseInt(Math.random() * _data.rsList.length); |
| 478 | GlobalConfig.RSServerIP = _data.rsList[index].ip || ""; | 481 | GlobalConfig.RSServerIP = _data.rsList[index].ip || ""; |
| 479 | GlobalConfig.RSServerPort = _data.rsList[index].port || ""; | 482 | GlobalConfig.RSServerPort = _data.rsList[index].port || ""; |
| 480 | - loger.log('初始->RS->.', GlobalConfig.RSServerIP , GlobalConfig.RSServerPort ); | 483 | + loger.log('初始->RS->.', GlobalConfig.RSServerIP, GlobalConfig.RSServerPort); |
| 481 | } | 484 | } |
| 482 | 485 | ||
| 483 | //文档地址 | 486 | //文档地址 |
| @@ -487,7 +490,7 @@ export default class MessageEntrance extends Emiter { | @@ -487,7 +490,7 @@ export default class MessageEntrance extends Emiter { | ||
| 487 | loger.log("docServer->", _data.docList[index]); | 490 | loger.log("docServer->", _data.docList[index]); |
| 488 | GlobalConfig.DOCServerIP = _data.docList[index].ip || ""; | 491 | GlobalConfig.DOCServerIP = _data.docList[index].ip || ""; |
| 489 | GlobalConfig.DOCServerPort = _data.docList[index].port || ""; | 492 | GlobalConfig.DOCServerPort = _data.docList[index].port || ""; |
| 490 | - loger.log('初始->DOC->.', GlobalConfig.DOCServerIP , GlobalConfig.DOCServerPort ); | 493 | + loger.log('初始->DOC->.', GlobalConfig.DOCServerIP, GlobalConfig.DOCServerPort); |
| 491 | } | 494 | } |
| 492 | 495 | ||
| 493 | //record | 496 | //record |
| @@ -499,7 +502,7 @@ export default class MessageEntrance extends Emiter { | @@ -499,7 +502,7 @@ export default class MessageEntrance extends Emiter { | ||
| 499 | let index = parseInt(Math.random() * _data.recordList.length); | 502 | let index = parseInt(Math.random() * _data.recordList.length); |
| 500 | GlobalConfig.RecordServerIP = _data.recordList[index].ip || ""; | 503 | GlobalConfig.RecordServerIP = _data.recordList[index].ip || ""; |
| 501 | GlobalConfig.RecordServerPort = _data.recordList[index].port || ""; | 504 | GlobalConfig.RecordServerPort = _data.recordList[index].port || ""; |
| 502 | - loger.log('初始->RECORD->.', GlobalConfig.RecordServerIP , GlobalConfig.RecordServerPort ); | 505 | + loger.log('初始->RECORD->.', GlobalConfig.RecordServerIP, GlobalConfig.RecordServerPort); |
| 503 | } | 506 | } |
| 504 | 507 | ||
| 505 | } | 508 | } |
| @@ -562,8 +565,8 @@ export default class MessageEntrance extends Emiter { | @@ -562,8 +565,8 @@ export default class MessageEntrance extends Emiter { | ||
| 562 | this._getFastestMsServer(function (_data) { | 565 | this._getFastestMsServer(function (_data) { |
| 563 | loger.log("MS选点结束->", _data); | 566 | loger.log("MS选点结束->", _data); |
| 564 | if (_data && _data.ip) { | 567 | if (_data && _data.ip) { |
| 565 | - GlobalConfig.MSServerIP = _data.ip||""; | ||
| 566 | - GlobalConfig.MSServerPort = _data.port||""; | 568 | + GlobalConfig.MSServerIP = _data.ip || ""; |
| 569 | + GlobalConfig.MSServerPort = _data.port || ""; | ||
| 567 | } | 570 | } |
| 568 | loger.log("当前使用的MS->", GlobalConfig.MSServerIP, GlobalConfig.MSServerPort); | 571 | loger.log("当前使用的MS->", GlobalConfig.MSServerIP, GlobalConfig.MSServerPort); |
| 569 | _this.isGetFastestMcuCallback = true; | 572 | _this.isGetFastestMcuCallback = true; |
| @@ -572,8 +575,8 @@ export default class MessageEntrance extends Emiter { | @@ -572,8 +575,8 @@ export default class MessageEntrance extends Emiter { | ||
| 572 | this._getFastestMcuServer(function (_data) { | 575 | this._getFastestMcuServer(function (_data) { |
| 573 | loger.log("MCU选点结束->", _data); | 576 | loger.log("MCU选点结束->", _data); |
| 574 | if (_data && _data.ip) { | 577 | if (_data && _data.ip) { |
| 575 | - GlobalConfig.MCUServerIP = _data.ip||""; | ||
| 576 | - GlobalConfig.MCUServerPort = _data.port||""; | 578 | + GlobalConfig.MCUServerIP = _data.ip || ""; |
| 579 | + GlobalConfig.MCUServerPort = _data.port || ""; | ||
| 577 | } | 580 | } |
| 578 | loger.log("当前使用的MCU->", GlobalConfig.MCUServerIP, GlobalConfig.MCUServerPort); | 581 | loger.log("当前使用的MCU->", GlobalConfig.MCUServerIP, GlobalConfig.MCUServerPort); |
| 579 | _this.isGetFastestMsCallback = true; | 582 | _this.isGetFastestMsCallback = true; |
| @@ -682,6 +685,13 @@ export default class MessageEntrance extends Emiter { | @@ -682,6 +685,13 @@ export default class MessageEntrance extends Emiter { | ||
| 682 | } | 685 | } |
| 683 | } | 686 | } |
| 684 | 687 | ||
| 688 | + _switchMcuIp() { | ||
| 689 | + loger.log('切换MCU IP->.'); | ||
| 690 | + if (_mcu) { | ||
| 691 | + _mcu.switchMCUIp(GlobalConfig.getClassInfo()); | ||
| 692 | + } | ||
| 693 | + } | ||
| 694 | + | ||
| 685 | // MCU 课堂成功 | 695 | // MCU 课堂成功 |
| 686 | _mcuJoinMCUClassSuccessHandler(_data) { | 696 | _mcuJoinMCUClassSuccessHandler(_data) { |
| 687 | //loger.log('MCU 课堂成功.'); | 697 | //loger.log('MCU 课堂成功.'); |
| @@ -745,19 +755,22 @@ export default class MessageEntrance extends Emiter { | @@ -745,19 +755,22 @@ export default class MessageEntrance extends Emiter { | ||
| 745 | this._emit(MessageTypes.CLASS_JOIN_SUCCESS, joinClassSuccessCallBackData); | 755 | this._emit(MessageTypes.CLASS_JOIN_SUCCESS, joinClassSuccessCallBackData); |
| 746 | } | 756 | } |
| 747 | 757 | ||
| 748 | - //切换MCU | ||
| 749 | - _changeMcuIpHandler() { | 758 | + //切换MCU ->_param->{reConnect:false} //reConnect(是否立即替换当前的ip并且重新连接) |
| 759 | + _switchMcuIpHandler(_param) { | ||
| 750 | if (GlobalConfig.isRecordPlayBack) { | 760 | if (GlobalConfig.isRecordPlayBack) { |
| 751 | - //录制回放不做操作 | 761 | + loger.log('录制回放->不进行MCU动态选点'); |
| 752 | return; | 762 | return; |
| 753 | } | 763 | } |
| 754 | loger.log('MCU->动态选点'); | 764 | loger.log('MCU->动态选点'); |
| 755 | let _this = this; | 765 | let _this = this; |
| 756 | this._getFastestMcuServer(function (_data) { | 766 | this._getFastestMcuServer(function (_data) { |
| 757 | loger.log("MCU选点结束->", _data); | 767 | loger.log("MCU选点结束->", _data); |
| 768 | + //记录当前的IP地址,选点结束后需要判断一下是否是新的IP; | ||
| 769 | + let oldIp= GlobalConfig.MCUServerIP; | ||
| 770 | + | ||
| 758 | if (_data && _data.ip) { | 771 | if (_data && _data.ip) { |
| 759 | - GlobalConfig.MCUServerIP = _data.ip||""; | ||
| 760 | - GlobalConfig.MCUServerPort = _data.port||""; | 772 | + GlobalConfig.MCUServerIP = _data.ip || ""; |
| 773 | + GlobalConfig.MCUServerPort = _data.port || ""; | ||
| 761 | } else { | 774 | } else { |
| 762 | //随机选择一个 | 775 | //随机选择一个 |
| 763 | if (GlobalConfig.mcuList && GlobalConfig.mcuList.length > 0) { | 776 | if (GlobalConfig.mcuList && GlobalConfig.mcuList.length > 0) { |
| @@ -766,23 +779,40 @@ export default class MessageEntrance extends Emiter { | @@ -766,23 +779,40 @@ export default class MessageEntrance extends Emiter { | ||
| 766 | GlobalConfig.MCUServerPort = GlobalConfig.mcuList[index].port || ""; | 779 | GlobalConfig.MCUServerPort = GlobalConfig.mcuList[index].port || ""; |
| 767 | } | 780 | } |
| 768 | } | 781 | } |
| 769 | - loger.log('MCU->切换->', GlobalConfig.MCUServerIP, GlobalConfig.MCUServerPort); | 782 | + if(oldIp&&oldIp!=GlobalConfig.MCUServerIP){ |
| 783 | + loger.log('MCU->最新地址->', GlobalConfig.MCUServerIP, GlobalConfig.MCUServerPort); | ||
| 784 | + //判断是否需要主动断开当前的连接然后重连新的服务器 | ||
| 785 | + if (_param && _param.reConnect == true) { | ||
| 786 | + loger.log('MCU->切换到最新的IP->', GlobalConfig.MCUServerIP, GlobalConfig.MCUServerPort); | ||
| 787 | + _this._startConnectMCU(); | ||
| 788 | + }else { | ||
| 789 | + //不需要断开当前的连接,更改ip即可 | ||
| 790 | + _this._switchMcuIp(); | ||
| 791 | + } | ||
| 792 | + }else { | ||
| 793 | + //如果选点结束后获得的ip和当前的IP相同,不需要切换 | ||
| 794 | + loger.log('MCU不需要切换->之前的IP->',oldIp,"新的IP->",GlobalConfig.MCUServerIP); | ||
| 795 | + } | ||
| 770 | }); | 796 | }); |
| 771 | } | 797 | } |
| 772 | 798 | ||
| 773 | - //切换MS | ||
| 774 | - _changeMsIpHandler() { | 799 | + //切换MS ->_param->{reConnect:false} //reConnect(是否立即替换当前的ip并且重新连接) |
| 800 | + _switchMsIpHandler(_param) { | ||
| 775 | if (GlobalConfig.isRecordPlayBack) { | 801 | if (GlobalConfig.isRecordPlayBack) { |
| 776 | //录制回放不做操作 | 802 | //录制回放不做操作 |
| 803 | + loger.log('录制回放->不进行MS动态选点'); | ||
| 777 | return; | 804 | return; |
| 778 | } | 805 | } |
| 779 | loger.log('MS->动态选点'); | 806 | loger.log('MS->动态选点'); |
| 780 | let _this = this; | 807 | let _this = this; |
| 781 | this._getFastestMsServer(function (_data) { | 808 | this._getFastestMsServer(function (_data) { |
| 782 | loger.log("MS选点结束->", _data); | 809 | loger.log("MS选点结束->", _data); |
| 810 | + //记录当前的IP地址,选点结束后需要判断一下是否是新的IP; | ||
| 811 | + let oldIp= GlobalConfig.MCUServerIP; | ||
| 812 | + | ||
| 783 | if (_data && _data.ip) { | 813 | if (_data && _data.ip) { |
| 784 | - GlobalConfig.MSServerIP = _data.ip||""; | ||
| 785 | - GlobalConfig.MSServerPort = _data.port||""; | 814 | + GlobalConfig.MSServerIP = _data.ip || ""; |
| 815 | + GlobalConfig.MSServerPort = _data.port || ""; | ||
| 786 | } else { | 816 | } else { |
| 787 | //随机选择一个 | 817 | //随机选择一个 |
| 788 | if (GlobalConfig.msList && GlobalConfig.msList.length > 0) { | 818 | if (GlobalConfig.msList && GlobalConfig.msList.length > 0) { |
| @@ -791,7 +821,20 @@ export default class MessageEntrance extends Emiter { | @@ -791,7 +821,20 @@ export default class MessageEntrance extends Emiter { | ||
| 791 | GlobalConfig.MSServerPort = GlobalConfig.msList[index].port || ""; | 821 | GlobalConfig.MSServerPort = GlobalConfig.msList[index].port || ""; |
| 792 | } | 822 | } |
| 793 | } | 823 | } |
| 794 | - loger.log('MS->切换->', GlobalConfig.MSServerIP, GlobalConfig.MSServerPort); | 824 | + |
| 825 | + | ||
| 826 | + if(oldIp&&oldIp!=GlobalConfig.MSServerIP){ | ||
| 827 | + /* loger.log('MS->切换地址->', GlobalConfig.MSServerIP, GlobalConfig.MSServerPort); | ||
| 828 | + //判断是否需要断开当前的连接重连新的服务器 | ||
| 829 | + if (_param && _param.reConnect == true) { | ||
| 830 | + loger.log('MS->最新地址->', GlobalConfig.MSServerIP, GlobalConfig.MSServerPort); | ||
| 831 | + }*/ | ||
| 832 | + loger.log('MS->最新地址->', GlobalConfig.MSServerIP, GlobalConfig.MSServerPort); | ||
| 833 | + }else { | ||
| 834 | + //如果选点结束后获得的ip和当前的IP相同,不需要切换 | ||
| 835 | + loger.log('MS不需要切换->IP',GlobalConfig.MSServerIP); | ||
| 836 | + } | ||
| 837 | + | ||
| 795 | }); | 838 | }); |
| 796 | } | 839 | } |
| 797 | 840 |
| @@ -27,6 +27,7 @@ class EverSocket extends Emiter { | @@ -27,6 +27,7 @@ class EverSocket extends Emiter { | ||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | begin(ip, port) { | 29 | begin(ip, port) { |
| 30 | + this._clearHistory(); | ||
| 30 | loger.log('开始WebSocket应用.'); | 31 | loger.log('开始WebSocket应用.'); |
| 31 | this._enableEverSocket = true; | 32 | this._enableEverSocket = true; |
| 32 | this.wsURL = 'ws://' + ip + ':' + port; | 33 | this.wsURL = 'ws://' + ip + ':' + port; |
| @@ -37,7 +38,9 @@ class EverSocket extends Emiter { | @@ -37,7 +38,9 @@ class EverSocket extends Emiter { | ||
| 37 | loger.log('停止WebSocket应用.'); | 38 | loger.log('停止WebSocket应用.'); |
| 38 | this._clear(); | 39 | this._clear(); |
| 39 | } | 40 | } |
| 40 | - | 41 | + switchSocketIp(ip,port) { |
| 42 | + this.wsURL = 'ws://' + ip + ':' + port; | ||
| 43 | + } | ||
| 41 | get connected() { | 44 | get connected() { |
| 42 | return this._connected; | 45 | return this._connected; |
| 43 | } | 46 | } |
| @@ -45,7 +48,7 @@ class EverSocket extends Emiter { | @@ -45,7 +48,7 @@ class EverSocket extends Emiter { | ||
| 45 | send(data) { | 48 | send(data) { |
| 46 | if (this._connected) { | 49 | if (this._connected) { |
| 47 | if (data) { | 50 | if (data) { |
| 48 | - loger.log('SEND MESSAGE,byteLength---->', data.byteLength); | 51 | + loger.log('SEND MESSAGE-->byteLength->', data.byteLength); |
| 49 | } else { | 52 | } else { |
| 50 | loger.log('SEND MESSAGE---->'); | 53 | loger.log('SEND MESSAGE---->'); |
| 51 | } | 54 | } |
| @@ -91,7 +94,6 @@ class EverSocket extends Emiter { | @@ -91,7 +94,6 @@ class EverSocket extends Emiter { | ||
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | _clear() { | 96 | _clear() { |
| 94 | - //this._emit(EverSocket.CLOSED); | ||
| 95 | loger.log('WebSocket,Timers销毁'); | 97 | loger.log('WebSocket,Timers销毁'); |
| 96 | window.clearInterval(this.pingTimer); | 98 | window.clearInterval(this.pingTimer); |
| 97 | window.clearInterval(this.pongTimer); | 99 | window.clearInterval(this.pongTimer); |
| @@ -114,7 +116,29 @@ class EverSocket extends Emiter { | @@ -114,7 +116,29 @@ class EverSocket extends Emiter { | ||
| 114 | this.websocket = undefined; | 116 | this.websocket = undefined; |
| 115 | 117 | ||
| 116 | } | 118 | } |
| 117 | - | 119 | + _clearHistory(){ |
| 120 | + loger.log('WebSocket->清除记录'); | ||
| 121 | + window.clearInterval(this.pingTimer); | ||
| 122 | + window.clearInterval(this.pongTimer); | ||
| 123 | + window.clearInterval(this.reConnectionTimeout); | ||
| 124 | + //this._setConnected(false);//先设置状态 | ||
| 125 | + this._connected = false; | ||
| 126 | + this._enableEverSocket = false; | ||
| 127 | + if (this.websocket == null) { | ||
| 128 | + loger.log('WebSocket->已经销毁'); | ||
| 129 | + return; | ||
| 130 | + } | ||
| 131 | + this.websocket.onopen = undefined; | ||
| 132 | + this.websocket.onclose = undefined; | ||
| 133 | + this.websocket.onerror = undefined; | ||
| 134 | + this.websocket.onmessage = undefined; | ||
| 135 | + try { | ||
| 136 | + this.websocket.close(); | ||
| 137 | + } catch (e) { | ||
| 138 | + loger.log('ignore errors'); | ||
| 139 | + } | ||
| 140 | + this.websocket = undefined; | ||
| 141 | + } | ||
| 118 | _onOpen() { | 142 | _onOpen() { |
| 119 | loger.log('WebSocket建立成功', this.wsURL); | 143 | loger.log('WebSocket建立成功', this.wsURL); |
| 120 | this.reConnectionCounter = 0; | 144 | this.reConnectionCounter = 0; |
| @@ -138,9 +162,9 @@ class EverSocket extends Emiter { | @@ -138,9 +162,9 @@ class EverSocket extends Emiter { | ||
| 138 | } | 162 | } |
| 139 | 163 | ||
| 140 | _onMessage(messageEvent) { | 164 | _onMessage(messageEvent) { |
| 141 | - loger.log('<----RECEIVE MESSAGE'); | ||
| 142 | this._lastActiveTime = Date.now(); | 165 | this._lastActiveTime = Date.now(); |
| 143 | const bufferData = messageEvent.data; | 166 | const bufferData = messageEvent.data; |
| 167 | + loger.log('RECEIVE MESSAGE-->byteLength->',bufferData.byteLength); | ||
| 144 | if (bufferData.byteLength > 0) { | 168 | if (bufferData.byteLength > 0) { |
| 145 | this._emit(EverSocket.MESSAGE, bufferData); | 169 | this._emit(EverSocket.MESSAGE, bufferData); |
| 146 | } | 170 | } |
| @@ -179,7 +203,7 @@ class EverSocket extends Emiter { | @@ -179,7 +203,7 @@ class EverSocket extends Emiter { | ||
| 179 | //目前客户端发送心跳请求的空数据,服务端不会每次都回,暂定为10秒心跳一次 | 203 | //目前客户端发送心跳请求的空数据,服务端不会每次都回,暂定为10秒心跳一次 |
| 180 | EverSocket.prototype.PONG_INTERVAL = EverSocket.PONG_INTERVAL = 21000;// | 204 | EverSocket.prototype.PONG_INTERVAL = EverSocket.PONG_INTERVAL = 21000;// |
| 181 | EverSocket.prototype.PING_INTERVAL = EverSocket.PING_INTERVAL = 10000;//心跳间隔 | 205 | EverSocket.prototype.PING_INTERVAL = EverSocket.PING_INTERVAL = 10000;//心跳间隔 |
| 182 | -EverSocket.prototype.RECONN_INTERVAL = EverSocket.RECONN_INTERVAL = 3000;//重连的间隔 | 206 | +EverSocket.prototype.RECONN_INTERVAL = EverSocket.RECONN_INTERVAL = 5000;//重连的间隔 |
| 183 | 207 | ||
| 184 | 208 | ||
| 185 | EverSocket.prototype.ERR_SOCKET_RECONNECT_FAILED =EverSocket.ERR_SOCKET_RECONNECT_FAILED=20001;//MCU自动重连失败,已经达到最大重连次数 | 209 | EverSocket.prototype.ERR_SOCKET_RECONNECT_FAILED =EverSocket.ERR_SOCKET_RECONNECT_FAILED=20001;//MCU自动重连失败,已经达到最大重连次数 |
| @@ -313,6 +313,7 @@ GlobalConfig.recordReplaytickValues={}; // 滚动条关键点,用于快进快 | @@ -313,6 +313,7 @@ GlobalConfig.recordReplaytickValues={}; // 滚动条关键点,用于快进快 | ||
| 313 | GlobalConfig.isAutoStartClass=0;//是否自动开始上课 0-否 ;1 是 | 313 | GlobalConfig.isAutoStartClass=0;//是否自动开始上课 0-否 ;1 是 |
| 314 | 314 | ||
| 315 | GlobalConfig.updateClassInfoDelay=30;//(秒),每隔30秒同步一次课堂状态的并保存到Sass | 315 | GlobalConfig.updateClassInfoDelay=30;//(秒),每隔30秒同步一次课堂状态的并保存到Sass |
| 316 | +GlobalConfig.msDynamicChooseIpDelay=15;//(秒)MS动态选点的间隔 | ||
| 316 | //GlobalConfig.serverTimestamp=0;//当前的系统时间戳 用get set 获取 | 317 | //GlobalConfig.serverTimestamp=0;//当前的系统时间戳 用get set 获取 |
| 317 | 318 | ||
| 318 | 319 |
| @@ -50,8 +50,6 @@ MessageTypes.AUDIO_BROADCAST= "audio_broadcast";//'audio.broadcast'; | @@ -50,8 +50,6 @@ MessageTypes.AUDIO_BROADCAST= "audio_broadcast";//'audio.broadcast'; | ||
| 50 | MessageTypes.AUDIO_GET_PUBLISH_PATH= "audio_get_publish_path";//获取音频推流地址 | 50 | MessageTypes.AUDIO_GET_PUBLISH_PATH= "audio_get_publish_path";//获取音频推流地址 |
| 51 | MessageTypes.AUDIO_PUBLISH_RESULT= "audio_publish_result";//获取音频推流结果 | 51 | MessageTypes.AUDIO_PUBLISH_RESULT= "audio_publish_result";//获取音频推流结果 |
| 52 | 52 | ||
| 53 | -MessageTypes.CHANGE_MS_IP ="change_ms_ip";//切换ms 重新选点 | ||
| 54 | - | ||
| 55 | 53 | ||
| 56 | //文档模块事件定义 | 54 | //文档模块事件定义 |
| 57 | MessageTypes.DOC_DELETE="document_delete";//'document.delete';//删除文档 | 55 | MessageTypes.DOC_DELETE="document_delete";//'document.delete';//删除文档 |
| @@ -72,8 +70,10 @@ MessageTypes.WHITEBOARD_ANNOTATION_UPDATE ="whiteboard_annotation_update";// 'wh | @@ -72,8 +70,10 @@ MessageTypes.WHITEBOARD_ANNOTATION_UPDATE ="whiteboard_annotation_update";// 'wh | ||
| 72 | //MessageTypes.WHITEBOARD_ANNOTATION_CLEAR = 'whiteboard.annotation.clear'; | 70 | //MessageTypes.WHITEBOARD_ANNOTATION_CLEAR = 'whiteboard.annotation.clear'; |
| 73 | 71 | ||
| 74 | 72 | ||
| 75 | -//MCU | ||
| 76 | -MessageTypes.CHANGE_MCU_IP ="change_mcu_ip";//切换mcu 重新选点 | 73 | +//MCU MS |
| 74 | +MessageTypes.SWITCH_MCU_IP ="switch_mcu_ip";//切换mcu 重新选点 | ||
| 75 | +MessageTypes.SWITCH_MS_IP ="switch_ms_ip";//切换ms 重新选点 | ||
| 76 | + | ||
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | //录制回放 | 79 | //录制回放 |
| @@ -23,19 +23,6 @@ class ConferApe extends Ape { | @@ -23,19 +23,6 @@ class ConferApe extends Ape { | ||
| 23 | ApeConsts.CONFERENCE_SESSION_NAME, | 23 | ApeConsts.CONFERENCE_SESSION_NAME, |
| 24 | ApeConsts.CONFERENCE_SESSION_TAG | 24 | ApeConsts.CONFERENCE_SESSION_TAG |
| 25 | ); | 25 | ); |
| 26 | - /* | ||
| 27 | - // Attribures | ||
| 28 | - this.hostNodeId = -1;//主持人的nodeId | ||
| 29 | - // 用户的身份,5种类型: | ||
| 30 | - // host(主持人/老师) | ||
| 31 | - // presenter(主讲人) | ||
| 32 | - // assistant(助教) | ||
| 33 | - // normal(普通角色/学生) | ||
| 34 | - // record(暂时没用. | ||
| 35 | - // 默认值: normal | ||
| 36 | - this.hostUserId = '';//主持人的 第三方userId | ||
| 37 | - */ | ||
| 38 | - | ||
| 39 | this.rosters = {};//用户列表 | 26 | this.rosters = {};//用户列表 |
| 40 | this.timerCounter = new TimerCounter();//计时器 | 27 | this.timerCounter = new TimerCounter();//计时器 |
| 41 | 28 | ||
| @@ -402,14 +389,21 @@ class ConferApe extends Ape { | @@ -402,14 +389,21 @@ class ConferApe extends Ape { | ||
| 402 | 389 | ||
| 403 | //开启计时器 | 390 | //开启计时器 |
| 404 | startTimerCounter() { | 391 | startTimerCounter() { |
| 392 | + this.stopTimerCounter(); | ||
| 393 | + if(this.timerCounter){ | ||
| 405 | this.timerCounter.startTimer(); | 394 | this.timerCounter.startTimer(); |
| 406 | } | 395 | } |
| 407 | 396 | ||
| 397 | + } | ||
| 398 | + | ||
| 408 | //停止计时器 | 399 | //停止计时器 |
| 409 | stopTimerCounter() { | 400 | stopTimerCounter() { |
| 401 | + if(this.timerCounter){ | ||
| 410 | this.timerCounter.stopTimer(); | 402 | this.timerCounter.stopTimer(); |
| 411 | } | 403 | } |
| 412 | 404 | ||
| 405 | + } | ||
| 406 | + | ||
| 413 | timerCounterUptate() { | 407 | timerCounterUptate() { |
| 414 | if (!this.mcu.connected) { | 408 | if (!this.mcu.connected) { |
| 415 | loger.warn('MCU 连接已经断开'); | 409 | loger.warn('MCU 连接已经断开'); |
| @@ -429,6 +423,7 @@ class ConferApe extends Ape { | @@ -429,6 +423,7 @@ class ConferApe extends Ape { | ||
| 429 | //loger.log('课堂进行时间',GlobalConfig.classTimestamp); | 423 | //loger.log('课堂进行时间',GlobalConfig.classTimestamp); |
| 430 | this._emit(MessageTypes.CLASS_UPDATE_TIMER, {"classTimestamp": GlobalConfig.classTimestamp}); | 424 | this._emit(MessageTypes.CLASS_UPDATE_TIMER, {"classTimestamp": GlobalConfig.classTimestamp}); |
| 431 | 425 | ||
| 426 | + | ||
| 432 | if (GlobalConfig.classTimestamp % GlobalConfig.updateClassInfoDelay == 0) { | 427 | if (GlobalConfig.classTimestamp % GlobalConfig.updateClassInfoDelay == 0) { |
| 433 | //如果是host身份,需要同步时间给其他人,同时把当前的状态上传到服务器 | 428 | //如果是host身份,需要同步时间给其他人,同时把当前的状态上传到服务器 |
| 434 | if (GlobalConfig.isHost) { | 429 | if (GlobalConfig.isHost) { |
| @@ -439,6 +434,11 @@ class ConferApe extends Ape { | @@ -439,6 +434,11 @@ class ConferApe extends Ape { | ||
| 439 | this.sendUpdaterClassStatusInfo({"actionType": 1}); | 434 | this.sendUpdaterClassStatusInfo({"actionType": 1}); |
| 440 | } | 435 | } |
| 441 | } | 436 | } |
| 437 | + | ||
| 438 | + //进行MS动态选点,选择最快的MS服务器地址(录制回放不做处理) | ||
| 439 | + if (!GlobalConfig.isRecordPlayBack&&GlobalConfig.classTimestamp % GlobalConfig.msDynamicChooseIpDelay == 0) { | ||
| 440 | + this._emit(MessageTypes.SWITCH_MS_IP); | ||
| 441 | + } | ||
| 442 | } | 442 | } |
| 443 | 443 | ||
| 444 | tableUpdateHandler(owner, itemIdx, itemData) { | 444 | tableUpdateHandler(owner, itemIdx, itemData) { |
| @@ -24,7 +24,7 @@ class MCU extends Emiter { | @@ -24,7 +24,7 @@ class MCU extends Emiter { | ||
| 24 | this._everSocket.on(everSocket.OPEN, this._everSocketOpenHandler.bind(this)); | 24 | this._everSocket.on(everSocket.OPEN, this._everSocketOpenHandler.bind(this)); |
| 25 | this._everSocket.on(everSocket.MESSAGE, this._everSocketMsgReceivedHandler.bind(this)); | 25 | this._everSocket.on(everSocket.MESSAGE, this._everSocketMsgReceivedHandler.bind(this)); |
| 26 | this._everSocket.on(everSocket.CLOSED, this._everSocketCloseHandler.bind(this)); | 26 | this._everSocket.on(everSocket.CLOSED, this._everSocketCloseHandler.bind(this)); |
| 27 | - this._everSocket.on(everSocket.ERROR,this._everSocketErrorHandler.bind(this)); | 27 | + this._everSocket.on(everSocket.ERROR, this._everSocketErrorHandler.bind(this)); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | // 注册Ape | 30 | // 注册Ape |
| @@ -42,12 +42,13 @@ class MCU extends Emiter { | @@ -42,12 +42,13 @@ class MCU extends Emiter { | ||
| 42 | GlobalConfig.setCurrentStatus(GlobalConfig.statusCode_3); | 42 | GlobalConfig.setCurrentStatus(GlobalConfig.statusCode_3); |
| 43 | this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_SOCKET_DISCONNECT); | 43 | this._emit(MessageTypes.MCU_ERROR, MessageTypes.ERR_SOCKET_DISCONNECT); |
| 44 | } | 44 | } |
| 45 | + | ||
| 45 | //EverSocket错误异常 | 46 | //EverSocket错误异常 |
| 46 | - _everSocketErrorHandler(_errorCode){ | ||
| 47 | - this._emit(MessageTypes.MCU_ERROR,_errorCode); | 47 | + _everSocketErrorHandler(_errorCode) { |
| 48 | + this._emit(MessageTypes.MCU_ERROR, _errorCode); | ||
| 48 | //如果自动重连次数已经达到最大值,重新选点 | 49 | //如果自动重连次数已经达到最大值,重新选点 |
| 49 | - if(_errorCode==everSocket.ERR_SOCKET_RECONNECT_FAILED){ | ||
| 50 | - this._emit(MessageTypes.CHANGE_MCU_IP); | 50 | + if (_errorCode == everSocket.ERR_SOCKET_RECONNECT_FAILED) { |
| 51 | + this._emit(MessageTypes.SWITCH_MCU_IP); | ||
| 51 | } | 52 | } |
| 52 | } | 53 | } |
| 53 | 54 | ||
| @@ -127,7 +128,7 @@ class MCU extends Emiter { | @@ -127,7 +128,7 @@ class MCU extends Emiter { | ||
| 127 | let subTypeLabel = pdu.id2type(pduMsg.subType); | 128 | let subTypeLabel = pdu.id2type(pduMsg.subType); |
| 128 | //loger.log('MCU-SecondLayer封装消息', 'sessionId', sessionLabel, pduMsg.sessionId, 'subtype', subTypeLabel, pduMsg.subType); | 129 | //loger.log('MCU-SecondLayer封装消息', 'sessionId', sessionLabel, pduMsg.sessionId, 'subtype', subTypeLabel, pduMsg.subType); |
| 129 | 130 | ||
| 130 | - loger.warn('MCU->收到消息处理->subType->',pduMsg.subType, GlobalConfig.mcuDelay, GlobalConfig.messageDelay); | 131 | + loger.warn('MCU->收到消息处理->subType->', pduMsg.subType, GlobalConfig.mcuDelay, GlobalConfig.messageDelay); |
| 131 | //延迟处理消息(3个条件--->ape允许延迟&&客户端设置需要延迟&&Sass设置的延迟时间大于0) | 132 | //延迟处理消息(3个条件--->ape允许延迟&&客户端设置需要延迟&&Sass设置的延迟时间大于0) |
| 132 | if (ape._apeDelayed && GlobalConfig.messageDelay && GlobalConfig.mcuDelay > 0) { | 133 | if (ape._apeDelayed && GlobalConfig.messageDelay && GlobalConfig.mcuDelay > 0) { |
| 133 | loger.warn('延迟处理消息->', GlobalConfig.mcuDelay); | 134 | loger.warn('延迟处理消息->', GlobalConfig.mcuDelay); |
| @@ -218,6 +219,17 @@ class MCU extends Emiter { | @@ -218,6 +219,17 @@ class MCU extends Emiter { | ||
| 218 | //开启EverSocket | 219 | //开启EverSocket |
| 219 | this._everSocket.begin(this.classInfo.MCUServerIP, this.classInfo.MCUServerPort); | 220 | this._everSocket.begin(this.classInfo.MCUServerIP, this.classInfo.MCUServerPort); |
| 220 | } | 221 | } |
| 222 | + | ||
| 223 | + //切换MCU的ip | ||
| 224 | + switchMCUIp(_classInfo) { | ||
| 225 | + if (_classInfo && _classInfo.MCUServerIP) { | ||
| 226 | + this.classInfo.MCUServerIP = _classInfo.MCUServerIP; | ||
| 227 | + this.classInfo.MCUServerPort = _classInfo.MCUServerIP; | ||
| 228 | + if (this._everSocket) { | ||
| 229 | + this._everSocket.switchSocketIp(this.classInfo.MCUServerIP, this.classInfo.MCUServerPort); | ||
| 230 | + } | ||
| 231 | + } | ||
| 232 | + } | ||
| 221 | } | 233 | } |
| 222 | 234 | ||
| 223 | export default new MCU; | 235 | export default new MCU; |
-
请 注册 或 登录 后发表评论