Add IStreamChatClient.SuspendConnectionAsync (non-permanent disconnect) - #226
Open
harlan wants to merge 1 commit into
Open
Add IStreamChatClient.SuspendConnectionAsync (non-permanent disconnect)#226harlan wants to merge 1 commit into
harlan wants to merge 1 commit into
Conversation
Adds a high-level way to close the websocket WITHOUT ending the user session, for callers that know the client is about to stop pumping Update() β an app being backgrounded. Messages are received on a background timer thread but only processed from Unity's main loop, so a stalled pump lets the receive queue fill with nothing draining it. The only high-level disconnect today is DisconnectUserAsync(), which calls DisconnectAsync(permanent: true) -> ReconnectScheduler.Stop(). That is one-way: _isStopped is never cleared and the scheduler exposes no restart, so a client disconnected that way never auto-recovers. The non-permanent variant existed only on InternalLowLevelClient, which is internal to the StreamChat.Core asmdef and so unreachable from a consumer assembly without an InternalsVisibleTo. So this is a pass-through to DisconnectAsync(permanent: false), which leaves the reconnect scheduler armed. Because the scheduler schedules against the Unity clock (frozen while the app is paused), the reconnect fires on the first frame after resume, re-hydrating missed events via the usual /sync catch-up. Purely additive β no existing behavior changes. It would fold away if the SDK ships its own Suspend()/Unsuspend(), which StreamChatLowLevelClient.DisconnectAsync already contemplates in a TODO.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a high-level way to close the websocket without ending the user session, for callers that know the client is about to stop pumping
Update()β typically an app being backgrounded.Why
Messages are received on a background timer thread but only handled from Unity's main loop. When the main loop stops, the receive queue fills with nothing draining it. A consumer that knows this is about to happen wants to close the socket deliberately and have it come back on resume.
The only high-level disconnect today is
DisconnectUserAsync(), which callsDisconnectAsync(permanent: true)βReconnectScheduler.Stop(). That is one-way:_isStoppedis never cleared and the scheduler exposes no restart, so a client disconnected that way never auto-recovers. The non-permanent variant already exists, but only onInternalLowLevelClient, which isinternalto theStreamChat.Coreasmdef and therefore unreachable from a consumer assembly without anInternalsVisibleTowe did not want to add.Change
A pass-through to
DisconnectAsync(permanent: false), which leaves the reconnect scheduler armed. Because the scheduler schedules against the Unity clock (frozen while the app is paused), the reconnect fires on the first frame after resume and re-hydrates missed events through the usual/synccatch-up.Purely additive β no existing behavior changes.
StreamChatClientis the only implementer ofIStreamChatClientin the repo.This would fold away if the SDK ships its own
Suspend()/Unsuspend(), whichStreamChatLowLevelClient.DisconnectAsyncalready contemplates in a TODO β if you'd rather build that instead, we're happy to drop this in favor of it.Testing
No test added: the behavior is a one-line delegation whose observable effect is the reconnect scheduler's internal state, which the current test setup has no seam for.