1
0
Fork 0
mirror of synced 2024-06-28 02:50:50 +12:00
budibase/packages/server/src/websocket.ts

18 lines
358 B
TypeScript
Raw Normal View History

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