fix(wk websocket): do not send messages to a closing websocket (#593)
This commit is contained in:
parent
5a67d780e5
commit
24f5f1f952
|
|
@ -283,7 +283,12 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport) {
|
||||||
}
|
}
|
||||||
socket = s;
|
socket = s;
|
||||||
s.on('message', message => transport.send(Buffer.from(message).toString()));
|
s.on('message', message => transport.send(Buffer.from(message).toString()));
|
||||||
transport.onmessage = message => s.send(message);
|
transport.onmessage = message => {
|
||||||
|
// We are not notified when socket starts closing, and sending messages to a closing
|
||||||
|
// socket throws an error.
|
||||||
|
if (s.readyState !== ws.CLOSING)
|
||||||
|
s.send(message);
|
||||||
|
};
|
||||||
s.on('close', () => {
|
s.on('close', () => {
|
||||||
socket = undefined;
|
socket = undefined;
|
||||||
transport.onmessage = undefined;
|
transport.onmessage = undefined;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue