-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
66 lines (57 loc) · 1.77 KB
/
server.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function() {
'use strict';
var http = require('http');
var express = require('express');
var io = require('socket.io');
var pty = require('pty.js');
var terminal = require('term.js');
var Console = require('console').Console;
var logger = new Console(process.stdout, process.stderr);
var app = express();
var server = http.createServer(app);
/*jslint unparam: true*/
app.use(function(req, res, next) {
var setHeader = res.setHeader;
res.setHeader = function(name) {
switch (name) {
case 'Cache-Control':
case 'Last-Modified':
case 'ETag':
return;
}
return setHeader.apply(res, arguments);
};
next();
});
/*jslint unparam: false*/
app.use(terminal.middleware({path: '/term/term.js'}));
app.use(express.static(__dirname + '/static/'));
server.listen(8080);
io = io.listen(server, {
log: false
});
var browser = {
sock: null
};
var rasp = {
socke: null
};
io.sockets.on('connection', function(sock) {
sock.on('browser_connected', function(data) {
if(browser.sock == null) {
browser.sock = sock;
browser.sock.on('from_browser_data', function(data) {
rasp.sock.emit('from_browser_data', data);
});
rasp.sock.emit('browser_connected');
}
});
sock.on('rasp_connected', function(data) {
logger.log('rasp_connected');
rasp.sock = sock;
rasp.sock.on('from_rasp_data', function(data) {
browser.sock.emit('from_rasp_data', data);
});
});
});
}());