mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-23 14:46:49 +03:00
1 line
1.9 KiB
JavaScript
1 line
1.9 KiB
JavaScript
var CreateKvmDataChannel=function(e,t,n){var o={},l=(((o.m=t).parent=o).webchannel=e,o.State=0,o.protocol=t.protocol,o.onStateChanged=null,o.onControlMsg=null,o.debugmode=0,o.keepalive=n,o.rtcKeepAlive=null,o.Start=function(){1==o.debugmode&&console.log("start"),o.xxStateChange(3),o.webchannel.onmessage=o.xxOnMessage,o.rtcKeepAlive=setInterval(o.xxSendRtcKeepAlive,3e4)},new FileReader),i=!1,s=[];return l.readAsBinaryString?l.onload=function(e){o.xxOnSocketData(e.target.result),0==s.length?i=!1:l.readAsBinaryString(new Blob([s.shift()]))}:l.readAsArrayBuffer&&(l.onloadend=function(e){o.xxOnSocketData(e.target.result),0==s.length?i=!1:l.readAsArrayBuffer(s.shift())}),o.xxOnMessage=function(e){if("string"==typeof e.data)null!=o.onControlMsg&&o.onControlMsg(e.data);else if("object"==typeof e.data)if(1==i)s.push(e.data);else if(l.readAsBinaryString)i=!0,l.readAsBinaryString(new Blob([e.data]));else if(f.readAsArrayBuffer)i=!0,l.readAsArrayBuffer(e.data);else{for(var t="",n=new Uint8Array(e.data),a=n.byteLength,r=0;r<a;r++)t+=String.fromCharCode(n[r]);o.xxOnSocketData(t)}else o.xxOnSocketData(e.data)},o.xxOnSocketData=function(e){if(e){if("object"==typeof e){for(var t="",n=new Uint8Array(e),a=n.byteLength,r=0;r<a;r++)t+=String.fromCharCode(n[r]);e=t}else if("string"!=typeof e)return;return o.m.ProcessData(e)}},o.sendCtrlMsg=function(e){"string"==typeof e&&(o.webchannel.send(e),null!=o.keepalive)&&o.keepalive.sendKeepAlive()},o.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}o.webchannel.send(e)},o.xxStateChange=function(e){o.State!=e&&(o.State=e,o.m.xxStateChange(o.State),null!=o.onStateChanged)&&o.onStateChanged(o,o.State)},o.Stop=function(){1==o.debugmode&&console.log("stop"),null!=o.rtcKeepAlive&&(clearInterval(o.rtcKeepAlive),o.rtcKeepAlive=null),o.xxStateChange(0)},o.xxSendRtcKeepAlive=function(){o.sendCtrlMsg(JSON.stringify({action:"ping"}))},o} |