Improve websocket types
This commit is contained in:
parent
2961b0ed89
commit
f0e158cc81
|
@ -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",
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue