* Decompress a compressed payload. * @param {Buffer} chunk Compressed data * @param {boolean} fin Final fragment flag * @param {Function} callback Callback function
(chunk, fin, callback)
| 17715 | } else if (!isEstablished(ws)) { |
| 17716 | failWebsocketConnection(ws, "Connection was closed before it was established."); |
| 17717 | ws[kReadyState] = states.CLOSING; |
| 17718 | } else if (ws[kSentClose] === sentCloseFrameState.NOT_SENT) { |
| 17719 | ws[kSentClose] = sentCloseFrameState.PROCESSING; |
| 17720 | const frame = new WebsocketFrameSend(); |
| 17721 | if (code !== void 0 && reason === void 0) { |
| 17722 | frame.frameData = Buffer.allocUnsafe(2); |
| 17723 | frame.frameData.writeUInt16BE(code, 0); |
| 17724 | } else if (code !== void 0 && reason !== void 0) { |
| 17725 | frame.frameData = Buffer.allocUnsafe(2 + reasonByteLength); |
| 17726 | frame.frameData.writeUInt16BE(code, 0); |
| 17727 | frame.frameData.write(reason, 2, "utf-8"); |
| 17728 | } else { |
| 17729 | frame.frameData = emptyBuffer; |
| 17730 | } |
| 17731 | const socket = ws[kResponse].socket; |
| 17732 | socket.write(frame.createFrame(opcodes.CLOSE)); |
| 17733 | ws[kSentClose] = sentCloseFrameState.SENT; |
| 17734 | ws[kReadyState] = states.CLOSING; |
| 17735 | } else { |
| 17736 | ws[kReadyState] = states.CLOSING; |
| 17737 | } |
| 17738 | } |
| 17739 | function onSocketData(chunk) { |
| 17740 | if (!this.ws[kByteParser].write(chunk)) { |
| 17741 | this.pause(); |
| 17742 | } |
| 17743 | } |
| 17744 | function onSocketClose() { |
| 17745 | var _a; |
| 17746 | const { ws } = this; |
| 17747 | const { [kResponse]: response } = ws; |
| 17748 | response.socket.off("data", onSocketData); |
| 17749 | response.socket.off("close", onSocketClose); |
| 17750 | response.socket.off("error", onSocketError); |
| 17751 | const wasClean = ws[kSentClose] === sentCloseFrameState.SENT && ws[kReceivedClose]; |
| 17752 | let code = 1005; |
| 17753 | let reason = ""; |
| 17754 | const result = ws[kByteParser].closingInfo; |
| 17755 | if (result && !result.error) { |
| 17756 | code = (_a = result.code) != null ? _a : 1005; |
| 17757 | reason = result.reason; |
| 17758 | } else if (!ws[kReceivedClose]) { |
| 17759 | code = 1006; |
| 17760 | } |
| 17761 | ws[kReadyState] = states.CLOSED; |
| 17762 | fireEvent("close", ws, (type, init) => new CloseEvent(type, init), { |
| 17763 | wasClean, |
| 17764 | code, |
| 17765 | reason |
| 17766 | }); |
no test coverage detected