mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
migrated socket IO initialization to typescript
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
let io;
|
||||
|
||||
module.exports = {
|
||||
init: httpServer => {
|
||||
io = require("socket.io")(httpServer);
|
||||
return io;
|
||||
},
|
||||
getIO: () => {
|
||||
if (!io) {
|
||||
throw new Error("Socket IO not initialized");
|
||||
}
|
||||
return io;
|
||||
},
|
||||
};
|
||||
15
backend/src/libs/socket.ts
Normal file
15
backend/src/libs/socket.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import socketIo, { Server as SocketIO } from "socket.io";
|
||||
import { Server } from "http";
|
||||
|
||||
let io: SocketIO;
|
||||
|
||||
export const initIO = (httpServer: Server): SocketIO => {
|
||||
io = socketIo(httpServer);
|
||||
return io;
|
||||
};
|
||||
export const getIO = (): SocketIO => {
|
||||
if (!io) {
|
||||
throw new Error("Socket IO not initialized");
|
||||
}
|
||||
return io;
|
||||
};
|
||||
Reference in New Issue
Block a user