Fixed exception when displaying large device file list.

Ylian Saint-Hilaire committed Aug 25, 2020 at 10:28 UTC 90fb380fb62da4c0f21ea1b665f9a84559502578
2 files changed +8 -2
public/scripts/agent-redir-ws-0.1.1-min.js
+1 -1
@@ -1 +1 @@
1 -var CreateAgentRedirect=function(e,t,n,o,a,c){var s={};function l(){1==s.webSwitchOk&&1==s.webRtcActive&&(s.latency.current=-1,s.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc0"}'),s.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc1"}'),null!=s.onStateChanged&&s.onStateChanged(s,s.State))}((s.m=t).parent=s).meshserver=e,s.authCookie=o,s.rauthCookie=a,s.State=0,s.nodeid=null,s.options=null,s.socket=null,s.connectstate=-1,s.tunnelid=Math.random().toString(36).substring(2),s.protocol=t.protocol,s.onStateChanged=null,s.ctrlMsgAllowed=!0,s.attemptWebRTC=!1,s.webRtcActive=!1,s.webSwitchOk=!1,s.webchannel=null,s.webrtc=null,s.debugmode=0,s.serverIsRecording=!1,s.latency={lastSend:null,current:-1,callback:null},null==c&&(c="/"),s.consoleMessage=null,s.onConsoleMessageChange=null,s.metadata=null,s.onMetadataChange=null,s.Start=function(e){var t=window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/meshrelay.ashx?browser=1&p="+s.protocol+(e?"&nodeid="+e:"")+"&id="+s.tunnelid;if(null!=o&&""!=o&&(t+="&auth="+o),null!=urlargs&&null!=urlargs.slowrelay&&(t+="&slowrelay="+urlargs.slowrelay),s.nodeid=e,s.connectstate=0,s.socket=new WebSocket(t),s.socket.binaryType="arraybuffer",s.socket.onopen=s.xxOnSocketConnected,s.socket.onmessage=s.xxOnMessage,s.socket.onerror=function(e){},s.socket.onclose=s.xxOnSocketClosed,s.xxStateChange(1),null!=s.meshserver){var n="*"+c+"meshrelay.ashx?p="+s.protocol+"&nodeid="+e+"&id="+s.tunnelid;null!=a&&""!=a&&(n+="&rauth="+a),s.meshserver.send({action:"msg",type:"tunnel",nodeid:s.nodeid,value:n,usage:s.protocol})}},s.xxOnSocketConnected=function(){1==s.debugmode&&console.log("onSocketConnected"),s.xxStateChange(2)},s.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?s.setConsoleMessage(t.msg,t.msgid,t.msgargs,t.timeout):"metadata"==t.type?(s.metadata=t,s.onMetadataChange&&s.onMetadataChange(s.metadata)):"rtt"==t.type&&"number"==typeof t.time?(s.latency.current=(new Date).getTime()-t.time,null!=s.latency.callbacks&&s.latency.callback(s.latency.current)):null!=s.webrtc&&("answer"==t.type?s.webrtc.setRemoteDescription(new RTCSessionDescription(t),function(){},s.xxCloseWebRTC):"webrtc0"==t.type?(s.webSwitchOk=!0,l()):"webrtc1"==t.type?s.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc2"}'):t.type)):s.m.ProcessData(e)},s.setConsoleMessage=function(e,t,n,o){s.consoleMessage!=e&&(s.consoleMessage=e,s.consoleMessageId=t,s.consoleMessageArgs=n,s.consoleMessageTimeout=o,s.onConsoleMessageChange&&s.onConsoleMessageChange(s,s.consoleMessage,s.consoleMessageId))},s.sendCtrlMsg=function(e){if(1==s.ctrlMsgAllowed){"undefined"!=typeof args&&args.redirtrace&&console.log("RedirSend",typeof e,e);try{s.socket.send(e)}catch(e){}}},s.xxOnMessage=function(e){if(s.State<3&&("c"==e.data||"cr"==e.data)){if("cr"==e.data&&(s.serverIsRecording=!0),null!=s.options){delete s.options.action,s.options.type="options";try{s.sendCtrlMsg(JSON.stringify(s.options))}catch(e){}}try{s.socket.send(s.protocol)}catch(e){}if(s.xxStateChange(3),1==s.attemptWebRTC){"undefined"!=typeof RTCPeerConnection?s.webrtc=new RTCPeerConnection(null):"undefined"!=typeof webkitRTCPeerConnection&&(s.webrtc=new webkitRTCPeerConnection(null)),null!=s.webrtc&&s.webrtc.createDataChannel&&(s.webchannel=s.webrtc.createDataChannel("DataChannel",{}),s.webchannel.binaryType="arraybuffer",s.webchannel.onmessage=s.xxOnMessage,s.webchannel.onopen=function(){s.webRtcActive=!0,l()},s.webchannel.onclose=function(e){s.webRtcActive&&s.Stop()},s.webrtc.onicecandidate=function(e){if(null==e.candidate)try{s.sendCtrlMsg(JSON.stringify(s.webrtcoffer))}catch(e){}else s.webrtcoffer.sdp+="a="+e.candidate.candidate+"\r\n"},s.webrtc.oniceconnectionstatechange=function(){null!=s.webrtc&&("disconnected"==s.webrtc.iceConnectionState?1==s.webRtcActive?s.Stop():s.xxCloseWebRTC():"failed"==s.webrtc.iceConnectionState&&s.xxCloseWebRTC())},s.webrtc.createOffer(function(e){s.webrtcoffer=e,s.webrtc.setLocalDescription(e,function(){},s.xxCloseWebRTC)},s.xxCloseWebRTC,{mandatory:{OfferToReceiveAudio:!1,OfferToReceiveVideo:!1}}))}}else if("string"==typeof e.data)s.xxOnControlCommand(e.data);else if(s.m.ProcessBinaryCommand)if(0!=u){var t=new Uint8Array(e.data);if(g.push(t),u+=t.byteLength,d<=u){var n=new Uint8Array(u),o=0;for(var a in g)n.set(g[a],o),o+=g[a].byteLength;s.m.ProcessBinaryCommand(i,d,n),u=d=i=0,g=[]}}else{var c=((t=new Uint8Array(e.data))[0]<<8)+t[1],r=(t[2]<<8)+t[3];27==c&&8==r&&(c=(t[8]<<8)+t[9],r=(t[5]<<16)+(t[6]<<8)+t[7],t=t.slice(8)),r!=t.byteLength?(i=c,d=r,u=t.byteLength,g=[t]):s.m.ProcessBinaryCommand(c,r,t)}else s.m.ProcessBinaryData?s.m.ProcessBinaryData(new Uint8Array(e.data)):s.m.ProcessData(String.fromCharCode.apply(null,new Uint8Array(e.data)))};var i=0,d=0,u=0,g=[];return s.sendText=function(e){"string"!=typeof e&&(e=JSON.stringify(e)),s.send(encode_utf8(e))},s.send=function(e){"undefined"!=typeof args&&args.redirtrace&&console.log("RedirSend",typeof e,e.length,"{"==e[0]?e:rstr2hex(e).substring(0,64));try{if(null!=s.socket&&s.socket.readyState==WebSocket.OPEN)if("string"==typeof e)if(1==s.debugmode){for(var t=new Uint8Array(e.length),n=[],o=0;o<e.length;++o)t[o]=e.charCodeAt(o),n.push(e.charCodeAt(o));1==s.webRtcActive?s.webchannel.send(t.buffer):s.socket.send(t.buffer)}else{for(t=new Uint8Array(e.length),o=0;o<e.length;++o)t[o]=e.charCodeAt(o);1==s.webRtcActive?s.webchannel.send(t.buffer):s.socket.send(t.buffer)}else 1==s.webRtcActive?s.webchannel.send(e):s.socket.send(e)}catch(e){}},s.xxOnSocketClosed=function(){s.Stop(1)},s.xxStateChange=function(e){s.State!=e&&(s.State=e,s.m.xxStateChange(s.State),null!=s.onStateChanged&&s.onStateChanged(s,s.State))},s.xxCloseWebRTC=function(){if(null!=s.webchannel){try{s.webchannel.close()}catch(e){}s.webchannel=null}if(null!=s.webrtc){try{s.webrtc.close()}catch(e){}s.webrtc=null}s.webRtcActive=!1},s.Stop=function(e){if(1==s.debugmode&&console.log("stop",e),s.xxCloseWebRTC(),s.connectstate=-1,null!=s.socket){try{1==s.socket.readyState&&(s.sendCtrlMsg('{"ctrlChannel":"102938","type":"close"}'),s.socket.close())}catch(e){}s.socket=null}s.xxStateChange(0)},s}
\ No newline at end of file
1 +var CreateAgentRedirect=function(e,t,n,o,a,c){var i={};function d(){1==i.webSwitchOk&&1==i.webRtcActive&&(i.latency.current=-1,i.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc0"}'),i.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc1"}'),null!=i.onStateChanged&&i.onStateChanged(i,i.State))}((i.m=t).parent=i).meshserver=e,i.authCookie=o,i.rauthCookie=a,i.State=0,i.nodeid=null,i.options=null,i.socket=null,i.connectstate=-1,i.tunnelid=Math.random().toString(36).substring(2),i.protocol=t.protocol,i.onStateChanged=null,i.ctrlMsgAllowed=!0,i.attemptWebRTC=!1,i.webRtcActive=!1,i.webSwitchOk=!1,i.webchannel=null,i.webrtc=null,i.debugmode=0,i.serverIsRecording=!1,i.latency={lastSend:null,current:-1,callback:null},null==c&&(c="/"),i.consoleMessage=null,i.onConsoleMessageChange=null,i.metadata=null,i.onMetadataChange=null,i.Start=function(e){var t=window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/meshrelay.ashx?browser=1&p="+i.protocol+(e?"&nodeid="+e:"")+"&id="+i.tunnelid;if(null!=o&&""!=o&&(t+="&auth="+o),null!=urlargs&&null!=urlargs.slowrelay&&(t+="&slowrelay="+urlargs.slowrelay),i.nodeid=e,i.connectstate=0,i.socket=new WebSocket(t),i.socket.binaryType="arraybuffer",i.socket.onopen=i.xxOnSocketConnected,i.socket.onmessage=i.xxOnMessage,i.socket.onerror=function(e){},i.socket.onclose=i.xxOnSocketClosed,i.xxStateChange(1),null!=i.meshserver){var n="*"+c+"meshrelay.ashx?p="+i.protocol+"&nodeid="+e+"&id="+i.tunnelid;null!=a&&""!=a&&(n+="&rauth="+a),i.meshserver.send({action:"msg",type:"tunnel",nodeid:i.nodeid,value:n,usage:i.protocol})}},i.xxOnSocketConnected=function(){1==i.debugmode&&console.log("onSocketConnected"),i.xxStateChange(2)},i.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?i.setConsoleMessage(t.msg,t.msgid,t.msgargs,t.timeout):"metadata"==t.type?(i.metadata=t,i.onMetadataChange&&i.onMetadataChange(i.metadata)):"rtt"==t.type&&"number"==typeof t.time?(i.latency.current=(new Date).getTime()-t.time,null!=i.latency.callbacks&&i.latency.callback(i.latency.current)):null!=i.webrtc&&("answer"==t.type?i.webrtc.setRemoteDescription(new RTCSessionDescription(t),function(){},i.xxCloseWebRTC):"webrtc0"==t.type?(i.webSwitchOk=!0,d()):"webrtc1"==t.type?i.sendCtrlMsg('{"ctrlChannel":"102938","type":"webrtc2"}'):t.type)):i.m.ProcessData(e)},i.setConsoleMessage=function(e,t,n,o){i.consoleMessage!=e&&(i.consoleMessage=e,i.consoleMessageId=t,i.consoleMessageArgs=n,i.consoleMessageTimeout=o,i.onConsoleMessageChange&&i.onConsoleMessageChange(i,i.consoleMessage,i.consoleMessageId))},i.sendCtrlMsg=function(e){if(1==i.ctrlMsgAllowed){"undefined"!=typeof args&&args.redirtrace&&console.log("RedirSend",typeof e,e);try{i.socket.send(e)}catch(e){}}},i.xxOnMessage=function(e){if(i.State<3&&("c"==e.data||"cr"==e.data)){if("cr"==e.data&&(i.serverIsRecording=!0),null!=i.options){delete i.options.action,i.options.type="options";try{i.sendCtrlMsg(JSON.stringify(i.options))}catch(e){}}try{i.socket.send(i.protocol)}catch(e){}if(i.xxStateChange(3),1==i.attemptWebRTC){"undefined"!=typeof RTCPeerConnection?i.webrtc=new RTCPeerConnection(null):"undefined"!=typeof webkitRTCPeerConnection&&(i.webrtc=new webkitRTCPeerConnection(null)),null!=i.webrtc&&i.webrtc.createDataChannel&&(i.webchannel=i.webrtc.createDataChannel("DataChannel",{}),i.webchannel.binaryType="arraybuffer",i.webchannel.onmessage=i.xxOnMessage,i.webchannel.onopen=function(){i.webRtcActive=!0,d()},i.webchannel.onclose=function(e){i.webRtcActive&&i.Stop()},i.webrtc.onicecandidate=function(e){if(null==e.candidate)try{i.sendCtrlMsg(JSON.stringify(i.webrtcoffer))}catch(e){}else i.webrtcoffer.sdp+="a="+e.candidate.candidate+"\r\n"},i.webrtc.oniceconnectionstatechange=function(){null!=i.webrtc&&("disconnected"==i.webrtc.iceConnectionState?1==i.webRtcActive?i.Stop():i.xxCloseWebRTC():"failed"==i.webrtc.iceConnectionState&&i.xxCloseWebRTC())},i.webrtc.createOffer(function(e){i.webrtcoffer=e,i.webrtc.setLocalDescription(e,function(){},i.xxCloseWebRTC)},i.xxCloseWebRTC,{mandatory:{OfferToReceiveAudio:!1,OfferToReceiveVideo:!1}}))}}else if("string"==typeof e.data)i.xxOnControlCommand(e.data);else if(i.m.ProcessBinaryCommand)if(0!=f){var t=new Uint8Array(e.data);if(b.push(t),f+=t.byteLength,g<=f){var n=new Uint8Array(f),o=0;for(var a in b)n.set(b[a],o),o+=b[a].byteLength;i.m.ProcessBinaryCommand(u,g,n),f=g=u=0,b=[]}}else{var c=((t=new Uint8Array(e.data))[0]<<8)+t[1],r=(t[2]<<8)+t[3];27==c&&8==r&&(c=(t[8]<<8)+t[9],r=(t[5]<<16)+(t[6]<<8)+t[7],t=t.slice(8)),r!=t.byteLength?(u=c,g=r,f=t.byteLength,b=[t]):i.m.ProcessBinaryCommand(c,r,t)}else if(i.m.ProcessBinaryData)i.m.ProcessBinaryData(new Uint8Array(e.data));else if(e.data.byteLength<16e3)i.m.ProcessData(String.fromCharCode.apply(null,new Uint8Array(e.data)));else{var s=new Blob([new Uint8Array(e.data)]),l=new FileReader;l.onload=function(e){i.m.ProcessData(e.target.result)},l.readAsText(s)}};var u=0,g=0,f=0,b=[];return i.sendText=function(e){"string"!=typeof e&&(e=JSON.stringify(e)),i.send(encode_utf8(e))},i.send=function(e){"undefined"!=typeof args&&args.redirtrace&&console.log("RedirSend",typeof e,e.length,"{"==e[0]?e:rstr2hex(e).substring(0,64));try{if(null!=i.socket&&i.socket.readyState==WebSocket.OPEN)if("string"==typeof e)if(1==i.debugmode){for(var t=new Uint8Array(e.length),n=[],o=0;o<e.length;++o)t[o]=e.charCodeAt(o),n.push(e.charCodeAt(o));1==i.webRtcActive?i.webchannel.send(t.buffer):i.socket.send(t.buffer)}else{for(t=new Uint8Array(e.length),o=0;o<e.length;++o)t[o]=e.charCodeAt(o);1==i.webRtcActive?i.webchannel.send(t.buffer):i.socket.send(t.buffer)}else 1==i.webRtcActive?i.webchannel.send(e):i.socket.send(e)}catch(e){}},i.xxOnSocketClosed=function(){i.Stop(1)},i.xxStateChange=function(e){i.State!=e&&(i.State=e,i.m.xxStateChange(i.State),null!=i.onStateChanged&&i.onStateChanged(i,i.State))},i.xxCloseWebRTC=function(){if(null!=i.webchannel){try{i.webchannel.close()}catch(e){}i.webchannel=null}if(null!=i.webrtc){try{i.webrtc.close()}catch(e){}i.webrtc=null}i.webRtcActive=!1},i.Stop=function(e){if(1==i.debugmode&&console.log("stop",e),i.xxCloseWebRTC(),i.connectstate=-1,null!=i.socket){try{1==i.socket.readyState&&(i.sendCtrlMsg('{"ctrlChannel":"102938","type":"close"}'),i.socket.close())}catch(e){}i.socket=null}i.xxStateChange(0)},i}
\ No newline at end of file
public/scripts/agent-redir-ws-0.1.1.js
+7 -1
@@ -206,7 +206,13 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
206 obj.m.ProcessBinaryData(new Uint8Array(e.data));
207 } else {
208 // Send as Text
209 - obj.m.ProcessData(String.fromCharCode.apply(null, new Uint8Array(e.data)));
209 + if (e.data.byteLength < 16000) { // Process small data block
210 + obj.m.ProcessData(String.fromCharCode.apply(null, new Uint8Array(e.data))); // This will stack overflow on Chrome with 100k+ blocks.
211 + } else { // Process large data block
212 + var bb = new Blob([new Uint8Array(e.data)]), f = new FileReader();
213 + f.onload = function (e) { obj.m.ProcessData(e.target.result); };
214 + f.readAsText(bb);
215 + }
216 }
217 }
218 };