* @see https://websockets.spec.whatwg.org/#feedback-from-the-protocol * @see https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.4
()
| 16198 | * @see https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.4 |
| 16199 | */ |
| 16200 | #onSocketClose() { |
| 16201 | const wasClean = this.#handler.closeState.has(sentCloseFrameState.SENT) && this.#handler.closeState.has(sentCloseFrameState.RECEIVED); |
| 16202 | let code = 1005; |
| 16203 | let reason = ""; |
| 16204 | const result = this.#parser?.closingInfo; |
| 16205 | if (result && !result.error) { |
| 16206 | code = result.code ?? 1005; |
| 16207 | reason = result.reason; |
| 16208 | } |
| 16209 | this.#handler.readyState = states.CLOSED; |
| 16210 | if (!this.#handler.closeState.has(sentCloseFrameState.RECEIVED)) { |
| 16211 | code = 1006; |
| 16212 | fireEvent("error", this, (type, init) => new ErrorEvent2(type, init), { |
| 16213 | error: new TypeError(reason) |
| 16214 | }); |
| 16215 | } |
| 16216 | fireEvent("close", this, (type, init) => new CloseEvent2(type, init), { |
| 16217 | wasClean, |
| 16218 | code, |
| 16219 | reason |
| 16220 | }); |
| 16221 | if (channels.close.hasSubscribers) { |
| 16222 | channels.close.publish({ |
| 16223 | websocket: this, |
| 16224 | code, |
| 16225 | reason |
| 16226 | }); |
| 16227 | } |
| 16228 | } |
| 16229 | /** |
| 16230 | * @param {WebSocket} ws |
| 16231 | * @param {Buffer|undefined} buffer |
no test coverage detected