-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbrowserext.js
54 lines (39 loc) · 1.41 KB
/
browserext.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
var WebSocketServer = require('websocket').server;
var http = require('http');
var winston = require('winston');
var protocol = require('./protocol');
var portNumbers = [6263, 10196, 14826, 24866,
25012, 38156, 46365, 49806, 55735, 59488];
var extId = 'chrome-extension://aomjjhallfgjeglblehebfpbcfeobpgk';
exports.connect = function() {
portNumbers.forEach(function(port) {
startServer(port)
});
winston.info('Servers started on all ports');
}
function startServer(port) {
var server = http.createServer(function(request, response) { });
server.listen(port, function() { });
wsServer = new WebSocketServer({
httpServer: server
});
wsServer.on('request', function(request) {
winston.debug('Connection request from origin: ' + request.origin);
if (request.origin != extId) {
winston.log("not authorized, rejected.");
request.reject();
return;
}
var connection = request.accept(null, request.origin);
winston.info('Connection accepted.');
connection.on('message', function(message) {
protocol.handleMessage(connection, message);
});
connection.on('close', function(connection) {
winston.info('Connection closed');
payloadKey = null;
m4 = null;
});
});
// winston.info("Websocket server started on port " + port)
}