let io;
module.exports = {
init: (server) => {
io = require('socket.io').listen(server); io.origins('*:*');
return io;
},
get: () => {
if (!io) {
throw new Error("socket is not initialized");
}
return io;
}
};
const app = require('../app');
const http = require('http');
/**
* Get port from environment and store in Express.
*/
const port = '3015';
app.set('port', port);
/**
* Create HTTP server.
*/
const server = http.createServer(app);
const io = require('./socket.js').init(server);
io.on('connection', (socket) => {
console.log('Connection success', socket.id);
socket.on('disconnect', () => {
console.log('Connection disconnected', socket.id);
});
}
const io = require('./socket.js').get();