* Decompress a compressed payload. * @param {Buffer} chunk Compressed data * @param {boolean} fin Final fragment flag * @param {Function} callback Callback function
(chunk, fin, callback)
| 17715 | ws[kReadyState] = states.CLOSING; |
| 17716 | } |
| 17717 | } |
| 17718 | function onSocketData(chunk) { |
| 17719 | if (!this.ws[kByteParser].write(chunk)) { |
| 17720 | this.pause(); |
| 17721 | } |
| 17722 | } |
| 17723 | function onSocketClose() { |
| 17724 | var _a; |
| 17725 | const { ws } = this; |
| 17726 | const { [kResponse]: response } = ws; |
| 17727 | response.socket.off("data", onSocketData); |
| 17728 | response.socket.off("close", onSocketClose); |
| 17729 | response.socket.off("error", onSocketError); |
| 17730 | const wasClean = ws[kSentClose] === sentCloseFrameState.SENT && ws[kReceivedClose]; |
| 17731 | let code = 1005; |
| 17732 | let reason = ""; |
| 17733 | const result = ws[kByteParser].closingInfo; |
| 17734 | if (result && !result.error) { |
| 17735 | code = (_a = result.code) != null ? _a : 1005; |
| 17736 | reason = result.reason; |
| 17737 | } else if (!ws[kReceivedClose]) { |
| 17738 | code = 1006; |
| 17739 | } |
| 17740 | ws[kReadyState] = states.CLOSED; |
| 17741 | fireEvent("close", ws, (type, init) => new CloseEvent(type, init), { |
| 17742 | wasClean, |
| 17743 | code, |
| 17744 | reason |
| 17745 | }); |
| 17746 | if (channels.close.hasSubscribers) { |
| 17747 | channels.close.publish({ |
| 17748 | websocket: ws, |
| 17749 | code, |
| 17750 | reason |
| 17751 | }); |
| 17752 | } |
| 17753 | } |
| 17754 | function onSocketError(error) { |
| 17755 | const { ws } = this; |
| 17756 | ws[kReadyState] = states.CLOSING; |
| 17757 | if (channels.socketError.hasSubscribers) { |
| 17758 | channels.socketError.publish(error); |
| 17759 | } |
| 17760 | this.destroy(); |
| 17761 | } |
| 17762 | module.exports = { |
| 17763 | establishWebSocketConnection, |
| 17764 | closeWebSocketConnection |
| 17765 | }; |
| 17766 | } |
no test coverage detected