(code = 1000, reason = '')
| 124 | } |
| 125 | |
| 126 | public close(code = 1000, reason = ''): void { |
| 127 | if (this.closed) {return;} |
| 128 | this.closed = true; |
| 129 | try { |
| 130 | const reasonBuf = Buffer.from(reason, 'utf8'); |
| 131 | const payload = Buffer.allocUnsafe(2 + reasonBuf.length); |
| 132 | payload.writeUInt16BE(code, 0); |
| 133 | reasonBuf.copy(payload, 2); |
| 134 | this.socket.write(encodeFrame(0x8, payload)); |
| 135 | } catch { |
| 136 | // ignore |
| 137 | } finally { |
| 138 | this.emitCloseOnce(); |
| 139 | this.socket.end(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | private emitCloseOnce(): void { |
| 144 | if (this.closeEmitted) {return;} |
no test coverage detected