mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-09 23:34:26 +00:00
Send ping/pong
This commit is contained in:
parent
b711de495b
commit
00ddf781de
@ -24,14 +24,16 @@ type clientContext struct {
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
Input = '0'
|
Input = '0'
|
||||||
ResizeTerminal = '1'
|
Ping = '1'
|
||||||
|
ResizeTerminal = '2'
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Output = '0'
|
Output = '0'
|
||||||
SetWindowTitle = '1'
|
Pong = '1'
|
||||||
SetPreferences = '2'
|
SetWindowTitle = '2'
|
||||||
SetReconnect = '3'
|
SetPreferences = '3'
|
||||||
|
SetReconnect = '4'
|
||||||
)
|
)
|
||||||
|
|
||||||
type argResizeTerminal struct {
|
type argResizeTerminal struct {
|
||||||
@ -161,6 +163,8 @@ func (context *clientContext) processReceive() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Ping:
|
||||||
|
context.connection.WriteMessage(websocket.TextMessage, []byte{Pong})
|
||||||
case ResizeTerminal:
|
case ResizeTerminal:
|
||||||
var args argResizeTerminal
|
var args argResizeTerminal
|
||||||
err = json.Unmarshal(data[1:], &args)
|
err = json.Unmarshal(data[1:], &args)
|
||||||
|
File diff suppressed because one or more lines are too long
@ -9,9 +9,13 @@
|
|||||||
|
|
||||||
var term;
|
var term;
|
||||||
|
|
||||||
|
var pingTimer;
|
||||||
|
|
||||||
ws.onopen = function(event) {
|
ws.onopen = function(event) {
|
||||||
ws.send(gotty_auth_token);
|
ws.send(gotty_auth_token);
|
||||||
|
|
||||||
|
pingTimer = setInterval(sendPing, 30 * 1000, ws);
|
||||||
|
|
||||||
hterm.defaultStorage = new lib.Storage.Local();
|
hterm.defaultStorage = new lib.Storage.Local();
|
||||||
hterm.defaultStorage.clear();
|
hterm.defaultStorage.clear();
|
||||||
|
|
||||||
@ -30,7 +34,7 @@
|
|||||||
|
|
||||||
io.onTerminalResize = function(columns, rows) {
|
io.onTerminalResize = function(columns, rows) {
|
||||||
ws.send(
|
ws.send(
|
||||||
"1" + JSON.stringify(
|
"2" + JSON.stringify(
|
||||||
{
|
{
|
||||||
columns: columns,
|
columns: columns,
|
||||||
rows: rows,
|
rows: rows,
|
||||||
@ -52,39 +56,40 @@
|
|||||||
term.io.writeUTF16(data);
|
term.io.writeUTF16(data);
|
||||||
break;
|
break;
|
||||||
case '1':
|
case '1':
|
||||||
|
// pong
|
||||||
|
case '2':
|
||||||
term.setWindowTitle(data);
|
term.setWindowTitle(data);
|
||||||
break;
|
break;
|
||||||
case '2':
|
case '3':
|
||||||
preferences = JSON.parse(data);
|
preferences = JSON.parse(data);
|
||||||
Object.keys(preferences).forEach(function(key) {
|
Object.keys(preferences).forEach(function(key) {
|
||||||
console.log("Setting " + key + ": " + preferences[key]);
|
console.log("Setting " + key + ": " + preferences[key]);
|
||||||
term.getPrefs().set(key, preferences[key]);
|
term.getPrefs().set(key, preferences[key]);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '4':
|
||||||
autoReconnect = JSON.parse(data);
|
autoReconnect = JSON.parse(data);
|
||||||
|
console.log("Enabling reconnect: " + autoReconnect + " seconds")
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
ws.onclose = function(event) {
|
ws.onclose = function(event) {
|
||||||
if (term) {
|
if (term) {
|
||||||
term.uninstallKeyboard();
|
term.uninstallKeyboard();
|
||||||
term.io.showOverlay("Connection Closed", null);
|
term.io.showOverlay("Connection Closed", null);
|
||||||
}
|
}
|
||||||
tryReconnect();
|
clearInterval(pingTimer);
|
||||||
|
if (autoReconnect > 0) {
|
||||||
|
setTimeout(openWs, autoReconnect * 1000);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.onerror = function(error) {
|
|
||||||
tryReconnect();
|
var sendPing = function(ws) {
|
||||||
}
|
ws.send("1");
|
||||||
}
|
}
|
||||||
|
|
||||||
openWs();
|
openWs();
|
||||||
|
|
||||||
var tryReconnect = function() {
|
|
||||||
if (autoReconnect >= 0) {
|
|
||||||
setTimeout(openWs, autoReconnect * 1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})()
|
})()
|
||||||
|
Loading…
Reference in New Issue
Block a user