* Runs whenever a new chunk is received. * Callback is called whenever there are no more chunks buffering, * or not enough bytes are buffered to parse.
(callback)
| 17844 | ws[kSentClose] = sentCloseFrameState.SENT; |
| 17845 | ws[kReadyState] = states.CLOSING; |
| 17846 | } else { |
| 17847 | ws[kReadyState] = states.CLOSING; |
| 17848 | } |
| 17849 | } |
| 17850 | function onSocketData(chunk) { |
| 17851 | if (!this.ws[kByteParser].write(chunk)) { |
| 17852 | this.pause(); |
| 17853 | } |
| 17854 | } |
| 17855 | function onSocketClose() { |
| 17856 | var _a; |
| 17857 | const { ws } = this; |
| 17858 | const { [kResponse]: response } = ws; |
| 17859 | response.socket.off("data", onSocketData); |
| 17860 | response.socket.off("close", onSocketClose); |
| 17861 | response.socket.off("error", onSocketError); |
| 17862 | const wasClean = ws[kSentClose] === sentCloseFrameState.SENT && ws[kReceivedClose]; |
| 17863 | let code = 1005; |
| 17864 | let reason = ""; |
| 17865 | const result = ws[kByteParser].closingInfo; |
| 17866 | if (result && !result.error) { |
| 17867 | code = (_a = result.code) != null ? _a : 1005; |
| 17868 | reason = result.reason; |
| 17869 | } else if (!ws[kReceivedClose]) { |
| 17870 | code = 1006; |
| 17871 | } |
| 17872 | ws[kReadyState] = states.CLOSED; |
| 17873 | fireEvent("close", ws, (type, init) => new CloseEvent(type, init), { |
| 17874 | wasClean, |
| 17875 | code, |
| 17876 | reason |
| 17877 | }); |
| 17878 | if (channels.close.hasSubscribers) { |
| 17879 | channels.close.publish({ |
| 17880 | websocket: ws, |
| 17881 | code, |
| 17882 | reason |
| 17883 | }); |
| 17884 | } |
| 17885 | } |
| 17886 | function onSocketError(error) { |
| 17887 | const { ws } = this; |
| 17888 | ws[kReadyState] = states.CLOSING; |
| 17889 | if (channels.socketError.hasSubscribers) { |
| 17890 | channels.socketError.publish(error); |
| 17891 | } |
| 17892 | this.destroy(); |
| 17893 | } |
| 17894 | module.exports = { |
| 17895 | establishWebSocketConnection, |
| 17896 | closeWebSocketConnection |
| 17897 | }; |
| 17898 | } |
| 17899 | }); |
| 17900 | |
| 17901 | // |
| 17902 | var require_permessage_deflate = __commonJS({ |
| 17903 | ""(exports, module) { |
no test coverage detected