-
Notifications
You must be signed in to change notification settings - Fork 0
/
sockets.js
39 lines (31 loc) · 1.01 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
let socketListeners = {};
const routes = require('./routes/routes.js');
const server = routes.server;
const io = require('socket.io').listen(server);
const Scene = require('./models/scene');
function startSockets() {
io.on('connection', function(socket) {
console.log("connected");
socket.on('room',function(data) {
console.log("room join request",data.room);
if(!data.room) return;
attemptAccessCodeJoin(socket);
});
});
}
function attemptAccessCodeJoin(socket) {
Scene.findSceneFromAccessCode(data.room,function(sceneData){
socket.emit('accessResponse');
if(!sceneData.error) {
if(!socketListeners[sceneData.accessCode]) {
socketListeners[sceneData.accessCode] = [socket];
} else {
socketListeners[sceneData.accessCode].push(socket);
}
}
});
}
function sendScene(scene) {
}
module.exports.startSockets = startSockets;
module.exports.sendScene = sendScene;