李勇

修复连接时设置ws的onmessage出现空对象的情况

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>UMD PLAYGROUND</title></head><body><div id="stage"></div><script type="text/javascript" src="test.js?8c5b5e6f30a1691a0b96"></script><script type="text/javascript" src="screenShare.js?8c5b5e6f30a1691a0b96"></script></body></html>
\ No newline at end of file
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>UMD PLAYGROUND</title></head><body><div id="stage"></div><script type="text/javascript" src="test.js?28427e809b69cbbbd3de"></script><script type="text/javascript" src="screenShare.js?28427e809b69cbbbd3de"></script></body></html>
\ No newline at end of file
... ...
!function(e,_){"object"==typeof exports&&"object"==typeof module?module.exports=_():"function"==typeof define&&define.amd?define([],_):"object"==typeof exports?exports.share=_():e.share=_()}(this,function(){return function(e){function _(t){if(r[t])return r[t].exports;var n=r[t]={exports:{},id:t,loaded:!1};return e[t].call(n.exports,n,n.exports,_),n.loaded=!0,n.exports}var r={};return _.m=e,_.c=r,_.p="",_(0)}([function(e,_,r){e.exports=r(2)},function(e,_){"use strict";function r(e,_){if(!(e instanceof _))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(_,"__esModule",{value:!0});var t=function(){function e(e,_){for(var r=0;r<_.length;r++){var t=_[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(_,r,t){return r&&e(_.prototype,r),t&&e(_,t),_}}(),n=function(){function e(){r(this,e),this.MAPS={}}return t(e,[{key:"on",value:function(e,_){if(e&&_){var r=this.MAPS[e];if(!r)return this.MAPS[e]=[_];r.push(_)}}},{key:"off",value:function(e,_){if(e){var r=this.MAPS[e];if(r){if(_)return r.splice(r.indexOf(_),1);r.length=0}}}},{key:"emit",value:function(e,_){if(e){var r=this.MAPS["*"];r&&r.length&&r.forEach(function(r){r(e,_)});var t=this.MAPS[e];t&&t.length&&t.forEach(function(e){e(_)})}}}]),e}(),a=n;_.default=a;(function(){"undefined"!=typeof __REACT_HOT_LOADER__&&(__REACT_HOT_LOADER__.register(n,"Emiter","D:/work/screenshare/src/Emiter.js"),__REACT_HOT_LOADER__.register(a,"default","D:/work/screenshare/src/Emiter.js"))})()},function(e,_,r){"use strict";function t(e){return e&&e.__esModule?e:{default:e}}function n(e){var _,r,t,n;t=e.length,_=new Uint8Array(3*t);var a=0;for(r=0;r<t;r++)n=e.charCodeAt(r),n>=1&&n<=127?_[a++]=n:n>2047?(_[a++]=224|n>>12&15,_[a++]=128|n>>6&63,_[a++]=128|n>>0&63):(_[a++]=192|n>>6&31,_[a++]=128|n>>0&63);return new Uint8Array(_.buffer,0,a)}function a(e){var _,r,t,n,a,s;for(_="",t=e.length,r=0;r<t;)switch(n=e[r++],n>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:_+=String.fromCharCode(n);break;case 12:case 13:a=e[r++],_+=String.fromCharCode((31&n)<<6|63&a);break;case 14:a=e[r++],s=e[r++],_+=String.fromCharCode((15&n)<<12|(63&a)<<6|(63&s)<<0)}return _}function s(e){var _=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=new Object;if(r.data_len=0,r.data="",r.name=e,"mov_start"==e)r.type=1;else if("mov_stop"==e)r.type=2;else if("mov_pause"==e){if(r.type=3,pos=_,pos.length>0){r.data_len=4;var t=new ArrayBuffer(r.data_len),a=new Uint32Array(t,0,1);a[0]=parseInt(pos),r.data=new Uint8Array(t,0,4)}}else if("mov_resume"==e)r.type=4;else if("mov_seek"==e){if(r.type=5,pos=_,pos.length>0){r.data_len=4;var t=new ArrayBuffer(r.data_len),a=new Uint32Array(t,0,1);a[0]=parseInt(pos),r.data=new Uint8Array(t,0,4)}}else if("ss_start"==e)r.type=6,r.data=n(_),r.data_len=r.data.length;else if("ss_stop"==e)r.type=7;else if("ss_version"==e)r.type=14;else if("get_mic"==e)r.type=26;else{if("ds_start"==e){r.type=27,r.data_len=536;var t=new ArrayBuffer(r.data_len),s=new Uint32Array(t,0,6);coordstr=_;var i=coordstr.split(",");if(4!=i.length)return;s[0]=parseInt(i[0]),s[1]=parseInt(i[1]),s[2]=parseInt(i[2]),s[3]=parseInt(i[3]);var A=new Uint8Array(t,24,256);window_name=_;for(var E=n(window_name),c=0;c<E.length;c++)A[c]=E[c];s[4]=E.length,s[5]=0;new Uint8Array(t,280,256);return r.data=new Uint8Array(t,0,r.data_len),void o(r)}if("ds_stop"==e)r.type=28;else{if("aud_start"==e){r.type=29,r.data_len=520;var t=new ArrayBuffer(r.data_len),O=new Uint32Array(t,0,1),C=_;O[0]=C.length;var S=new Uint32Array(t,4,1);S[0]=0;for(var T=new Uint8Array(t,8,256),l=n(C),c=0;c<l.length;c++)T[c]=l[c];new Uint8Array(t,264,256);return r.data=new Uint8Array(t,0,r.data_len),void o(r)}if("aud_stop"==e)r.type=30;else if("get_cam"==e)r.type=41;else{if("cam_start"==e){r.type=42,r.data_len=520;var t=new ArrayBuffer(r.data_len),f=new Uint32Array(t,0,1),R=_;f[0]=R.length;var S=new Uint32Array(t,4,1);S[0]=0;for(var I=new Uint8Array(t,8,256),U=n(R),c=0;c<U.length;c++)I[c]=U[c];new Uint8Array(t,264,256);return r.data=new Uint8Array(t,0,r.data_len),void o(r)}"cam_stop"==e?r.type=43:"set_videoparam"==e?(r.type=46,r.data=n(_),r.data_len=r.data.length):"get_videoparam"==e?(r.type=47,r.data=n(_),r.data_len=r.data.length):"start_record"==e?(r.type=48,r.data=n(_),r.data_len=r.data.length):"stop_record"==e?(r.type=49,r.data=n(_),r.data_len=r.data.length):"start_push"==e?(r.type=50,r.data=n(_),r.data_len=r.data.length):"stop_push"==e?(r.type=51,r.data=n(_),r.data_len=r.data.length):"get_rtmp_port"==e?r.type=52:"set_mic_vol"==e?(r.type=53,r.data=n(_),r.data_len=r.data.length):"get_mic_vol"==e&&(r.type=54)}}}o(r)}function o(e){var _=8+e.data_len,r=new ArrayBuffer(_),t=new Uint16Array(r,0,1),n=new Uint8Array(r,2,1),a=new Uint32Array(r,4,1);if(t[0]=e.type,n[0]=0,a[0]=e.data_len,e.data_len>0)for(var s=new Uint8Array(r,8,e.data_len),o=0;o<e.data_len;o++)s[o]=e.data[o];L&&L.send(r)}function i(){try{L&&(L.close(),L=L.onopen=L.onclose=L.onerror=L.onmessage=null,C.emit(C.CLOSE))}catch(e){console.log(e)}}function A(){i()}function E(){L&&i(),L=new WebSocket(m),p=setTimeout(function(){clearTimeout(p),i()},1500),L.timeout=1500,L.binaryType="arraybuffer",L.onopen=function(){clearTimeout(p),s("get_rtmp_port"),s("get_mic"),s("get_cam"),s("get_mic_vol"),C.emit(C.OPEN)},L.onclose=function(){i()},L.onerror=function(){i()},L.onmessage=function(e){var _=e.data;if("string"==typeof e.data)console.log("on message [string] ignore.");else{var r=new DataView(_),t=r.getUint16(0,!0);console.log("onmessage code->",t);var n=(r.getUint8(2,!0),r.getUint32(4,!0));if(t>=0&&t<S.length){S[t]}if(0==t||6==t||8==t)console.log("mov_start,mov_pause,mov_seek success");else if(10==t){if(n>36){var s=new Uint32Array(_,8,8),o="width:"+s[0]+" height:"+s[1];o="framerate:"+s[2]+" duration:"+s[3],o="playpos:"+s[4]+" filesize:"+s[5],T=o;var i=s[6],A=new Uint8Array(_,40,i),E=a(A);T.filename=E,C.emit(C.MOVIE_INFO_CHANGE,T)}}else if(11==t)console.log("ss_start success"),C.emit(C.SS_START);else if(24<=t&&26>=t){if(n>=4){var c=r.getUint32(8,!0);l=c.toString(),C.emit(C.VERSION_INFO_CHANGE,l)}}else if(55==t)console.log("ds_start success");else if(59==t)console.log("as start success");else if(83==t){if(console.log("get camera sucess"),n>4){var O=r.getUint32(8,!0),L=12;f.length=0;for(var d=0;d<O;d++){var g=r.getUint32(L,!0);L+=4;var m=new Uint8Array(_,L,g-1);L+=g;var p=a(m);f.push(p)}C.emit(C.CAMERA_INFO_CHANGE,f)}}else if(53==t){if(n>4){var y=r.getUint32(8,!0),L=12;R.length=0;for(var d=0;d<y;d++){var D=r.getUint32(L,!0);L+=4;var h=new Uint8Array(_,L,D-1);L+=D;var p=a(h);R.push(p)}C.emit(C.MIC_INFO_CHANGE,R)}}else if(85==t)console.log("cam_share success");else if(95==t){console.log("get_videoparam success");var v=new Uint8Array(_,8,_.byteLength-8-1),p=a(v);I=p,C.emit(C.VIDEO_INFO_CHANGE,I)}else if(105==t){console.log("get_rtmp_port_success");var v=new Uint8Array(_,8,_.byteLength-8-1),p=a(v);U=p,C.emit(C.RTMP_PORT_CHANGE,U)}else if(109==t){console.log("get_mic_vol success");var v=new Uint8Array(_,8,_.byteLength-8-1),p=a(v);u=p,C.emit(C.MIC_VOL_CHANGE,u)}else if(111<=t&&114>=t){var v=new Uint8Array(_,8,_.byteLength-8),P=a(v);console.log("url->",P)}else if(13==t)C.emit(C.SS_STOP);else{var v=new Uint8Array(_,8,_.byteLength-8),p=a(v);console.log("data ->",p)}}}}Object.defineProperty(_,"__esModule",{value:!0});var c=r(1),O=t(c),C=new O.default,S=["MOV_START_SUC","MOV_START_FAIL","MOV_STOP_SUC","MOV_STOP_FAIL","MOV_PAUSE_SUC","MOV_PAUSE_FAIL","MOV_RESUME_SUC","MOV_RESUME_FAIL","MOV_SEEK_SUC","MOV_SEEK_FAIL","MOV_PROPERTY","SS_START_SUC","SS_START_FAIL","SS_STOP_SUC","SS_STOP_FAIL","REC_START_SUC","REC_START_FAIL","REC_STOP_SUC","REC_STOP_FAIL","REC_PAUSE_SUC","REC_PAUSE_FAIL","REC_RESUME_SUC","REC_RESUME_FAIL","MOV_PLAY_FINISH","MOV_VERSION","SS_VERSION","REC_VERSION","MOV_SELECT_FILE_CANCEL","QAV_LOGIN_SUC","QAV_LOGIN_FAIL","QAV_LOGOUT_SUC","QAV_LOGOUT_FAIL","QAV_ENTERROOM_SUC","QAV_ENTERROOM_FAIL","QAV_LEAVEROOM_SUC","QAV_LEAVEROOM_FAIL","QAV_OPEN_MIC_SUC","QAV_OPEN_MIC_FAIL","QAV_OPEN_MIC_NODEV","QAV_CLOSE_MIC_SUC","QAV_CLOSE_MIC_FAIL","QAV_CLOSE_MIC_NODEV","QAV_OPEN_PLAYER_SUC","QAV_OPEN_PLAYER_FAIL","QAV_OPEN_PLAYER_NODEV","QAV_CLOSE_PLAYER_SUC","QAV_CLOSE_PLAYER_FAIL","QAV_CLOSE_PLAYER_NODEV","QAV_MUTE_AUDIO_SUC","QAV_MUTE_AUDIO_FAIL","QAV_UNMUTE_AUDIO_SUC","QAV_UNMUTE_AUDIO_FAIL","REC_SAVE_FILE_CANCEL","GET_MIC_SUC","GET_MIC_FAIL","DS_START_SUC","DS_START_FAIL","DS_STOP_SUC","DS_STOP_FAIL","AUD_START_SUC","AUD_START_FAIL","AUD_STOP_SUC","AUD_STOP_FAIL","AUD_DATA","SS_DATA","MOV_DATA","PEN_START_SUC","PEN_START_FAIL","PEN_STOP_SUC","PEN_STOP_FAIL","PEN_VERSION","QAV_DEVICE_SUC","QAV_DEVICE_FAIL","CBD_QUERY_SUC","CBD_QUERY_FAIL","CBD_GET_SUC","CBD_GET_FAIL","FILE_GET_SUC","FILE_GET_FAIL","FILE_SET_SUC","FILE_SET_FAIL","RESTART_SUC","RESTART_FAIL","GET_CAM_SUC","GET_CAM_FAIL","CAM_START_SUC","CAM_START_FAIL","CAM_STOP_SUC","CAM_STOP_FAIL","SWITCH_SCENE_SUC","SWITCH_SCENE_FAIL","PUSH_STREAM_FAIL","SHOW_UI_SUC","SET_VIDEO_PARAM_SUC","SET_VIDEO_PARAM_FAIL","GET_VIDEO_PARAM_SUC","GET_VIDEO_PARAM_FAIL","START_RECORD_SUC","START_RECORD_FAIL","STOP_RECORD_SUC","STOP_RECORD_FAIL","START_PUSH_SUC","START_PUSH_FAIL","STOP_PUSH_SUC","STOP_PUSH_FAIL","GET_RTMP_PORT_SUC","GET_RTMP_PORT_FAIL","SET_MIC_VOL_SUC","SET_MIC_VOL_FAIL","GET_MIC_VOL_SUC","GET_MIC_VOL_FAIL","RTMP_CONNECTING","RTMP_CONNECT_SUC","RTMP_CONNECT_FAIL","RTMP_CONNECT_CLOSED"],T=null,l="",f=[],R=[],I="",U="",u="",L=null,d="127.0.0.1",g=8090,m="ws://127.0.0.1:8090",p=0;C.infos={movieInfo:T,versionInfo:l,cameraInfo:f,micInfo:R,videoInfo:I,rtmpPort:U,micVol:u},C.MOVIE_INFO_CHANGE="MOVIE_INFO_CHANGE",C.VERSION_INFO_CHANGE="VERSION_INFO_CHANGE",C.CAMERA_INFO_CHANGE="CAMERA_INFO_CHANGE",C.MIC_INFO_CHANGE="MIC_INFO_CHANGE",C.VIDEO_INFO_CHANGE="VIDEO_INFO_CHANGE",C.RTMP_PORT_CHANGE="RTMP_PORT_CHANGE",C.MIC_VOL_CHANGE="MIC_VOL_CHANGE",C.SS_START="SS_START",C.SS_STOP="SS_STOP",C.OPEN="OPEN",C.CLOSE="CLOSE",C.ERROR="ERROR",C.getRTMPPort=function(){s("get_rtmp_port")},C.getMicInfo=function(){s("get_mic")},C.getCamInfo=function(){s("get_cam")},C.getMicVol=function(){s("get_mic_vol")},C.start=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"127.0.0.1",_=arguments[1];d=e,g=_,E()},C.startConnect=function(e){m=e,E()},C.stop=function(){A()},C.startShareScreen=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";s("ss_start",e)},C.stopShareScreen=function(){s("ss_stop")};var y=C;_.default=y;(function(){"undefined"!=typeof __REACT_HOT_LOADER__&&(__REACT_HOT_LOADER__.register(C,"e","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(n,"utf16to8","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(a,"utf8to16","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(S,"CODE","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(s,"sendCommand","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(o,"_sendCommand","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(T,"movieInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(l,"versionInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(f,"cameraInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(R,"micInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(I,"videoInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(U,"rtmpPort","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(u,"micVol","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(L,"ws","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(d,"host","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(g,"port","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(m,"fullUrl","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(p,"wstimer","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(i,"clear","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(A,"stop","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(E,"start","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(y,"default","D:/work/screenshare/src/main.js"))})()}])});
\ No newline at end of file
!function(e,_){"object"==typeof exports&&"object"==typeof module?module.exports=_():"function"==typeof define&&define.amd?define([],_):"object"==typeof exports?exports.share=_():e.share=_()}(this,function(){return function(e){function _(t){if(r[t])return r[t].exports;var n=r[t]={exports:{},id:t,loaded:!1};return e[t].call(n.exports,n,n.exports,_),n.loaded=!0,n.exports}var r={};return _.m=e,_.c=r,_.p="",_(0)}([function(e,_,r){e.exports=r(2)},function(e,_){"use strict";function r(e,_){if(!(e instanceof _))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(_,"__esModule",{value:!0});var t=function(){function e(e,_){for(var r=0;r<_.length;r++){var t=_[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(_,r,t){return r&&e(_.prototype,r),t&&e(_,t),_}}(),n=function(){function e(){r(this,e),this.MAPS={}}return t(e,[{key:"on",value:function(e,_){if(e&&_){var r=this.MAPS[e];if(!r)return this.MAPS[e]=[_];r.push(_)}}},{key:"off",value:function(e,_){if(e){var r=this.MAPS[e];if(r){if(_)return r.splice(r.indexOf(_),1);r.length=0}}}},{key:"emit",value:function(e,_){if(e){var r=this.MAPS["*"];r&&r.length&&r.forEach(function(r){r(e,_)});var t=this.MAPS[e];t&&t.length&&t.forEach(function(e){e(_)})}}}]),e}(),a=n;_.default=a;(function(){"undefined"!=typeof __REACT_HOT_LOADER__&&(__REACT_HOT_LOADER__.register(n,"Emiter","D:/work/screenshare/src/Emiter.js"),__REACT_HOT_LOADER__.register(a,"default","D:/work/screenshare/src/Emiter.js"))})()},function(e,_,r){"use strict";function t(e){return e&&e.__esModule?e:{default:e}}function n(e){var _,r,t,n;t=e.length,_=new Uint8Array(3*t);var a=0;for(r=0;r<t;r++)n=e.charCodeAt(r),n>=1&&n<=127?_[a++]=n:n>2047?(_[a++]=224|n>>12&15,_[a++]=128|n>>6&63,_[a++]=128|n>>0&63):(_[a++]=192|n>>6&31,_[a++]=128|n>>0&63);return new Uint8Array(_.buffer,0,a)}function a(e){var _,r,t,n,a,s;for(_="",t=e.length,r=0;r<t;)switch(n=e[r++],n>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:_+=String.fromCharCode(n);break;case 12:case 13:a=e[r++],_+=String.fromCharCode((31&n)<<6|63&a);break;case 14:a=e[r++],s=e[r++],_+=String.fromCharCode((15&n)<<12|(63&a)<<6|(63&s)<<0)}return _}function s(e){var _=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=new Object;if(r.data_len=0,r.data="",r.name=e,"mov_start"==e)r.type=1;else if("mov_stop"==e)r.type=2;else if("mov_pause"==e){if(r.type=3,pos=_,pos.length>0){r.data_len=4;var t=new ArrayBuffer(r.data_len),a=new Uint32Array(t,0,1);a[0]=parseInt(pos),r.data=new Uint8Array(t,0,4)}}else if("mov_resume"==e)r.type=4;else if("mov_seek"==e){if(r.type=5,pos=_,pos.length>0){r.data_len=4;var t=new ArrayBuffer(r.data_len),a=new Uint32Array(t,0,1);a[0]=parseInt(pos),r.data=new Uint8Array(t,0,4)}}else if("ss_start"==e)r.type=6,r.data=n(_),r.data_len=r.data.length;else if("ss_stop"==e)r.type=7;else if("ss_version"==e)r.type=14;else if("get_mic"==e)r.type=26;else{if("ds_start"==e){r.type=27,r.data_len=536;var t=new ArrayBuffer(r.data_len),s=new Uint32Array(t,0,6);coordstr=_;var i=coordstr.split(",");if(4!=i.length)return;s[0]=parseInt(i[0]),s[1]=parseInt(i[1]),s[2]=parseInt(i[2]),s[3]=parseInt(i[3]);var A=new Uint8Array(t,24,256);window_name=_;for(var E=n(window_name),c=0;c<E.length;c++)A[c]=E[c];s[4]=E.length,s[5]=0;new Uint8Array(t,280,256);return r.data=new Uint8Array(t,0,r.data_len),void o(r)}if("ds_stop"==e)r.type=28;else{if("aud_start"==e){r.type=29,r.data_len=520;var t=new ArrayBuffer(r.data_len),O=new Uint32Array(t,0,1),C=_;O[0]=C.length;var S=new Uint32Array(t,4,1);S[0]=0;for(var T=new Uint8Array(t,8,256),l=n(C),c=0;c<l.length;c++)T[c]=l[c];new Uint8Array(t,264,256);return r.data=new Uint8Array(t,0,r.data_len),void o(r)}if("aud_stop"==e)r.type=30;else if("get_cam"==e)r.type=41;else{if("cam_start"==e){r.type=42,r.data_len=520;var t=new ArrayBuffer(r.data_len),f=new Uint32Array(t,0,1),R=_;f[0]=R.length;var S=new Uint32Array(t,4,1);S[0]=0;for(var I=new Uint8Array(t,8,256),u=n(R),c=0;c<u.length;c++)I[c]=u[c];new Uint8Array(t,264,256);return r.data=new Uint8Array(t,0,r.data_len),void o(r)}"cam_stop"==e?r.type=43:"set_videoparam"==e?(r.type=46,r.data=n(_),r.data_len=r.data.length):"get_videoparam"==e?(r.type=47,r.data=n(_),r.data_len=r.data.length):"start_record"==e?(r.type=48,r.data=n(_),r.data_len=r.data.length):"stop_record"==e?(r.type=49,r.data=n(_),r.data_len=r.data.length):"start_push"==e?(r.type=50,r.data=n(_),r.data_len=r.data.length):"stop_push"==e?(r.type=51,r.data=n(_),r.data_len=r.data.length):"get_rtmp_port"==e?r.type=52:"set_mic_vol"==e?(r.type=53,r.data=n(_),r.data_len=r.data.length):"get_mic_vol"==e&&(r.type=54)}}}o(r)}function o(e){var _=8+e.data_len,r=new ArrayBuffer(_),t=new Uint16Array(r,0,1),n=new Uint8Array(r,2,1),a=new Uint32Array(r,4,1);if(t[0]=e.type,n[0]=0,a[0]=e.data_len,e.data_len>0)for(var s=new Uint8Array(r,8,e.data_len),o=0;o<e.data_len;o++)s[o]=e.data[o];d&&d.send(r)}function i(){try{d&&(d.close(),d=d.onopen=d.onclose=d.onerror=d.onmessage=null,C.emit(C.CLOSE))}catch(e){console.log(e)}}function A(){i()}function E(){d&&i(),d=new WebSocket(p),clearTimeout(D),D=setTimeout(function(){clearTimeout(D),i()},1500),d&&(d.timeout=1500,d.binaryType="arraybuffer",d.onopen=function(){clearTimeout(D),s("get_rtmp_port"),s("get_mic"),s("get_cam"),s("get_mic_vol"),C.emit(C.OPEN)},d.onclose=function(){i()},d.onerror=function(){i()},d.onmessage=function(e){var _=e.data;if("string"==typeof e.data)console.log("on message [string] ignore.");else{var r=new DataView(_),t=r.getUint16(0,!0);console.log("onmessage code->",t);var n=(r.getUint8(2,!0),r.getUint32(4,!0));if(t>=0&&t<T.length){T[t]}if(0==t||6==t||8==t)console.log("mov_start,mov_pause,mov_seek success");else if(10==t){if(n>36){var s=new Uint32Array(_,8,8),o="width:"+s[0]+" height:"+s[1];o="framerate:"+s[2]+" duration:"+s[3],o="playpos:"+s[4]+" filesize:"+s[5],l=o;var i=s[6],A=new Uint8Array(_,40,i),E=a(A);l.filename=E,C.emit(C.MOVIE_INFO_CHANGE,l)}}else if(11==t)console.log("ss_start success"),C.emit(C.SS_START);else if(24<=t&&26>=t){if(n>=4){var c=r.getUint32(8,!0);f=c.toString(),C.emit(C.VERSION_INFO_CHANGE,f)}}else if(55==t)console.log("ds_start success");else if(59==t)console.log("as start success");else if(83==t){if(console.log("get camera sucess"),n>4){var O=r.getUint32(8,!0),S=12;R.length=0;for(var d=0;d<O;d++){var g=r.getUint32(S,!0);S+=4;var m=new Uint8Array(_,S,g-1);S+=g;var p=a(m);R.push(p)}C.emit(C.CAMERA_INFO_CHANGE,R)}}else if(53==t){if(n>4){var D=r.getUint32(8,!0),S=12;I.length=0;for(var d=0;d<D;d++){var h=r.getUint32(S,!0);S+=4;var y=new Uint8Array(_,S,h-1);S+=h;var p=a(y);I.push(p)}C.emit(C.MIC_INFO_CHANGE,I)}}else if(85==t)console.log("cam_share success");else if(95==t){console.log("get_videoparam success");var v=new Uint8Array(_,8,_.byteLength-8-1),p=a(v);u=p,C.emit(C.VIDEO_INFO_CHANGE,u)}else if(105==t){console.log("get_rtmp_port_success");var v=new Uint8Array(_,8,_.byteLength-8-1),p=a(v);U=p,C.emit(C.RTMP_PORT_CHANGE,U)}else if(109==t){console.log("get_mic_vol success");var v=new Uint8Array(_,8,_.byteLength-8-1),p=a(v);L=p,C.emit(C.MIC_VOL_CHANGE,L)}else if(111<=t&&114>=t){var v=new Uint8Array(_,8,_.byteLength-8),P=a(v);console.log("url->",P)}else if(13==t)C.emit(C.SS_STOP);else{var v=new Uint8Array(_,8,_.byteLength-8),p=a(v);console.log("data ->",p)}}})}Object.defineProperty(_,"__esModule",{value:!0});var c=r(1),O=t(c),C=new O.default,S="v1.1.0.20170825",T=["MOV_START_SUC","MOV_START_FAIL","MOV_STOP_SUC","MOV_STOP_FAIL","MOV_PAUSE_SUC","MOV_PAUSE_FAIL","MOV_RESUME_SUC","MOV_RESUME_FAIL","MOV_SEEK_SUC","MOV_SEEK_FAIL","MOV_PROPERTY","SS_START_SUC","SS_START_FAIL","SS_STOP_SUC","SS_STOP_FAIL","REC_START_SUC","REC_START_FAIL","REC_STOP_SUC","REC_STOP_FAIL","REC_PAUSE_SUC","REC_PAUSE_FAIL","REC_RESUME_SUC","REC_RESUME_FAIL","MOV_PLAY_FINISH","MOV_VERSION","SS_VERSION","REC_VERSION","MOV_SELECT_FILE_CANCEL","QAV_LOGIN_SUC","QAV_LOGIN_FAIL","QAV_LOGOUT_SUC","QAV_LOGOUT_FAIL","QAV_ENTERROOM_SUC","QAV_ENTERROOM_FAIL","QAV_LEAVEROOM_SUC","QAV_LEAVEROOM_FAIL","QAV_OPEN_MIC_SUC","QAV_OPEN_MIC_FAIL","QAV_OPEN_MIC_NODEV","QAV_CLOSE_MIC_SUC","QAV_CLOSE_MIC_FAIL","QAV_CLOSE_MIC_NODEV","QAV_OPEN_PLAYER_SUC","QAV_OPEN_PLAYER_FAIL","QAV_OPEN_PLAYER_NODEV","QAV_CLOSE_PLAYER_SUC","QAV_CLOSE_PLAYER_FAIL","QAV_CLOSE_PLAYER_NODEV","QAV_MUTE_AUDIO_SUC","QAV_MUTE_AUDIO_FAIL","QAV_UNMUTE_AUDIO_SUC","QAV_UNMUTE_AUDIO_FAIL","REC_SAVE_FILE_CANCEL","GET_MIC_SUC","GET_MIC_FAIL","DS_START_SUC","DS_START_FAIL","DS_STOP_SUC","DS_STOP_FAIL","AUD_START_SUC","AUD_START_FAIL","AUD_STOP_SUC","AUD_STOP_FAIL","AUD_DATA","SS_DATA","MOV_DATA","PEN_START_SUC","PEN_START_FAIL","PEN_STOP_SUC","PEN_STOP_FAIL","PEN_VERSION","QAV_DEVICE_SUC","QAV_DEVICE_FAIL","CBD_QUERY_SUC","CBD_QUERY_FAIL","CBD_GET_SUC","CBD_GET_FAIL","FILE_GET_SUC","FILE_GET_FAIL","FILE_SET_SUC","FILE_SET_FAIL","RESTART_SUC","RESTART_FAIL","GET_CAM_SUC","GET_CAM_FAIL","CAM_START_SUC","CAM_START_FAIL","CAM_STOP_SUC","CAM_STOP_FAIL","SWITCH_SCENE_SUC","SWITCH_SCENE_FAIL","PUSH_STREAM_FAIL","SHOW_UI_SUC","SET_VIDEO_PARAM_SUC","SET_VIDEO_PARAM_FAIL","GET_VIDEO_PARAM_SUC","GET_VIDEO_PARAM_FAIL","START_RECORD_SUC","START_RECORD_FAIL","STOP_RECORD_SUC","STOP_RECORD_FAIL","START_PUSH_SUC","START_PUSH_FAIL","STOP_PUSH_SUC","STOP_PUSH_FAIL","GET_RTMP_PORT_SUC","GET_RTMP_PORT_FAIL","SET_MIC_VOL_SUC","SET_MIC_VOL_FAIL","GET_MIC_VOL_SUC","GET_MIC_VOL_FAIL","RTMP_CONNECTING","RTMP_CONNECT_SUC","RTMP_CONNECT_FAIL","RTMP_CONNECT_CLOSED"],l=null,f="",R=[],I=[],u="",U="",L="",d=null,g="127.0.0.1",m=8090,p="ws://127.0.0.1:8090",D=0;C.infos={movieInfo:l,versionInfo:f,cameraInfo:R,micInfo:I,videoInfo:u,rtmpPort:U,micVol:L},C.MOVIE_INFO_CHANGE="MOVIE_INFO_CHANGE",C.VERSION_INFO_CHANGE="VERSION_INFO_CHANGE",C.CAMERA_INFO_CHANGE="CAMERA_INFO_CHANGE",C.MIC_INFO_CHANGE="MIC_INFO_CHANGE",C.VIDEO_INFO_CHANGE="VIDEO_INFO_CHANGE",C.RTMP_PORT_CHANGE="RTMP_PORT_CHANGE",C.MIC_VOL_CHANGE="MIC_VOL_CHANGE",C.SS_START="SS_START",C.SS_STOP="SS_STOP",C.OPEN="OPEN",C.CLOSE="CLOSE",C.ERROR="ERROR",C.getRTMPPort=function(){s("get_rtmp_port")},C.getMicInfo=function(){s("get_mic")},C.getCamInfo=function(){s("get_cam")},C.getMicVol=function(){s("get_mic_vol")},C.start=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"127.0.0.1",_=arguments[1];g=e,m=_,E()},C.startConnect=function(e){p=e,E()},C.stop=function(){A()},C.startShareScreen=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";s("ss_start",e)},C.stopShareScreen=function(){s("ss_stop")};var h=C;_.default=h;(function(){"undefined"!=typeof __REACT_HOT_LOADER__&&(__REACT_HOT_LOADER__.register(C,"e","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(S,"shareVersion","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(n,"utf16to8","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(a,"utf8to16","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(T,"CODE","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(s,"sendCommand","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(o,"_sendCommand","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(l,"movieInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(f,"versionInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(R,"cameraInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(I,"micInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(u,"videoInfo","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(U,"rtmpPort","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(L,"micVol","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(d,"ws","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(g,"host","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(m,"port","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(p,"fullUrl","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(D,"wstimer","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(i,"clear","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(A,"stop","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(E,"start","D:/work/screenshare/src/main.js"),__REACT_HOT_LOADER__.register(h,"default","D:/work/screenshare/src/main.js"))})()}])});
\ No newline at end of file
... ...
... ... @@ -15,7 +15,6 @@
import Emiter from 'Emiter';
import Loger from 'Loger';
let loger = Loger.getLoger('EverSocket');
class EverSocket extends Emiter {
constructor() {
super();
... ... @@ -60,6 +59,7 @@ class EverSocket extends Emiter {
_newConnection() {
this.websocket = new WebSocket(this.wsURL);
if( this.websocket){
this.websocket.binaryType = 'arraybuffer';
this.websocket.onopen = this._onOpen.bind(this);
this.websocket.onclose = this._onClose.bind(this);
... ... @@ -67,6 +67,8 @@ class EverSocket extends Emiter {
this.websocket.onmessage = this._onMessage.bind(this);
}
}
_reConnection() {
this._clear();
this.reConnectionTimeout = window.setTimeout(() => {
... ... @@ -80,10 +82,13 @@ class EverSocket extends Emiter {
loger.log('WebSocket,Timers销毁');
window.clearInterval(this.pingTimer);
window.clearInterval(this.pongTimer);
if(this.websocket){
this.websocket.onopen = undefined;
this.websocket.onclose = undefined;
this.websocket.onerror = undefined;
this.websocket.onmessage = undefined;
}
try {
this.websocket.close();
} catch (e) {
... ...
... ... @@ -15,7 +15,7 @@
import Emiter from './Emiter.js';
const e = new Emiter();
let shareVersion='v1.1.0.20170825';
function utf16to8(str) {
var out, i, len, c;
... ... @@ -414,10 +414,12 @@ function start() {
}
//ws = new WebSocket('ws://' + host + ':' + port);
ws = new WebSocket(fullUrl);//wss或ws地址 由外部传递
clearTimeout(wstimer);
wstimer = setTimeout(() => {
clearTimeout(wstimer);
clear();
}, 1500)
if(ws){
ws.timeout = 1500;
ws.binaryType = 'arraybuffer';
ws.onopen = () => {
... ... @@ -437,6 +439,7 @@ function start() {
clear();
}
ws.onmessage = (evt) => {
const msg = evt.data;
if (typeof (evt.data) === "string") {
... ... @@ -553,6 +556,9 @@ function start() {
}
}
}
}
}
e.infos = { movieInfo, versionInfo, cameraInfo, micInfo, videoInfo, rtmpPort, micVol }
... ...