mirror of https://gitgud.io/fatchan/jschan.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
595 B
30 lines
595 B
5 years ago
|
'use strict';
|
||
|
|
||
|
const configs = require(__dirname+'/configs/main.json');
|
||
|
|
||
|
module.exports = {
|
||
|
|
||
|
io: null, //null to begin with
|
||
|
|
||
|
connect: (server) => {
|
||
|
const io = require('socket.io')(server);
|
||
|
const redisAdapter = require('socket.io-redis');
|
||
|
io.adapter(redisAdapter({ ...configs.redis }));
|
||
|
module.exports.io = io;
|
||
|
module.exports.startRooms();
|
||
|
},
|
||
|
|
||
|
startRooms: () => {
|
||
|
module.exports.io.on('connection', socket => {
|
||
|
socket.on('room', room => {
|
||
|
socket.join(room);
|
||
|
});
|
||
|
});
|
||
|
},
|
||
|
|
||
|
emitRoom: (room, event, message) => {
|
||
|
module.exports.io.to(room).emit(event, message);
|
||
|
},
|
||
|
|
||
|
}
|