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