2022-08-23 09:48:16 +02:00
|
|
|
import { Server } from "socket.io"
|
|
|
|
import http from "http"
|
2022-08-22 19:24:34 +02:00
|
|
|
|
|
|
|
export class Websocket {
|
2022-08-23 09:48:16 +02:00
|
|
|
socketServer: Server
|
2022-08-22 19:24:34 +02:00
|
|
|
|
2022-08-23 09:48:16 +02:00
|
|
|
constructor(server: http.Server, path: string) {
|
|
|
|
this.socketServer = new Server(server, {
|
2022-08-22 19:24:34 +02:00
|
|
|
path,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit an event to all sockets
|
|
|
|
emit(event: string, payload: any) {
|
2022-08-23 09:48:16 +02:00
|
|
|
this.socketServer.sockets.emit(event, payload)
|
2022-08-22 19:24:34 +02:00
|
|
|
}
|
|
|
|
}
|