You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
650 B
26 lines
650 B
import * as WebSocket from "ws"; |
|
|
|
import { ServerState } from "@server/state"; |
|
import { WebSocketConnection } from "./WebSocketConnection"; |
|
|
|
export class WebSocketApi { |
|
state: ServerState; |
|
clients: Set<WebSocketConnection> = new Set(); |
|
|
|
constructor(state: ServerState) { |
|
this.state = state; |
|
} |
|
|
|
listen(webSocketServer: WebSocket.Server) { |
|
webSocketServer.on("connection", this.handleConnection); |
|
} |
|
|
|
handleConnection = (socket: WebSocket) => { |
|
const client = new WebSocketConnection(this, socket); |
|
this.clients.add(client); |
|
}; |
|
|
|
removeClient(client: WebSocketConnection) { |
|
return this.clients.delete(client); |
|
} |
|
}
|
|
|