1let io;
2
3module.exports = {
4 init: (server) => {
5 io = require('socket.io').listen(server); io.origins('*:*');
6 return io;
7 },
8 get: () => {
9 if (!io) {
10 throw new Error("socket is not initialized");
11 }
12 return io;
13 }
14};
15
1const app = require('../app');
2const http = require('http');
3
4/**
5 * Get port from environment and store in Express.
6 */
7
8const port = '3015';
9app.set('port', port);
10
11/**
12 * Create HTTP server.
13 */
14
15const server = http.createServer(app);
16const io = require('./socket.js').init(server);
17
18io.on('connection', (socket) => {
19 console.log('Connection success', socket.id);
20 socket.on('disconnect', () => {
21 console.log('Connection disconnected', socket.id);
22 });
23}
24