Files
whaticket-community/backend/src/libs/socket.ts
2020-09-20 10:52:05 -03:00

17 lines
380 B
TypeScript

import socketIo, { Server as SocketIO } from "socket.io";
import { Server } from "http";
import AppError from "../errors/AppError";
let io: SocketIO;
export const initIO = (httpServer: Server): SocketIO => {
io = socketIo(httpServer);
return io;
};
export const getIO = (): SocketIO => {
if (!io) {
throw new AppError("Socket IO not initialized");
}
return io;
};