-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (50 loc) · 1.29 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var socketio = require("socket.io");
require("./extensions");
var seats = require("./seats"),
api = require("./railsApi"),
SeatingClient = require("./seatingClient");
if (process.env.NODE_ENV == "production") {
var dsn = process.env.SENTRY_DSN;
if (!dsn) {
console.log('error: missing ENV variable SENTRY_DSN');
process.exit(1);
}
var Sentry = require('@sentry/node');
Sentry.init({
dsn: dsn
});
}
var clients = {};
api.init(clients);
var io = socketio(api.server, {
"path": "/node"
});
io.of("/seating")
.use(function (socket, next) {
var restoreId = socket.handshake.query.restore_id;
if (restoreId && !(restoreId in clients)) {
next(new Error("Invalid socket id to restore"));
return;
}
next();
})
.on("connection", function (socket) {
var client;
var restoreId = socket.handshake.query.restore_id;
if (restoreId) {
client = clients[restoreId];
client.setSocket(socket);
} else {
client = new SeatingClient(
socket,
socket.handshake.query.event_id,
socket.handshake.query.privileged === 'true'
);
client.on("destroyed", function () {
client.removeAllListeners();
delete clients[client.id];
});
clients[client.id] = client;
}
})
;