-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.js
More file actions
40 lines (31 loc) · 1002 Bytes
/
Copy pathsocket.js
File metadata and controls
40 lines (31 loc) · 1002 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
33
34
35
36
37
38
39
40
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;
let authIO;
let chatIO;
let callIO;
export const initSocket = (server) => {
io = new Server(server, {
cors: { origin: "*", methods: ["GET", "POST"] },
});
authIO = io.of("/auth");
chatIO = io.of("/chat");
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, authIO };
};
export const getIO = () => {
if (!io) throw new Error("Socket.io not initialized");
return io;
};
export const getAuthIO = () => {
if (!authIO) throw new Error("Auth namespace not initialized");
return authIO;
};