| 121 | } |
| 122 | |
| 123 | private onConnect(ws: WebSocket): void { |
| 124 | this.clients.add(ws); |
| 125 | this.send(ws, { |
| 126 | type: "trackerConfig", |
| 127 | config: this.upstream.getConfig().tracker, |
| 128 | }); |
| 129 | const state = this.loop.getState(); |
| 130 | if (state) this.send(ws, { type: "trackerState", state }); |
| 131 | |
| 132 | ws.on("message", (raw) => this.onMessage(raw.toString())); |
| 133 | ws.on("close", () => this.clients.delete(ws)); |
| 134 | ws.on("error", () => this.clients.delete(ws)); |
| 135 | } |
| 136 | |
| 137 | private onMessage(raw: string): void { |
| 138 | let msg: TrackerClientMessage; |