-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.js
45 lines (35 loc) · 1.31 KB
/
socket.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
40
41
42
43
44
45
// socket.js
const io = require('socket.io');
const sessionMiddleware = require('./middlewares/sessionMiddleware');
const passportMiddleware = require('./middlewares/passportMiddleware');
const authenticationMiddleware = require('./middlewares/authenticationMiddleware');
const {
handleShapeEvents,
handleTextEvents,
handleImageEvents,
handleDrawEvents,
handleEraseEvents,
handleChatEvents,
handleConnection,
handleDisconnection,
} = require('./socketEvents');
module.exports = (httpServer) => {
const socketIO = io(httpServer);
socketIO.use(sessionMiddleware);
socketIO.use(passportMiddleware.initialize());
socketIO.use(passportMiddleware.session());
socketIO.use(authenticationMiddleware);
socketIO.on('connection', handleConnection);
socketIO.on('create', handleShapeEvents.create);
socketIO.on('update', handleShapeEvents.update);
socketIO.on('bringToFront', handleShapeEvents.bringToFront);
socketIO.on('sendToBack', handleShapeEvents.sendToBack);
socketIO.on('textUpdate', handleTextEvents.update);
socketIO.on('newImage', handleImageEvents.newImage);
socketIO.on('updateImage', handleImageEvents.updateImage);
socketIO.on('draw', handleDrawEvents.draw);
socketIO.on('erase', handleEraseEvents.erase);
socketIO.on('chat message', handleChatEvents.message);
socketIO.on('disconnect', handleDisconnection);
return socketIO;
};