-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockets.js
39 lines (37 loc) · 1.34 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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* eslint-disable comma-dangle */
/* eslint-disable function-paren-newline */
/* eslint-disable implicit-arrow-linebreak */
/* eslint-disable quotes */
/* eslint-disable indent */
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());
});
};