Skip to content

Improve reconnect logic for websocket - #406

Merged
cloudwebrtc merged 42 commits into
mainfrom
improve-reconnect-logic-for-websocket
Dec 21, 2023
Merged

cloudwebrtc merged 42 commits into
mainfrom
improve-reconnect-logic-for-websocket

Conversation

@cloudwebrtc

@cloudwebrtc cloudwebrtc commented Nov 23, 2023

Copy link
Copy Markdown
Contributor
  • Added example of manual subscription, but will separate it to another PR later
    Tested platforms
  • macOS
  • Windows
  • Android
  • iOS
  • Web

@cloudwebrtc
cloudwebrtc force-pushed the improve-reconnect-logic-for-websocket branch from 9f933f6 to 005950e Compare November 24, 2023 13:08
@cloudwebrtc
cloudwebrtc force-pushed the improve-reconnect-logic-for-websocket branch from 35faaa1 to 0488642 Compare November 27, 2023 09:50
@cloudwebrtc
cloudwebrtc force-pushed the improve-reconnect-logic-for-websocket branch from 6056aac to 242919a Compare December 18, 2023 13:08
@cloudwebrtc
cloudwebrtc force-pushed the improve-reconnect-logic-for-websocket branch from 242919a to 763cf0b Compare December 18, 2023 13:11
@cloudwebrtc
cloudwebrtc force-pushed the improve-reconnect-logic-for-websocket branch from a63f0ac to 295a318 Compare December 18, 2023 13:38
@cloudwebrtc
cloudwebrtc merged commit 0fcc341 into main Dec 21, 2023
@cloudwebrtc
cloudwebrtc deleted the improve-reconnect-logic-for-websocket branch December 21, 2023 13:31
hiroshihorie added a commit that referenced this pull request Jul 7, 2026
## Summary

Follow-up to #1065. Ensures the SDK emits exactly one
`RoomDisconnectedEvent` per failed connection attempt.

Previously a failed initial connect produced two
`EngineDisconnectedEvent`s, and therefore two `RoomDisconnectedEvent`s
and two room cleanups:

1. The signal client emits
`SignalDisconnectedEvent(signalingConnectionFailure)` while `connect()`
is failing (the validate path has done this since #406, and the
certificate pinning path in #1065 follows the same pattern), which the
engine relayed as `EngineDisconnectedEvent`.
2. `Engine.connect`'s catch then emits
`EngineDisconnectedEvent(joinFailure)` for the same failure.

## Changes

- `Engine.connect`'s catch is now the single emitter for initial connect
failures. It picks the reason by error type:
`signalingConnectionFailure` for `CertificatePinningException`,
`joinFailure` otherwise.
- The `signalingConnectionFailure` relay in the engine's signal listener
is removed (with a comment explaining why). During reconnects the
engine's reconnect handling already owns disconnect emission, so the
relay only ever produced duplicates. This also removes the
`_isReconnecting`/`_attemptingReconnect` guard that #1065 added to
suppress the relay during reconnects, since there is no longer anything
to suppress.
- `SignalDisconnectedEvent` at the signal level is unchanged, only the
engine-level relay is removed.

## Behavior change

Apps listening for `RoomDisconnectedEvent` now receive one event per
failed connect instead of two. The reasons are unchanged for the common
case (`joinFailure`); certificate pinning failures surface as
`signalingConnectionFailure`. Apps that specifically depended on
receiving both events for a single failure would see one.

## Testing

Added room-level tests through the mock e2e container asserting exactly
one `RoomDisconnectedEvent` per failed initial connect, for both a
certificate pinning failure (`signalingConnectionFailure`) and a generic
websocket failure (`joinFailure`). Both tests fail against the previous
code (two events observed) and pass with this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant