-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
37 lines (28 loc) · 931 Bytes
/
server.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
require("dotenv").config({ path: "./config/.env" });
const socket = require("socket.io");
require("express-socket.io-session");
const passportSocketIo = require("passport.socketio");
const app = require("./app");
const PORT = process.env.PORT || 5000;
const server = app.listen(PORT, () => {
console.log("Server was run successfully");
});
global.socket = socket;
global.io = socket(server);
const socketIoPassportOptions = Object.assign(app.sessionOptions, {
success: (data, accept) => {
accept(null, false);
},
fail: (data, message, error, accept) => {
accept(null, false);
},
});
global.io.use(passportSocketIo.authorize(app.sessionOptions));
global.sessionMap = {};
global.io.on("connection", (socket) => {
console.log(global.sessionMap);
if (!global.sessionMap.hasOwnProperty(socket.request.user.id)) {
global.sessionMap[socket.request.user.id] = socket.id;
}
});
module.exports = server;