-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sio-client): do not send a packet on an expired connection (#5134)
When a laptop is suspended or a phone is locked, the timer that is used to check the liveness of the connection is paused and is not able to detect that the heartbeat has failed. Previously, emitting a message after resuming the page would lose the message. The status of the timer will now be checked before sending the message, so that it gets buffered and sent upon reconnection. Note: we could also have used the Page Visibility API or a custom setTimeout() method based on setInterval(), but this would not be as reliable as the current solution. Reference: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API Related: #5135
- Loading branch information
1 parent
7a23dde
commit 8adcfbf
Showing
4 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -440,16 +440,13 @@ export class Socket< | |
packet.id = id; | ||
} | ||
|
||
const isTransportWritable = | ||
this.io.engine && | ||
this.io.engine.transport && | ||
this.io.engine.transport.writable; | ||
const isTransportWritable = this.io.engine?.transport?.writable; | ||
const isConnected = this.connected && !this.io.engine?._hasPingExpired(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
darrachequesne
Member
|
||
|
||
const discardPacket = | ||
this.flags.volatile && (!isTransportWritable || !this.connected); | ||
const discardPacket = this.flags.volatile && !isTransportWritable; | ||
if (discardPacket) { | ||
debug("discard packet as the transport is not currently writable"); | ||
} else if (this.connected) { | ||
} else if (isConnected) { | ||
this.notifyOutgoingListeners(packet); | ||
this.packet(packet); | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@darrachequesne
is a bit safer in case there's a version mismatch and it's an older engine without the fn?