(code = 1000, reason = "")
| 56 | } |
| 57 | |
| 58 | close(code = 1000, reason = ""): void { |
| 59 | if (this.closed) return; |
| 60 | this.closed = true; |
| 61 | |
| 62 | const reasonBuf = Buffer.from(reason, "utf-8"); |
| 63 | const payload = Buffer.alloc(2 + reasonBuf.length); |
| 64 | payload.writeUInt16BE(code, 0); |
| 65 | reasonBuf.copy(payload, 2); |
| 66 | this.writeFrame(OP_CLOSE, payload); |
| 67 | |
| 68 | // Give the client a moment to receive the close frame before destroying. |
| 69 | // If writeFrame failed (socket already destroyed), this is a no-op. |
| 70 | setTimeout(() => { |
| 71 | if (!this.socket.destroyed) { |
| 72 | this.socket.destroy(); |
| 73 | } |
| 74 | // Emit close event for server-initiated closes so listeners |
| 75 | // (e.g. activeConnections.delete) always fire. |
| 76 | this.emit("close", code, reason); |
| 77 | }, 100); |
| 78 | } |
| 79 | |
| 80 | destroy(): void { |
| 81 | if (this.closed) return; |
nothing calls this directly
no test coverage detected