-
Notifications
You must be signed in to change notification settings - Fork 18
/
sockets.js
22 lines (20 loc) · 1.15 KB
/
sockets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const socketio = require('socket.io');
const Room = require('./controllers/Rooms');
const Canvas = require('./controllers/Canvas');
const Disconnect = require('./controllers/Disconnect');
const Game = require('./controllers/Game');
module.exports.init = (server) => {
const io = socketio(server);
io.on('connection', (socket) => {
console.log('connected user');
socket.on('newPrivateRoom', (player) => new Room(io, socket).createPrivateRoom(player));
socket.on('joinRoom', async (data) => { await new Room(io, socket).joinRoom(data); });
socket.on('settingsUpdate', (data) => new Room(io, socket).updateSettings(data));
socket.on('drawing', (data) => new Canvas(io, socket).broadcastDrawing(data));
socket.on('clearCanvas', () => new Canvas(io, socket).clearCanvas());
socket.on('startGame', async () => { await new Game(io, socket).startGame(); });
socket.on('getPlayers', async () => { await new Game(io, socket).getPlayers(); });
socket.on('message', (data) => new Game(io, socket).onMessage(data));
socket.on('disconnect', () => new Disconnect(io, socket).onDisconnect());
});
};