1
0
Fork 0
mirror of synced 2024-09-12 07:27:20 +12:00

Improve websocket types

This commit is contained in:
Andrew Kingston 2022-08-23 08:48:16 +01:00
parent 2961b0ed89
commit f0e158cc81
2 changed files with 7 additions and 10 deletions

View file

@ -14,7 +14,7 @@ export const initWebsocket = () => {
const tls = location.protocol === "https:"
const proto = tls ? "wss:" : "ws:"
const host = location.hostname
const port = location.port || (tls ? 433 : 80)
const port = location.port || (tls ? 443 : 80)
console.log(`${proto}//${host}:${port}`)
const socket = io(`${proto}//${host}:${port}`, {
path: "/socket/client",

View file

@ -1,20 +1,17 @@
import SocketIO from "socket.io"
import { Server } from "socket.io"
import http from "http"
export class Websocket {
socketIO: any
socketServer: Server
constructor(server: any, path: string) {
// @ts-ignore
this.socketIO = SocketIO(server, {
constructor(server: http.Server, path: string) {
this.socketServer = new Server(server, {
path,
cors: {
origin: "*",
},
})
}
// Emit an event to all sockets
emit(event: string, payload: any) {
this.socketIO.sockets.emit(event, payload)
this.socketServer.sockets.emit(event, payload)
}
}