-
Notifications
You must be signed in to change notification settings - Fork 101
/
execWebSocket.js
43 lines (31 loc) · 984 Bytes
/
execWebSocket.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
const logger = require("./logger");
const _ = require('lodash');
function originIsAllowed(origin) {
// put logic here to detect whether the specified origin is allowed.
return true;
}
// process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
const ExecOperator = function () {
this.registers = {};
this.start = () => {
let that = this;
global.wsServer.on('request', function (request) {
try {
let protocol = request.requestedProtocols[0];
console.log(protocol, that.registers);
let func = that.registers[protocol];
// console.log(func);
if (func) {
func(request);
}
} catch (e) {
console.log(e);
}
});
};
this.register = (protocol, func) => {
console.log(protocol);
this.registers[protocol] = func;
};
}
module.exports = new ExecOperator();