var openWs = function() {
var ws = new WebSocket(url, protocols);
+ var unloadCallback = function(event) {
+ var message = 'Close terminal? this will also terminate the command.';
+ (event || window.event).returnValue = message;
+ return message;
+ };
ws.onopen = function(event) {
console.log("Websocket connection opened");
});
term.on('open', function() {
- window.onresize = function(event) {
+ window.addEventListener('resize', function(event) {
term.fit();
- };
+ });
+ window.addEventListener('beforeunload', unloadCallback);
term.fit();
term.focus();
});
term.showOverlay("Connection Closed", null);
}
}
+ window.removeEventListener('beforeunload', unloadCallback);
clearInterval(pingTimer);
if (autoReconnect > 0) {
setTimeout(openWs, autoReconnect * 1000);
<body>
<div id="terminal-container"></div>
<script src="auth_token.js"></script>
- <script>!function(){var e,o,n,t=document.getElementById("terminal-container"),c="https:"==window.location.protocol,s=(c?"wss://":"ws://")+window.location.host+window.location.pathname+"ws",i="undefined"!=typeof tty_auth_token?tty_auth_token:null,a=["tty"],r=-1,l=function(){var c=new WebSocket(s,a);c.onopen=function(s){for(console.log("Websocket connection opened"),n=!1,c.send(JSON.stringify({AuthToken:i})),o=setInterval(d,3e4,c),"undefined"!=typeof e&&e.destroy(),e=new Terminal,e.on("resize",function(o){c.readyState===WebSocket.OPEN&&c.send("2"+JSON.stringify({columns:o.cols,rows:o.rows})),setTimeout(function(){e.showOverlay(o.cols+"x"+o.rows)},500)}),e.on("data",function(e){c.readyState===WebSocket.OPEN&&c.send("0"+e)}),e.on("open",function(){window.onresize=function(o){e.fit()},e.fit(),e.focus()});t.firstChild;)t.removeChild(t.firstChild);e.open(t)},c.onmessage=function(o){var n=o.data.slice(1);switch(o.data[0]){case"0":e.writeUTF8(window.atob(n));break;case"1":break;case"2":document.title=n;break;case"3":var t=JSON.parse(n);Object.keys(t).forEach(function(o){console.log("Setting "+o+": "+t[o]),e.setOption(o,t[o])});break;case"4":r=JSON.parse(n),console.log("Enabling reconnect: "+r+" seconds")}},c.onclose=function(t){console.log("Websocket connection closed with code: "+t.code),e&&(e.off("data"),e.off("resize"),n||e.showOverlay("Connection Closed",null)),clearInterval(o),r>0&&setTimeout(l,1e3*r)}},d=function(e){e.send("1")};l()}();</script>
+ <script>!function(){var e,n,o,t=document.getElementById("terminal-container"),i="https:"==window.location.protocol,s=(i?"wss://":"ws://")+window.location.host+window.location.pathname+"ws",a="undefined"!=typeof tty_auth_token?tty_auth_token:null,c=["tty"],r=-1,l=function(){var i=new WebSocket(s,c),f=function(e){var n="Close terminal? this will also terminate the command.";return(e||window.event).returnValue=n,n};i.onopen=function(s){for(console.log("Websocket connection opened"),o=!1,i.send(JSON.stringify({AuthToken:a})),n=setInterval(d,3e4,i),"undefined"!=typeof e&&e.destroy(),e=new Terminal,e.on("resize",function(n){i.readyState===WebSocket.OPEN&&i.send("2"+JSON.stringify({columns:n.cols,rows:n.rows})),setTimeout(function(){e.showOverlay(n.cols+"x"+n.rows)},500)}),e.on("data",function(e){i.readyState===WebSocket.OPEN&&i.send("0"+e)}),e.on("open",function(){window.addEventListener("resize",function(n){e.fit()}),window.addEventListener("beforeunload",f),e.fit(),e.focus()});t.firstChild;)t.removeChild(t.firstChild);e.open(t)},i.onmessage=function(n){var o=n.data.slice(1);switch(n.data[0]){case"0":e.writeUTF8(window.atob(o));break;case"1":break;case"2":document.title=o;break;case"3":var t=JSON.parse(o);Object.keys(t).forEach(function(n){console.log("Setting "+n+": "+t[n]),e.setOption(n,t[n])});break;case"4":r=JSON.parse(o),console.log("Enabling reconnect: "+r+" seconds")}},i.onclose=function(t){console.log("Websocket connection closed with code: "+t.code),e&&(e.off("data"),e.off("resize"),o||e.showOverlay("Connection Closed",null)),window.removeEventListener("beforeunload",f),clearInterval(n),r>0&&setTimeout(l,1e3*r)}},d=function(e){e.send("1")};l()}();</script>
</body>
</html>