-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.js
More file actions
32 lines (23 loc) · 855 Bytes
/
Copy pathsocket.js
File metadata and controls
32 lines (23 loc) · 855 Bytes
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
import { Server } from "socket.io";
import { socketAuth } from "./src/middlewares/socket/socketAuth.middleware.js";
import { findSocketAuthInfo } from "./src/middlewares/socket/findSocketAuthInfo.middleware.js";
import { socketProfile } from "./src/middlewares/socket/socketProfile.middleware.js";
let io;
export const initSocket = server => {
io = new Server(server, {
cors: { origin: "*", methods: ["GET", "POST"] }
});
const chatIO = io.of("/chat");
const callIO = io.of("/call");
chatIO.use(socketAuth);
chatIO.use(findSocketAuthInfo);
chatIO.use(socketProfile);
callIO.use(socketAuth);
callIO.use(findSocketAuthInfo);
callIO.use(socketProfile);
return { io, chatIO, callIO };
};
export const getIO = () => {
if (!io) throw new Error("Socket.io not initialized");
return io;
};