Add IStreamChatClient.SuspendConnectionAsync (non-permanent disconnect) - #226
Add IStreamChatClient.SuspendConnectionAsync (non-permanent disconnect)#226harlan 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.
|
Hey Harlan β thanks for your contribution. The diagnosis is right: DisconnectUserAsync is logout, and when Update() is about to stop you need a way to drop the socket without ending the session so the receive queue does not pile up. We went with a slightly different shape in the upcoming release rather than merging this as-is.
By default, the SDK now pauses the socket when the app goes to the background and resumes it when the app returns to the foreground, so you should not need to wire this yourself. If you want more control, set We are closing this PR in favor of #238. |
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.