MeshCentral/public/scripts/agent-redir-ws-0.1.1-min.js

1 line
6.3 KiB
JavaScript
Raw Normal View History

2020-09-07 23:18:46 -04:00
var CreateAgentRedirect=function(e,t,n,o,a,c){var d={};function u(){1==d.webSwitchOk&&1==d.webRtcActive&&(d.latency.current=-1,d.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc0"}'),d.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc1"}'),null!=d.onStateChanged&&d.onStateChanged(d,d.State))}((d.m=t).parent=d).meshserver=e,d.authCookie=o,d.rauthCookie=a,d.State=0,d.nodeid=null,d.options=null,d.socket=null,d.connectstate=-1,d.tunnelid=Math.random().toString(36).substring(2),d.protocol=t.protocol,d.onStateChanged=null,d.ctrlMsgAllowed=!0,d.attemptWebRTC=!1,d.webRtcActive=!1,d.webSwitchOk=!1,d.webchannel=null,d.webrtc=null,d.debugmode=0,d.serverIsRecording=!1,d.latency={lastSend:null,current:-1,callback:null},null==c&&(c="/"),d.consoleMessage=null,d.onConsoleMessageChange=null,d.metadata=null,d.onMetadataChange=null,d.Start=function(e){var t,n=window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/meshrelay.ashx?browser=1&p="+d.protocol+(e?"&nodeid="+e:"")+"&id="+d.tunnelid;null!=o&&""!=o&&(n+="&auth="+o),null!=urlargs&&null!=urlargs.slowrelay&&(n+="&slowrelay="+urlargs.slowrelay),d.nodeid=e,d.connectstate=0,d.socket=new WebSocket(n),d.socket.binaryType="arraybuffer",d.socket.onopen=d.xxOnSocketConnected,d.socket.onmessage=d.xxOnMessage,d.socket.onerror=function(e){},d.socket.onclose=d.xxOnSocketClosed,d.xxStateChange(1),null!=d.meshserver&&(t="*"+c+"meshrelay.ashx?p="+d.protocol+"&nodeid="+e+"&id="+d.tunnelid,null!=a&&""!=a&&(t+="&rauth="+a),d.meshserver.send({action:"msg",type:"tunnel",nodeid:d.nodeid,value:t,usage:d.protocol}))},d.xxOnSocketConnected=function(){1==d.debugmode&&console.log("onSocketConnected"),d.xxStateChange(2)},d.xxOnControlCommand=function(e){var t;try{t=JSON.parse(e)}catch(e){return}"102938"==t.ctrlChannel?("undefined"!=typeof args&&args.redirtrace&&console.log("RedirRecv",t),"console"==t.type?d.setConsoleMessage(t.msg,t.msgid,t.msgargs,t.timeout):"metadata"==t.type?(d.metadata=t,d.onMetadataChange&&d.onMetadataChange(d.metadata)):"rtt"==t.type&&"number"==typeof t.time?(d.latency.current=(new Date).getTime()-t.time,null!=d.latency.callbacks&&d.latency.callback(d.latency.current)):null!=d.webrtc&&("answer"==t.type?d.webrtc.setRemoteDescription(new RTCSessionDescription(t),function(){},d.xxCloseWebRTC):"webrtc0"==t.type?(d.webSwitchOk=!0,u()):"webrtc1"==t.type?d.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc2"}'):t.type)):d.m.ProcessData(e)},d.setConsoleMessage=function(e,t,n,o){d.consoleMessage!=e&&(d.consoleMessage=e,d.consoleMessageId=t,d.consoleMessageArgs=n,d.consoleMessageTimeout=o,d.onConsoleMessageChange&&d.onConsoleMessageChange(d,d.consoleMessage,d.consoleMessageId))},d.sendCtrlMsg=function(e){if(1==d.ctrlMsgAllowed){"undefined"!=typeof args&&args.redirtrace&&console.log("RedirSend",typeof e,e);try{d.socket.send(e)}catch(e){}}},d.xxOnMessage=function(e){if(d.State<3&&("c"==e.data||"cr"==e.data)){if("cr"==e.data&&(d.serverIsRecording=!0),null!=d.options){delete d.options.action,d.options.type="options";try{d.sendCtrlMsg(JSON.stringify(d.options))}catch(e){}}try{d.socket.send(d.protocol)}catch(e){}var t;return d.xxStateChange(3),void(1==d.attemptWebRTC&&(t=null,"undefined"!=typeof RTCPeerConnection?d.webrtc=new RTCPeerConnection(t):"undefined"!=typeof webkitRTCPeerConnection&&(d.webrtc=new webkitRTCPeerConnection(t)),null!=d.webrtc&&d.webrtc.createDataChannel&&(d.webchannel=d.webrtc.createDataChannel("DataChannel",{}),d.webchannel.binaryType="arraybuffer",d.webchannel.onmessage=d.xxOnMessage,d.webchannel.onopen=function(){d.webRtcActive=!0,u()},d.webchannel.onclose=function(e){d.webRtcActive&&d.Stop()},d.webrtc.onicecandidate=function(e){if(null==e.candidate)try{d.sendCtrlMsg(JSON.stringify(d.webrtcoffer))}catch(e){}else d.webrtcoffer.sdp+="a="+e.candidate.candidate+"\r\n"},d.webrtc.oniceconnectionstatechange=function(){null!=d.webrtc&&("disconnected"==d.webrtc.iceConnectionState?1==d.webRtcActive?d.Stop():d.xxCloseWebRTC():"failed"==d.webrtc.iceConnectionState&&d.xxCloseWebRTC())},d.web