-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.js
40 lines (34 loc) · 1.19 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var client = {};
client.run = function (options) {
options = options || {};
var socket = new WebSocket(options.remote);
var term = new Terminal({
cursorBlink: true,
});
term.open(options.target);
term.fit();
var cols = term.cols,
rows = term.rows;
socket.onopen = function(e) {
socket.send(JSON.stringify({"screen":{"cols": cols, "rows": rows}}));
term.on('data', function(data) {
socket.send(JSON.stringify({'stdin':data}));
});
socket.onmessage = function(event) {
json_msg = JSON.parse(event.data);
var type = json_msg.type;
switch (type) {
case 'loadavg':
document.getElementById('uptime').innerHTML = "loadavg: " + json_msg.stdout;
break;
case 'terminal':
term.write(json_msg.stdout);
break;
}
};
socket.onclose = function() {
//term.destroy();
};
};
return {'socket': socket, 'term': term};
};