UNPKG

meshcentral

Version:

Web based remote computer management server

1 lines 1.96 kB
var CreateKvmDataChannel=function(e,t,n){var a={};a.m=t,t.parent=a,a.webchannel=e,a.State=0,a.protocol=t.protocol,a.onStateChanged=null,a.onControlMsg=null,a.debugmode=0,a.keepalive=n,a.rtcKeepAlive=null,a.Start=function(){1==a.debugmode&&console.log("start"),a.xxStateChange(3),a.webchannel.onmessage=a.xxOnMessage,a.rtcKeepAlive=setInterval(a.xxSendRtcKeepAlive,3e4)};var r=new FileReader,o=!1,l=[];return r.readAsBinaryString?r.onload=function(e){a.xxOnSocketData(e.target.result),0==l.length?o=!1:r.readAsBinaryString(new Blob([l.shift()]))}:r.readAsArrayBuffer&&(r.onloadend=function(e){a.xxOnSocketData(e.target.result),0==l.length?o=!1:r.readAsArrayBuffer(l.shift())}),a.xxOnMessage=function(e){if("string"!=typeof e.data)if("object"==typeof e.data){if(1==o)return void l.push(e.data);if(r.readAsBinaryString)o=!0,r.readAsBinaryString(new Blob([e.data]));else if(f.readAsArrayBuffer)o=!0,r.readAsArrayBuffer(e.data);else{for(var t="",n=new Uint8Array(e.data),i=n.byteLength,s=0;s<i;s++)t+=String.fromCharCode(n[s]);a.xxOnSocketData(t)}}else a.xxOnSocketData(e.data);else null!=a.onControlMsg&&a.onControlMsg(e.data)},a.xxOnSocketData=function(e){if(e){if("object"==typeof e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=0;o<r;o++)t+=String.fromCharCode(n[o]);e=t}else if("string"!=typeof e)return;return a.m.ProcessData(e)}},a.sendCtrlMsg=function(e){"string"==typeof e&&(a.webchannel.send(e),null!=a.keepalive&&a.keepalive.sendKeepAlive())},a.send=function(e){if("string"==typeof e){for(var t=new Uint8Array(e.length),n=0;n<e.length;++n)t[n]=e.charCodeAt(n);e=t}a.webchannel.send(e)},a.xxStateChange=function(e){a.State!=e&&(a.State=e,a.m.xxStateChange(a.State),null!=a.onStateChanged&&a.onStateChanged(a,a.State))},a.Stop=function(){1==a.debugmode&&console.log("stop"),null!=a.rtcKeepAlive&&(clearInterval(a.rtcKeepAlive),a.rtcKeepAlive=null),a.xxStateChange(0)},a.xxSendRtcKeepAlive=function(){a.sendCtrlMsg(JSON.stringify({action:"ping"}))},a}