-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
41 lines (29 loc) · 1.03 KB
/
index.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
'use strict';
const WebsocketServer = require('websocket').server;
const http = require('http');
var createWebSocketServer = function(args, config, logger) {
const log = logger.create('websocket.server');
log.info('Starting websocket server...');
let port = typeof config.websocketServer.port !== 'undefined' ? config.websocketServer.port : 8889;
let httpServer = http.createServer((req, res) => {
res.writeHead(404);
res.end();
});
let server = new WebsocketServer({
httpServer: httpServer
});
// Add possibility to set custom events for users before server starts
if(config.websocketServer.beforeStart) {
config.websocketServer.beforeStart(server);
}
httpServer.listen(port, () => {
// Add possibility to do something after server has started
if(config.websocketServer.afterStart) {
config.websocketServer.afterStart(server);
}
log.info(`websocket server started on port ${port}`);
});
};
module.exports = {
'framework:websocket-server': ['factory', createWebSocketServer]
};