(socket: WebSocket, request: IncomingMessage, ctx: KoaContext)
| 22 | } |
| 23 | |
| 24 | accept(socket: WebSocket, request: IncomingMessage, ctx: KoaContext) { |
| 25 | const match = this.regexp.exec(new URL(request.url, `http://${request.headers.host}`).pathname); |
| 26 | if (!match) return false; |
| 27 | ctx.params ||= {}; |
| 28 | for (let i = 0; i < this.keys.length; i++) { |
| 29 | ctx.params[this.keys[i].name] = match[i + 1]; |
| 30 | ctx.HydroContext.args[this.keys[i].name] = match[i + 1]; |
| 31 | } |
| 32 | this.clients.add(socket); |
| 33 | socket.on('close', () => { |
| 34 | this.clients.delete(socket); |
| 35 | }); |
| 36 | this.callback?.(socket, request, ctx); |
| 37 | return true; |
| 38 | } |
| 39 | |
| 40 | close() { |
| 41 | for (const socket of this.clients) { |
no test coverage detected