MeshCentral/public/scripts/agent-redir-rtc-0.1.0-min.js

1 line
1.9 KiB
JavaScript
Raw Normal View History

2020-05-01 23:16:57 -04:00
var CreateKvmDataChannel=function(e,t,n){var o={};((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)};var l=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)if("object"==typeof e.data){if(1==i)return void s.push(e.data);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);else null!=o.onControlMsg&&o.onControlMsg(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}