stream-chat 10.0.0-rc.21 → 10.0.0-rc.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.browser.js +2196 -3902
- package/dist/cjs/index.browser.js.map +3 -3
- package/dist/cjs/index.node.js +2197 -3902
- package/dist/cjs/index.node.js.map +3 -3
- package/dist/esm/index.mjs +2199 -3905
- package/dist/esm/index.mjs.map +4 -4
- package/dist/types/ChannelManager.d.ts +120 -233
- package/dist/types/CooldownTimer.d.ts +8 -23
- package/dist/types/EventHandlerPipeline.d.ts +17 -37
- package/dist/types/LiveLocationManager.d.ts +22 -50
- package/dist/types/api-client.d.ts +9 -14
- package/dist/types/channel.d.ts +253 -448
- package/dist/types/channel_state.d.ts +48 -95
- package/dist/types/client.d.ts +245 -370
- package/dist/types/client_state.d.ts +1 -3
- package/dist/types/configuration/ConfigController.d.ts +30 -124
- package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
- package/dist/types/configuration/keys.d.ts +5 -19
- package/dist/types/configuration/shape.d.ts +12 -29
- package/dist/types/configuration/types.d.ts +59 -87
- package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
- package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
- package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
- package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
- package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
- package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
- package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
- package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
- package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
- package/dist/types/connection/networkConnection/types.d.ts +12 -27
- package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
- package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
- package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
- package/dist/types/connection/wsConnection/config.d.ts +8 -28
- package/dist/types/connection/wsConnection/types.d.ts +17 -70
- package/dist/types/entityStore/EntityStore.d.ts +153 -113
- package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
- package/dist/types/errors.d.ts +7 -19
- package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
- package/dist/types/gen/chat/ChatApi.d.ts +28 -14
- package/dist/types/gen/models/index.d.ts +769 -86
- package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
- package/dist/types/index.d.ts +2 -4
- package/dist/types/languageNames.d.ts +9 -24
- package/dist/types/logger.d.ts +1 -3
- package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
- package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
- package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
- package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
- package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
- package/dist/types/messageComposer/configuration/types.d.ts +29 -56
- package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
- package/dist/types/messageComposer/messageComposer.d.ts +30 -164
- package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
- package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
- package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
- package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
- package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
- package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
- package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
- package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
- package/dist/types/messageComposer/pollComposer.d.ts +8 -4
- package/dist/types/messageComposer/textComposer.d.ts +3 -9
- package/dist/types/messageComposer/types.d.ts +5 -8
- package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
- package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
- package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
- package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
- package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
- package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
- package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
- package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
- package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
- package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
- package/dist/types/messageOperations/types.d.ts +15 -30
- package/dist/types/middleware.d.ts +7 -5
- package/dist/types/moderation.d.ts +21 -14
- package/dist/types/notifications/NotificationManager.d.ts +8 -31
- package/dist/types/notifications/types.d.ts +19 -59
- package/dist/types/offline-support/offline_support_api.d.ts +145 -539
- package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
- package/dist/types/offline-support/queueableOperations.d.ts +24 -52
- package/dist/types/offline-support/types.d.ts +24 -187
- package/dist/types/pagination/ItemIndex.d.ts +4 -12
- package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
- package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
- package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
- package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
- package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
- package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
- package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
- package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
- package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
- package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
- package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
- package/dist/types/pagination/sortCompiler.d.ts +11 -22
- package/dist/types/pagination/utility.normalization.d.ts +5 -23
- package/dist/types/pagination/utility.search.d.ts +3 -8
- package/dist/types/poll.d.ts +14 -14
- package/dist/types/poll_manager.d.ts +11 -2
- package/dist/types/poll_optimistic_votes.d.ts +10 -14
- package/dist/types/reminders/Reminder.d.ts +4 -4
- package/dist/types/reminders/ReminderManager.d.ts +7 -20
- package/dist/types/search/BaseSearchSource.d.ts +7 -12
- package/dist/types/search/ChannelSearchSource.d.ts +7 -7
- package/dist/types/search/MessageSearchSource.d.ts +7 -9
- package/dist/types/search/SearchController.d.ts +17 -22
- package/dist/types/search/types.d.ts +6 -10
- package/dist/types/signing.d.ts +12 -3
- package/dist/types/thread.d.ts +23 -71
- package/dist/types/thread_manager.d.ts +45 -70
- package/dist/types/token_manager.d.ts +8 -13
- package/dist/types/types.d.ts +64 -125
- package/dist/types/types.utility.d.ts +3 -3
- package/dist/types/upload-utils.d.ts +5 -10
- package/dist/types/uploadManager.d.ts +17 -45
- package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
- package/dist/types/utils/WithSubscriptions.d.ts +5 -15
- package/dist/types/utils/concurrency.d.ts +11 -19
- package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
- package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
- package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
- package/dist/types/utils/objectPath.d.ts +6 -41
- package/dist/types/utils/retryable.d.ts +8 -12
- package/dist/types/utils/throttling/throttle.d.ts +8 -23
- package/dist/types/utils/time.d.ts +24 -64
- package/dist/types/utils.d.ts +40 -86
- package/package.json +7 -2
- package/src/ChannelManager.ts +159 -300
- package/src/CooldownTimer.ts +11 -29
- package/src/EventHandlerPipeline.ts +21 -44
- package/src/LiveLocationManager.ts +35 -74
- package/src/api-client.ts +43 -61
- package/src/campaign.ts +1 -1
- package/src/channel.ts +396 -749
- package/src/channel_batch_updater.ts +1 -1
- package/src/channel_state.ts +50 -105
- package/src/client.ts +360 -588
- package/src/client_state.ts +1 -6
- package/src/configuration/ConfigController.ts +41 -157
- package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
- package/src/configuration/index.ts +1 -1
- package/src/configuration/keys.ts +13 -32
- package/src/configuration/shape.ts +67 -70
- package/src/configuration/types.ts +60 -100
- package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
- package/src/configuration/utils/copyConfigPatch.ts +11 -32
- package/src/configuration/utils/declarativeSlices.ts +9 -39
- package/src/configuration/utils/deepFreezeConfig.ts +3 -17
- package/src/configuration/utils/index.ts +2 -4
- package/src/configuration/utils/serverAuthority.ts +20 -68
- package/src/connection/ConnectionIdManager.ts +20 -49
- package/src/connection/ConnectionRecoveryManager.ts +51 -178
- package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
- package/src/connection/networkConnection/reporters.ts +9 -36
- package/src/connection/networkConnection/types.ts +12 -27
- package/src/connection/wsConnection/StableWSConnection.ts +73 -193
- package/src/connection/wsConnection/WSConnection.ts +56 -131
- package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
- package/src/connection/wsConnection/config.ts +13 -48
- package/src/connection/wsConnection/types.ts +17 -70
- package/src/constants.ts +4 -4
- package/src/entityStore/EntityStore.ts +162 -167
- package/src/entityStore/StoreBackedItemIndex.ts +14 -47
- package/src/errors.ts +7 -19
- package/src/formatMessageMemo.ts +3 -9
- package/src/gen/chat/ChannelApi.ts +19 -0
- package/src/gen/chat/ChatApi.ts +87 -13
- package/src/gen/models/index.ts +793 -71
- package/src/gen/moderation/ModerationApi.ts +0 -4
- package/src/index.ts +10 -14
- package/src/languageNames.ts +9 -24
- package/src/logger.ts +1 -3
- package/src/messageComposer/LocationComposer.ts +7 -23
- package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
- package/src/messageComposer/attachmentIdentity.ts +2 -13
- package/src/messageComposer/attachmentManager.ts +17 -63
- package/src/messageComposer/attachmentUtils.ts +3 -17
- package/src/messageComposer/configuration/configuration.ts +5 -8
- package/src/messageComposer/configuration/types.ts +29 -56
- package/src/messageComposer/fileUtils.ts +1 -1
- package/src/messageComposer/linkPreviewsManager.ts +8 -20
- package/src/messageComposer/messageComposer.ts +54 -222
- package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
- package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
- package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
- package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
- package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
- package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
- package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
- package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
- package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
- package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
- package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
- package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
- package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
- package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
- package/src/messageComposer/middleware/textComposer/types.ts +1 -6
- package/src/messageComposer/pollComposer.ts +11 -8
- package/src/messageComposer/textComposer.ts +9 -59
- package/src/messageComposer/types.ts +9 -12
- package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
- package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
- package/src/messageOperations/FailedSendCache.ts +4 -9
- package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
- package/src/messageOperations/MessageOperations.ts +33 -62
- package/src/messageOperations/applyReactionLocally.ts +9 -28
- package/src/messageOperations/createMessageOperations.ts +17 -33
- package/src/messageOperations/reflectReactionEvent.ts +5 -13
- package/src/messageOperations/sendOrdering.ts +4 -7
- package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
- package/src/messageOperations/types.ts +15 -30
- package/src/middleware.ts +7 -10
- package/src/moderation.ts +25 -21
- package/src/notifications/NotificationManager.ts +11 -35
- package/src/notifications/types.ts +19 -59
- package/src/offline-support/offline_support_api.ts +178 -608
- package/src/offline-support/offline_sync_manager.ts +25 -69
- package/src/offline-support/queueableOperations.ts +31 -84
- package/src/offline-support/types.ts +25 -188
- package/src/pagination/ItemIndex.ts +4 -12
- package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
- package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
- package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
- package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
- package/src/pagination/filterCompiler.ts +11 -25
- package/src/pagination/paginators/BasePaginator.ts +422 -976
- package/src/pagination/paginators/ChannelPaginator.ts +130 -190
- package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
- package/src/pagination/paginators/MessagePaginator.ts +135 -175
- package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
- package/src/pagination/paginators/ReminderPaginator.ts +12 -15
- package/src/pagination/paginators/ThreadPaginator.ts +16 -26
- package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
- package/src/pagination/paginators/stateThrottling.ts +5 -10
- package/src/pagination/sortCompiler.ts +23 -50
- package/src/pagination/utility.normalization.ts +8 -30
- package/src/pagination/utility.search.ts +4 -11
- package/src/poll.ts +19 -19
- package/src/poll_manager.ts +16 -20
- package/src/poll_optimistic_votes.ts +17 -22
- package/src/reminders/Reminder.ts +5 -6
- package/src/reminders/ReminderManager.ts +9 -34
- package/src/reminders/ReminderTimer.ts +1 -2
- package/src/search/BaseSearchSource.ts +14 -29
- package/src/search/ChannelSearchSource.ts +8 -8
- package/src/search/MessageSearchSource.ts +19 -25
- package/src/search/SearchController.ts +18 -24
- package/src/search/types.ts +6 -10
- package/src/segment.ts +1 -1
- package/src/signing.ts +23 -3
- package/src/thread.ts +72 -173
- package/src/thread_manager.ts +59 -76
- package/src/token_manager.ts +11 -21
- package/src/types.ts +78 -126
- package/src/types.utility.ts +3 -3
- package/src/upload-utils.ts +5 -10
- package/src/uploadManager.ts +22 -54
- package/src/utils/FixedSizeQueueCache.ts +13 -21
- package/src/utils/WithSubscriptions.ts +5 -15
- package/src/utils/concurrency.ts +16 -55
- package/src/utils/mergeWith/mergeWith.ts +10 -13
- package/src/utils/mergeWith/mergeWithCore.ts +24 -81
- package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
- package/src/utils/objectPath.ts +6 -41
- package/src/utils/retryable.ts +10 -14
- package/src/utils/throttling/throttle.ts +9 -25
- package/src/utils/time.ts +26 -66
- package/src/utils.ts +72 -128
|
@@ -11,13 +11,7 @@ import type { StateStore, Unsubscribe } from '@stream-io/state-store';
|
|
|
11
11
|
const logger = chatLoggerSystem.getLogger('client');
|
|
12
12
|
|
|
13
13
|
export type ConnectionRecoveryManagerConfig = {
|
|
14
|
-
/**
|
|
15
|
-
* Whether the client recovers its own state when the connection comes back.
|
|
16
|
-
*
|
|
17
|
-
* Set it to `false` only if the application recovers state itself — nothing is then re-queried or
|
|
18
|
-
* re-watched on reconnect, and refreshing whatever is on screen becomes the consumer's job.
|
|
19
|
-
* Read when a recovery actually runs, so flipping it takes effect from the next reconnect.
|
|
20
|
-
*/
|
|
14
|
+
/** Whether the client recovers its own state on reconnect. Set `false` if the app does it itself. */
|
|
21
15
|
enabled: boolean;
|
|
22
16
|
};
|
|
23
17
|
|
|
@@ -25,77 +19,24 @@ export const DEFAULT_CONNECTION_RECOVERY_MANAGER_CONFIG: ConnectionRecoveryManag
|
|
|
25
19
|
deepFreezeConfig({ enabled: true });
|
|
26
20
|
|
|
27
21
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* 1. **Every loaded channel list re-runs its own first-page query** (`ChannelManager.recover`). Since
|
|
34
|
-
* `queryChannels` watches by default, that also re-establishes the watches for the channels on
|
|
35
|
-
* that page.
|
|
36
|
-
* 2. **Every active channel reloads itself** (`Channel.reload`), because a list page carries far fewer
|
|
37
|
-
* messages per channel than an open channel's loaded window, so the open channel cannot be served
|
|
38
|
-
* by the list query.
|
|
39
|
-
* 3. **Every active thread reloads its replies** (`Thread.reload`), because none of the above touches
|
|
40
|
-
* them: a channel reload refreshes the main message list, and `ThreadManager`'s own recovery
|
|
41
|
-
* refreshes the thread *list*, reusing thread instances without rehydrating them unless something
|
|
42
|
-
* separately marked them stale.
|
|
43
|
-
*
|
|
44
|
-
* It is explicitly **not** a sweep over the channel store (`client.channelManager.values()`). Watches
|
|
45
|
-
* are a bounded server resource, and after any scrolling that store holds far more channels than a query returns — so
|
|
46
|
-
* re-watching all of them would be both wasteful and a watch-limit hazard. Channels outside the
|
|
47
|
-
* refreshed pages come back demand-driven, when an event proves them relevant (see
|
|
48
|
-
* `restoreInterruptedWatch` in `ChannelManager`).
|
|
49
|
-
*
|
|
50
|
-
* This replaces the removed `client.recoverState()` bulk query
|
|
51
|
-
* (`cid: { $in: <every loaded channel> }, limit: 30`), which invented its own query shape unrelated to any
|
|
52
|
-
* list's filters and silently dropped everything past the thirtieth channel.
|
|
53
|
-
*
|
|
54
|
-
* ### Triggers, and why there are two
|
|
22
|
+
* After a reconnect, brings what the app is consuming back in line with the server:
|
|
23
|
+
* 1. loaded channel lists re-run their first-page query (`ChannelManager.recover`), re-watching it;
|
|
24
|
+
* 2. active channels reload (`Channel.reload`);
|
|
25
|
+
* 3. active threads reload their replies (`Thread.reload`).
|
|
55
26
|
*
|
|
56
|
-
*
|
|
27
|
+
* It does not sweep the channel store (watches are a bounded server resource). Other channels recover
|
|
28
|
+
* on demand, when an event proves them relevant.
|
|
57
29
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* offline sync.
|
|
61
|
-
* - **Active channels** — the offline DB's *sync-status edge* when offline support is enabled, and
|
|
62
|
-
* that same store otherwise. `Channel.reload()` has no deferral of its own, so it has to be
|
|
63
|
-
* triggered by something that is already post-sync.
|
|
64
|
-
*
|
|
65
|
-
* The edge is what guarantees `executePendingTasks()` → `sync()` → query ordering, on every reconnect
|
|
66
|
-
* path: `OfflineDBSyncManager` calls `invokeSyncStatusListeners(true)` **unconditionally** after
|
|
67
|
-
* `syncAndExecutePendingTasks()` on each online transition — it does not require `isSynced` to have
|
|
68
|
-
* been `false` first. That matters because the sync edge, unlike anything derived from a single
|
|
69
|
-
* transition, is guaranteed to land after the replay and the sync rather than alongside them.
|
|
70
|
-
*
|
|
71
|
-
* Recovery deliberately keeps no "did we drop?" flag of its own: `ChannelWatchStatus.WasWatching`
|
|
72
|
-
* already records exactly that, written from the truthful hooks
|
|
73
|
-
* (`StableWSConnection._setHealth(false)` and `closeConnection()`, plus
|
|
74
|
-
* `WSConnectionFallback._setState()` after an `enableWSFallback` switch).
|
|
75
|
-
*
|
|
76
|
-
* The status store it follows is the long-poll's once `enableWSFallback` has switched to it, so a
|
|
77
|
-
* long-poll reconnect recovers the same way a WebSocket reconnect does.
|
|
30
|
+
* Lists recover when the socket goes online. Active channels recover on the offline DB's sync-status
|
|
31
|
+
* edge when offline support is on (it lands after pending tasks replay), else on the same socket status.
|
|
78
32
|
*/
|
|
79
33
|
export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
80
34
|
client: StreamChat;
|
|
81
|
-
/** The shared configuration machinery — see {@link ConfigController}. */
|
|
82
35
|
private readonly configController: ConfigController<ConnectionRecoveryManagerConfig>;
|
|
83
36
|
/** Set while a pass over the active channels and threads is in flight. */
|
|
84
37
|
private isRecovering = false;
|
|
85
|
-
/**
|
|
86
|
-
* A reconnect that arrived while a pass was already running, so the pass re-runs when it finishes.
|
|
87
|
-
*
|
|
88
|
-
* A second pass cannot start alongside the first: they would reload every active channel twice and
|
|
89
|
-
* race on {@link isRecovering}, the earlier one clearing it while the later is still going. Nor can
|
|
90
|
-
* the reconnect simply be dropped — the running pass will withhold its `connection.recovered`
|
|
91
|
-
* precisely because the socket moved under it, so nothing else would bring the newer connection's
|
|
92
|
-
* state back in line.
|
|
93
|
-
*
|
|
94
|
-
* Re-entry is not hypothetical. The trigger is a subscription to the socket's status store, and a
|
|
95
|
-
* reload that moves that status calls straight back into here before the first `await`.
|
|
96
|
-
*/
|
|
38
|
+
/** A reconnect that arrived mid-pass: re-run once when the pass finishes, not concurrently. */
|
|
97
39
|
private recoveryRequestedAgain = false;
|
|
98
|
-
/** Undone by `unregisterSubscriptions`, so re-registering does not stack listeners. */
|
|
99
40
|
private unsubscribeSyncStatus?: Unsubscribe;
|
|
100
41
|
|
|
101
42
|
constructor({ client }: { client: StreamChat }) {
|
|
@@ -106,28 +47,27 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
106
47
|
this.client = client;
|
|
107
48
|
}
|
|
108
49
|
|
|
109
|
-
/**
|
|
110
|
-
* Resolved configuration, as a store — the shape every configurable class exposes
|
|
111
|
-
* (`configState` / `config` / `updateConfig`).
|
|
112
|
-
*/
|
|
113
50
|
get configState(): StateStore<ConnectionRecoveryManagerConfig> {
|
|
114
51
|
return this.configController.state;
|
|
115
52
|
}
|
|
116
53
|
|
|
117
|
-
/** The current resolved configuration. `Readonly` — change it through {@link updateConfig}. */
|
|
118
54
|
public get config(): Readonly<ConnectionRecoveryManagerConfig> {
|
|
119
55
|
return this.configState.getLatestValue();
|
|
120
56
|
}
|
|
121
57
|
|
|
122
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Merges a partial configuration into the resolved config.
|
|
60
|
+
*
|
|
61
|
+
* @param config - Fields to merge into the resolved config.
|
|
62
|
+
*/
|
|
123
63
|
public updateConfig(config: Partial<ConnectionRecoveryManagerConfig>) {
|
|
124
64
|
this.configController.patch(config);
|
|
125
65
|
}
|
|
126
66
|
|
|
127
67
|
/**
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
68
|
+
* Re-derives the configuration from the declarative slice.
|
|
69
|
+
*
|
|
70
|
+
* @param config - The declarative slice. Leave it out to rebuild from the defaults.
|
|
131
71
|
*/
|
|
132
72
|
public initializeConfig(config?: Partial<ConnectionRecoveryManagerConfig>) {
|
|
133
73
|
this.configController.initialize(config);
|
|
@@ -135,37 +75,29 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
135
75
|
|
|
136
76
|
public registerSubscriptions = () => {
|
|
137
77
|
if (!this.hasSubscriptions) {
|
|
138
|
-
// Driven by the socket
|
|
139
|
-
//
|
|
140
|
-
// is written on every transition, including the deliberate close and the two error paths that
|
|
141
|
-
// were always silent. The device's network is a separate signal that cannot start a recovery,
|
|
142
|
-
// because a device regaining a network has no reconnected socket and no fresh connection ID yet,
|
|
143
|
-
// so a query fired then would establish no watch.
|
|
78
|
+
// Driven by the socket status alone, which records every transition. A regained device network
|
|
79
|
+
// cannot start a recovery: there is no connection ID to watch with yet.
|
|
144
80
|
let wasHealthy: boolean | undefined;
|
|
145
81
|
this.addUnsubscribeFunction(
|
|
146
82
|
this.client.wsConnection.state.subscribeWithSelector(
|
|
147
83
|
({ isHealthy, lastUnhealthyAt }) => ({ isHealthy, lastUnhealthyAt }),
|
|
148
84
|
({ isHealthy, lastUnhealthyAt }) => {
|
|
149
|
-
// The immediate first call is the current status
|
|
150
|
-
// would re-query on nothing more than someone registering subscriptions.
|
|
85
|
+
// The immediate first call is the current status, not a change.
|
|
151
86
|
const previous = wasHealthy;
|
|
152
87
|
wasHealthy = isHealthy;
|
|
153
88
|
if (previous === undefined || !isHealthy) return;
|
|
154
89
|
|
|
155
|
-
// A first connect is not a recovery
|
|
156
|
-
//
|
|
157
|
-
// the deliberate `closeConnection()` that mobile backgrounding uses, so every real
|
|
158
|
-
// reconnect still qualifies.
|
|
90
|
+
// A first connect is not a recovery (`lastUnhealthyAt` is set by every drop, including
|
|
91
|
+
// `closeConnection()`).
|
|
159
92
|
if (!lastUnhealthyAt) return;
|
|
160
93
|
|
|
161
|
-
|
|
94
|
+
if (!this.config.enabled) return;
|
|
95
|
+
|
|
96
|
+
// Lists always recover here; their own deferral handles offline ordering.
|
|
162
97
|
runDetached(this.recoverChannelLists(), { context: 'recoverChannelLists' });
|
|
163
98
|
|
|
164
|
-
// Active channels recover off the
|
|
165
|
-
//
|
|
166
|
-
// runs per reconnect: binding the subscription is what makes the edge the driver, so the
|
|
167
|
-
// same call reports which path applies. Deliberately not split into a separate predicate
|
|
168
|
-
// — two independent reads of "is there an edge?" could disagree with each other.
|
|
99
|
+
// Active channels recover off the sync-status edge when there is one (the only signal that
|
|
100
|
+
// lands after replay and sync), else here. Exactly one path runs per reconnect.
|
|
169
101
|
const syncEdgeDrivesActiveChannels = this.ensureSyncStatusSubscription();
|
|
170
102
|
if (!syncEdgeDrivesActiveChannels) {
|
|
171
103
|
runDetached(this.recoverActiveChannels(), {
|
|
@@ -187,20 +119,10 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
187
119
|
};
|
|
188
120
|
|
|
189
121
|
/**
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* deferred rather than handed in. Doing it from the status handler is safe even when this manager's
|
|
195
|
-
* subscription runs before the sync manager's: `OfflineDBSyncManager` awaits
|
|
196
|
-
* `syncAndExecutePendingTasks()` before publishing, so the edge cannot land in the same synchronous
|
|
197
|
-
* notification that registers us.
|
|
198
|
-
*
|
|
199
|
-
* An offline DB whose `init()` never succeeded publishes no edge, so it must not be treated as the
|
|
200
|
-
* trigger — hence the `initialized` check, which also means a later successful init is picked up on
|
|
201
|
-
* the next reconnect.
|
|
202
|
-
*
|
|
203
|
-
* @returns whether the sync-status edge is now driving active-channel recovery.
|
|
122
|
+
* Binds to the offline DB's sync-status edge once the DB is initialized (an uninitialized one
|
|
123
|
+
* publishes no edge). Safe from the status handler: the edge is published only after
|
|
124
|
+
* `syncAndExecutePendingTasks()` resolves. Returns whether the edge now drives active-channel
|
|
125
|
+
* recovery.
|
|
204
126
|
*/
|
|
205
127
|
private ensureSyncStatusSubscription = (): boolean => {
|
|
206
128
|
if (this.unsubscribeSyncStatus) return true;
|
|
@@ -209,8 +131,7 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
209
131
|
if (!offlineDb?.state.getLatestValue().initialized) return false;
|
|
210
132
|
|
|
211
133
|
const { unsubscribe } = offlineDb.syncManager.onSyncStatusChange((status) => {
|
|
212
|
-
|
|
213
|
-
if (!status) return;
|
|
134
|
+
if (!status || !this.config.enabled) return;
|
|
214
135
|
runDetached(this.recoverActiveChannels(), { context: 'recoverActiveChannels' });
|
|
215
136
|
});
|
|
216
137
|
this.unsubscribeSyncStatus = unsubscribe;
|
|
@@ -218,13 +139,8 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
218
139
|
};
|
|
219
140
|
|
|
220
141
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* Deliberately NOT filtered on `watchStatus`. A channel opened while offline never reached
|
|
224
|
-
* `Watching` at all (its `watch()` threw, leaving `offlineMode`), so a `WasWatching` filter here
|
|
225
|
-
* would permanently strand the single most important offline case. `Channel.reload()`'s own
|
|
226
|
-
* `initialized || offlineMode` guard is the correct gate, and this is not a "restore a lost watch"
|
|
227
|
-
* decision anyway — it is "the channel being read must show the truth".
|
|
142
|
+
* Channels a consumer is reading. Not filtered on `watchStatus`: a channel opened while offline never
|
|
143
|
+
* reached `Watching`, and `Channel.reload()` has its own `initialized || offlineMode` guard.
|
|
228
144
|
*/
|
|
229
145
|
private get recoverableActiveChannels(): Channel[] {
|
|
230
146
|
return this.client.channelManager
|
|
@@ -233,24 +149,13 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
233
149
|
}
|
|
234
150
|
|
|
235
151
|
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* Threads need their own pass because nothing else brings an open thread's replies back — a
|
|
239
|
-
* channel reload refreshes the main message list, `ChannelManager.recover()` refreshes the channel
|
|
240
|
-
* lists*, and `ThreadManager`'s own recovery refreshes the thread *list*, reusing existing
|
|
241
|
-
* instances without rehydrating them unless they were separately marked stale.
|
|
242
|
-
*
|
|
243
|
-
* `active` is the filter that matters: the registry also holds every thread the list has paged
|
|
244
|
-
* in, which is not what should be re-fetched on a reconnect — only what someone is actually
|
|
245
|
-
* reading. An active thread is always registered, listed or not (`thread.activate()` registers it).
|
|
246
|
-
* Guarded on the owning channel the same way active channels are: a thread whose channel was
|
|
247
|
-
* disconnected (`disconnect()`) has nothing to recover into.
|
|
152
|
+
* Threads a consumer is displaying. They need their own pass: channel reloads and the thread list
|
|
153
|
+
* refresh do not rehydrate them. Threads of a disconnected channel are skipped.
|
|
248
154
|
*/
|
|
249
155
|
private get recoverableActiveThreads(): Thread[] {
|
|
250
156
|
const threads: Thread[] = [];
|
|
251
157
|
for (const thread of this.client.threads.registeredThreads) {
|
|
252
|
-
//
|
|
253
|
-
// does, and adding one just for this would grow the public surface for a single internal read.
|
|
158
|
+
// `Thread` has no `active` accessor, so read it off state.
|
|
254
159
|
const { active } = thread.state.getLatestValue();
|
|
255
160
|
if (!active || thread.channel.pendingDisposal) continue;
|
|
256
161
|
threads.push(thread);
|
|
@@ -259,9 +164,8 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
259
164
|
}
|
|
260
165
|
|
|
261
166
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* and any other reloads on its next `activate()`.
|
|
167
|
+
* Flags closed threads stale, since they miss events during a drop. A listed thread rehydrates via the
|
|
168
|
+
* thread list reload, any other on its next `activate()`.
|
|
265
169
|
*/
|
|
266
170
|
private markInactiveThreadsStale() {
|
|
267
171
|
for (const thread of this.client.threads.registeredThreads) {
|
|
@@ -271,13 +175,10 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
271
175
|
}
|
|
272
176
|
|
|
273
177
|
private recoverChannelLists = async () => {
|
|
274
|
-
if (!this.config.enabled) return;
|
|
275
178
|
await this.client.channelManager.recover();
|
|
276
179
|
};
|
|
277
180
|
|
|
278
181
|
private recoverActiveChannels = async ({ isRetry = false } = {}): Promise<void> => {
|
|
279
|
-
if (!this.config.enabled) return;
|
|
280
|
-
|
|
281
182
|
if (this.isRecovering) {
|
|
282
183
|
this.recoveryRequestedAgain = true;
|
|
283
184
|
return;
|
|
@@ -286,15 +187,8 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
286
187
|
const channels = this.recoverableActiveChannels;
|
|
287
188
|
const threads = this.recoverableActiveThreads;
|
|
288
189
|
this.markInactiveThreadsStale();
|
|
289
|
-
// Captured
|
|
290
|
-
//
|
|
291
|
-
// still failed the reloads while ending up online again.
|
|
292
|
-
//
|
|
293
|
-
// The socket alone. Every reload is a request over it, so it is the connection whose failure
|
|
294
|
-
// invalidates them, and its store records every transition including the deliberate close and the
|
|
295
|
-
// two error paths. A device that loses its network takes the socket with it and is caught here
|
|
296
|
-
// anyway, while a device whose network is merely unknown — every host without a reporter — would
|
|
297
|
-
// otherwise have no protection at all.
|
|
190
|
+
// Captured to detect a socket drop during the reloads. The timestamp, not the boolean: a drop and
|
|
191
|
+
// return inside the window still fails the reloads.
|
|
298
192
|
const socketDropBefore =
|
|
299
193
|
this.client.wsConnection.state.getLatestValue().lastUnhealthyAt;
|
|
300
194
|
this.isRecovering = true;
|
|
@@ -304,10 +198,7 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
304
198
|
`Recovering ${channels.length} active channel(s) and ${threads.length} active thread(s).`,
|
|
305
199
|
);
|
|
306
200
|
|
|
307
|
-
// allSettled
|
|
308
|
-
// surfaced anywhere — the loaded window simply stays as it was until the next reconnect, or until
|
|
309
|
-
// a query the consumer itself issues records its own `lastQueryError` on the paginator. Channels
|
|
310
|
-
// and threads are independent requests, so they run together rather than in sequence.
|
|
201
|
+
// `allSettled`: one failure must not stop the others. Failed refreshes are not surfaced.
|
|
311
202
|
await Promise.allSettled([
|
|
312
203
|
...channels.map((channel) => channel.reload()),
|
|
313
204
|
...threads.map((thread) => thread.reload()),
|
|
@@ -315,24 +206,15 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
315
206
|
|
|
316
207
|
this.isRecovering = false;
|
|
317
208
|
|
|
318
|
-
// A reconnect landed
|
|
319
|
-
//
|
|
320
|
-
// event for the same reason, and this is what stops that withholding from stranding.
|
|
321
|
-
//
|
|
322
|
-
// Once, not until it settles. A reload that keeps moving the socket would otherwise recur without
|
|
323
|
-
// bound, and a connection still flapping after two passes is not one more query away from being
|
|
324
|
-
// caught up. The next up-edge starts a fresh pass anyway, because this one has finished by then.
|
|
209
|
+
// A reconnect landed mid-reload, so what was fetched belongs to a gone connection. Re-run once, not
|
|
210
|
+
// until settled: a flapping socket would loop forever.
|
|
325
211
|
const retryAfterReconnect = this.recoveryRequestedAgain && !isRetry;
|
|
326
212
|
this.recoveryRequestedAgain = false;
|
|
327
213
|
if (retryAfterReconnect) return await this.recoverActiveChannels({ isRetry: true });
|
|
328
214
|
|
|
329
|
-
//
|
|
330
|
-
//
|
|
331
|
-
//
|
|
332
|
-
// would mark messages read that were never fetched.
|
|
333
|
-
//
|
|
334
|
-
// Withholding is safe rather than stranding: a drop guarantees a later reconnect, and that
|
|
335
|
-
// recovery dispatches the event.
|
|
215
|
+
// A drop mid-recovery can fail every reload while this still reaches the end. Dispatching then would
|
|
216
|
+
// report stale state as fresh (the UI SDKs mark messages read off this event). Withholding is safe:
|
|
217
|
+
// the next reconnect recovers and dispatches it.
|
|
336
218
|
const socket = this.client.wsConnection.state.getLatestValue();
|
|
337
219
|
|
|
338
220
|
if (socket.lastUnhealthyAt !== socketDropBefore || !socket.isHealthy) {
|
|
@@ -344,21 +226,12 @@ export class ConnectionRecoveryManager extends WithSubscriptions {
|
|
|
344
226
|
return;
|
|
345
227
|
}
|
|
346
228
|
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
// reconnect (`StableWSConnection._reconnect()`, or v9's long-poll `connect(true)`), so a
|
|
350
|
-
// `closeConnection()` → `openConnection()` cycle (mobile backgrounding) never produced it.
|
|
351
|
-
// Consumers keying post-recovery work off this event — the UI SDKs' mark-read-on-catch-up
|
|
352
|
-
// among them — need it after the reload above, not before.
|
|
229
|
+
// Dispatched here so it fires on every reconnect path, including `closeConnection()` then
|
|
230
|
+
// `openConnection()`, and after the reloads.
|
|
353
231
|
this.client.dispatchEvent({ type: 'connection.recovered' });
|
|
354
232
|
};
|
|
355
233
|
|
|
356
|
-
/**
|
|
357
|
-
* Run a full recovery now, without waiting for a connection event.
|
|
358
|
-
*
|
|
359
|
-
* A no-op while one is already running: {@link recoverActiveChannels} defers the request to the
|
|
360
|
-
* end of the pass in flight rather than stacking a second one alongside it.
|
|
361
|
-
*/
|
|
234
|
+
/** Runs a full recovery now, without waiting for a connection event. A no-op while one is running. */
|
|
362
235
|
public recover = async () => {
|
|
363
236
|
if (this.isRecovering) {
|
|
364
237
|
logger
|
|
@@ -21,72 +21,35 @@ export const DEFAULT_NETWORK_CONNECTION_OBSERVER_CONFIG: NetworkConnectionObserv
|
|
|
21
21
|
deepFreezeConfig({ statusReporter: undefined });
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* Device network status as reactive `state`, written only through {@link setStatus} (by a
|
|
25
|
+
* {@link NetworkStatusReporter}). It is a separate fact from the WebSocket status in
|
|
26
|
+
* `client.wsConnection.state`: a socket can die on a working network, and a device can go offline
|
|
27
|
+
* before the socket notices. Read both and branch; network status must never gate requests.
|
|
26
28
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* has not noticed yet and keeps looking healthy for up to its 35s connection-check window. Conflating them is
|
|
30
|
-
* what makes offline UI blame the network for a dead socket, so nothing here derives one from the
|
|
31
|
-
* other:
|
|
32
|
-
*
|
|
33
|
-
* - the `network*` fields are written **only** via {@link setStatus}, from the platform
|
|
34
|
-
* listener the integrator registers ({@link NetworkStatusReporter}). The SDK cannot detect
|
|
35
|
-
* device network status itself — every platform reports it differently — so it has to be told. A
|
|
36
|
-
* browser reports it properly and that reporter is installed automatically; everywhere else the
|
|
37
|
-
* stand-in mirrors the WebSocket until a real reporter is installed, and `isOnline` stays
|
|
38
|
-
* `undefined` — *unknown* rather than offline — until the socket has been up once.
|
|
39
|
-
* Combining the two is a presentation decision and deliberately absent: whether "network down and
|
|
40
|
-
* socket down" reads as *no network* or as *reconnecting* is copy taxonomy, and a boolean named for
|
|
41
|
-
* reachability invites gating requests on it, which network status must never do. Read both and branch.
|
|
42
|
-
*
|
|
43
|
-
* The store is the whole interface. There is no companion event: a store already says both what the
|
|
44
|
-
* status is and that it just changed, and publishing the same fact twice only created the chance for
|
|
45
|
-
* the two to disagree.
|
|
29
|
+
* Browsers get their reporter automatically. Elsewhere a stand-in mirrors the WebSocket until a real
|
|
30
|
+
* one is installed, and `isOnline` stays `undefined` (unknown) until the socket has been up once.
|
|
46
31
|
*/
|
|
47
32
|
export class NetworkConnectionObserver extends WithSubscriptions {
|
|
48
33
|
client: StreamChat;
|
|
49
34
|
state: StateStore<NetworkConnectionState>;
|
|
50
|
-
/** The shared configuration machinery — see {@link ConfigController}. */
|
|
51
35
|
private readonly configController: ConfigController<NetworkConnectionObserverConfig>;
|
|
52
|
-
/**
|
|
53
|
-
* Held separately from `addUnsubscribeFunction` because it has to be **replaced**, not just torn
|
|
54
|
-
* down: that set only clears on unregister, so it cannot express a swap.
|
|
55
|
-
*/
|
|
36
|
+
/** Replaced on each install, which `addUnsubscribeFunction` (cleared on unregister) cannot do. */
|
|
56
37
|
private unsubscribeStatusReporter?: Unsubscribe;
|
|
57
|
-
/**
|
|
58
|
-
* The reporter currently installed, so re-installing the same one is a no-op. Configuration is
|
|
59
|
-
* re-derived more than once — the client calls `initializeConfig` directly and again through the
|
|
60
|
-
* config store's immediate subscribe — and tearing a platform listener down only to recreate it
|
|
61
|
-
* identical is wasteful at best and, for something like `NetInfo`, a needless native round trip.
|
|
62
|
-
*/
|
|
38
|
+
/** The installed reporter, so re-installing the same one (config is re-derived) is a no-op. */
|
|
63
39
|
private installedReporter?: NetworkStatusReporter;
|
|
64
40
|
/**
|
|
65
|
-
* What
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* Held here rather than written into the resolved configuration, which a derivation rebuilds from
|
|
69
|
-
* the declarative tree: a reporter set imperatively has to survive `client.config.set` on any
|
|
70
|
-
* `client` key.
|
|
41
|
+
* What `setStatusReporter` was last given (`null` clears, `undefined` if never called). Kept out
|
|
42
|
+
* of the resolved config, which derivations rebuild.
|
|
71
43
|
*/
|
|
72
44
|
private imperativeReporter?: NetworkStatusReporter | null;
|
|
73
|
-
/**
|
|
74
|
-
* The declared reporter the last installation saw, so a *change* to it can be told apart from a
|
|
75
|
-
* re-derivation that named the same thing. Whichever source spoke last wins, and this is what makes
|
|
76
|
-
* that comparison possible.
|
|
77
|
-
*/
|
|
45
|
+
/** The declared reporter the last install saw, to tell a changed declaration from a re-derive. */
|
|
78
46
|
private declaredReporter?: NetworkStatusReporter;
|
|
79
47
|
/**
|
|
80
|
-
* Whether
|
|
81
|
-
* the client
|
|
82
|
-
* reporter there on the first call could report a status into a half-built client.
|
|
48
|
+
* Whether config was derived at least once. `registerSubscriptions` runs mid-construction, when
|
|
49
|
+
* the client cannot take a status report yet.
|
|
83
50
|
*/
|
|
84
51
|
private configInitialized = false;
|
|
85
|
-
/**
|
|
86
|
-
* The host default, built once. {@link getDefaultNetworkStatusReporter} returns a fresh closure for
|
|
87
|
-
* the socket-derived variant, and a fresh identity every derivation would defeat the
|
|
88
|
-
* re-installation guard below — tearing a platform listener down only to recreate it identical.
|
|
89
|
-
*/
|
|
52
|
+
/** The host default, built once: the socket-mirroring one is a fresh closure per call. */
|
|
90
53
|
private defaultReporter?: NetworkStatusReporter;
|
|
91
54
|
|
|
92
55
|
constructor({ client }: { client: StreamChat }) {
|
|
@@ -102,25 +65,20 @@ export class NetworkConnectionObserver extends WithSubscriptions {
|
|
|
102
65
|
});
|
|
103
66
|
}
|
|
104
67
|
|
|
105
|
-
/**
|
|
106
|
-
* Resolved configuration, as a store — the shape every configurable class exposes
|
|
107
|
-
* (`configState` / `config` / `updateConfig`).
|
|
108
|
-
*/
|
|
109
68
|
get configState(): StateStore<NetworkConnectionObserverConfig> {
|
|
110
69
|
return this.configController.state;
|
|
111
70
|
}
|
|
112
71
|
|
|
113
|
-
/** The current resolved configuration. `Readonly` — change it through {@link updateConfig}. */
|
|
114
72
|
public get config(): Readonly<NetworkConnectionObserverConfig> {
|
|
115
73
|
return this.configState.getLatestValue();
|
|
116
74
|
}
|
|
117
75
|
|
|
118
76
|
/**
|
|
119
|
-
* Merges a partial configuration into the resolved config
|
|
77
|
+
* Merges a partial configuration into the resolved config. Also re-installs the reporter: the
|
|
78
|
+
* `setStatusReporter` one unless the configured reporter has changed since (set, replaced or
|
|
79
|
+
* cleared), else the configured one, else the host default.
|
|
120
80
|
*
|
|
121
|
-
*
|
|
122
|
-
* {@link setStatusReporter} rather than a write nobody acts on. Without it the field was
|
|
123
|
-
* stored and never invoked, leaving `isOnline` `undefined` forever with no error anywhere.
|
|
81
|
+
* @param config - Fields to merge into the resolved config.
|
|
124
82
|
*/
|
|
125
83
|
public updateConfig(config: Partial<NetworkConnectionObserverConfig>) {
|
|
126
84
|
this.configController.patch(config);
|
|
@@ -128,12 +86,11 @@ export class NetworkConnectionObserver extends WithSubscriptions {
|
|
|
128
86
|
}
|
|
129
87
|
|
|
130
88
|
/**
|
|
131
|
-
* Rebuilds the resolved configuration from package defaults plus the declarative slice
|
|
132
|
-
*
|
|
133
|
-
*
|
|
89
|
+
* Rebuilds the resolved configuration from package defaults plus the declarative slice. Also
|
|
90
|
+
* re-installs the reporter: the `setStatusReporter` one unless the configured reporter has changed
|
|
91
|
+
* since (set, replaced or cleared), else the configured one, else the host default.
|
|
134
92
|
*
|
|
135
|
-
*
|
|
136
|
-
* is what makes `client.config.set({ client: { connections: { statusReporter } } })` work.
|
|
93
|
+
* @param config - The declarative slice. Leave it out to rebuild from the defaults.
|
|
137
94
|
*/
|
|
138
95
|
public initializeConfig(config?: Partial<NetworkConnectionObserverConfig>) {
|
|
139
96
|
this.configController.initialize(config);
|
|
@@ -141,26 +98,19 @@ export class NetworkConnectionObserver extends WithSubscriptions {
|
|
|
141
98
|
this.installConfiguredReporter();
|
|
142
99
|
}
|
|
143
100
|
|
|
144
|
-
/** The reporter for this host, resolved once. See {@link defaultReporter}. */
|
|
145
101
|
private get hostDefaultReporter(): NetworkStatusReporter {
|
|
146
102
|
return (this.defaultReporter ??= getDefaultNetworkStatusReporter(
|
|
147
103
|
this.client.wsConnection,
|
|
148
104
|
));
|
|
149
105
|
}
|
|
150
106
|
|
|
151
|
-
/**
|
|
152
|
-
* Installs the reporter the resolved configuration names, falling back to the host default.
|
|
153
|
-
*
|
|
154
|
-
* The single place installation happens, so every path that can change what should be installed —
|
|
155
|
-
* a derivation, a patch — goes through the same resolution instead of each reimplementing it.
|
|
156
|
-
*/
|
|
107
|
+
/** Installs the imperative reporter if set, else the declared one, else the host default. */
|
|
157
108
|
private installConfiguredReporter() {
|
|
158
109
|
const declared = this.config.statusReporter;
|
|
159
110
|
|
|
160
111
|
if (declared !== this.declaredReporter) {
|
|
161
112
|
this.declaredReporter = declared;
|
|
162
|
-
//
|
|
163
|
-
// call: whichever source spoke last is what the integrator meant.
|
|
113
|
+
// A changed declaration outranks an earlier imperative call: the last source to speak wins.
|
|
164
114
|
this.imperativeReporter = undefined;
|
|
165
115
|
}
|
|
166
116
|
|
|
@@ -171,18 +121,14 @@ export class NetworkConnectionObserver extends WithSubscriptions {
|
|
|
171
121
|
);
|
|
172
122
|
}
|
|
173
123
|
|
|
174
|
-
/**
|
|
175
|
-
* Device network status. `undefined` means unknown — see {@link NetworkConnectionState.isOnline}.
|
|
176
|
-
* Guards must test `=== false`, never `!isOnline`.
|
|
177
|
-
*/
|
|
124
|
+
/** Device network status; `undefined` is unknown, so test `=== false`, never `!isOnline`. */
|
|
178
125
|
public get isOnline(): boolean | undefined {
|
|
179
126
|
return this.state.getLatestValue().isOnline;
|
|
180
127
|
}
|
|
181
128
|
|
|
182
129
|
/**
|
|
183
|
-
* Whether the installed reporter is the
|
|
184
|
-
* (`createWSConnectionNetworkStatusReporter`)
|
|
185
|
-
* down", not "the device is offline".
|
|
130
|
+
* Whether the installed reporter is the default that mirrors the WebSocket
|
|
131
|
+
* (`createWSConnectionNetworkStatusReporter`), where `isOnline === false` means "socket down".
|
|
186
132
|
*
|
|
187
133
|
* @internal
|
|
188
134
|
*/
|
|
@@ -195,26 +141,17 @@ export class NetworkConnectionObserver extends WithSubscriptions {
|
|
|
195
141
|
}
|
|
196
142
|
|
|
197
143
|
/**
|
|
198
|
-
* Installs the platform listener that reports device network status,
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* Available as a setter, not just a constructor option, because React Native registers its native
|
|
203
|
-
* handlers *after* the client exists.
|
|
204
|
-
*
|
|
205
|
-
* What is set here survives every later configuration derivation, and is only superseded by the
|
|
206
|
-
* declarative tree naming a *different* reporter — `client.config.set({ client: { networkConnection:
|
|
207
|
-
* { statusReporter } } })`.
|
|
144
|
+
* Installs the platform listener that reports device network status, replacing the previous one.
|
|
145
|
+
* `null` clears it and keeps the last known status. It survives later config derivations and is
|
|
146
|
+
* superseded only when the config names a different reporter
|
|
147
|
+
* (`client.config.set({ client: { networkConnection: { statusReporter } } })`).
|
|
208
148
|
*/
|
|
209
149
|
public setStatusReporter(reporter: NetworkStatusReporter | null | undefined) {
|
|
210
|
-
//
|
|
211
|
-
// default. `null` is kept distinct from `undefined`: it means "explicitly none", which must
|
|
212
|
-
// survive a derivation too.
|
|
150
|
+
// `null` ("explicitly none") stays distinct from `undefined` (never set) across derivations.
|
|
213
151
|
this.imperativeReporter = reporter ?? null;
|
|
214
152
|
this.installConfiguredReporter();
|
|
215
153
|
}
|
|
216
154
|
|
|
217
|
-
/** Installs one reporter, unsubscribing whatever was there. */
|
|
218
155
|
private installReporter(reporter: NetworkStatusReporter | null | undefined) {
|
|
219
156
|
if (reporter && reporter === this.installedReporter) return;
|
|
220
157
|
|
|
@@ -236,16 +173,9 @@ export class NetworkConnectionObserver extends WithSubscriptions {
|
|
|
236
173
|
}
|
|
237
174
|
}
|
|
238
175
|
|
|
239
|
-
/**
|
|
240
|
-
* Reports device network status.
|
|
241
|
-
*
|
|
242
|
-
* The reporter calls this; so may a host with no listener API to register at all, and it is the
|
|
243
|
-
* supported replacement for reaching into `client.wsConnection.onlineStatusChanged` with a
|
|
244
|
-
* synthesized DOM event.
|
|
245
|
-
*/
|
|
176
|
+
/** Reports device network status. Called by the reporter, or by a host with no listener API. */
|
|
246
177
|
public setStatus(isOnline: boolean) {
|
|
247
|
-
// Guard before stamping:
|
|
248
|
-
// timestamp would defeat that and publish an update for a status that did not change.
|
|
178
|
+
// Guard before stamping: a fresh timestamp would publish an update for an unchanged status.
|
|
249
179
|
if (this.isOnline === isOnline) return;
|
|
250
180
|
|
|
251
181
|
const now = new Date();
|
|
@@ -254,12 +184,7 @@ export class NetworkConnectionObserver extends WithSubscriptions {
|
|
|
254
184
|
);
|
|
255
185
|
}
|
|
256
186
|
|
|
257
|
-
/**
|
|
258
|
-
* Nothing to subscribe to beyond the reporter, which {@link initializeConfig} installs — this
|
|
259
|
-
* class has no client events to listen to, by design: deriving either status from an event would
|
|
260
|
-
* be the conflation it exists to prevent. Present because `WithSubscriptions` requires it, and so
|
|
261
|
-
* that teardown releases the platform listener.
|
|
262
|
-
*/
|
|
187
|
+
/** Listens to no client events; teardown only releases the platform listener. */
|
|
263
188
|
public registerSubscriptions = () => {
|
|
264
189
|
if (!this.hasSubscriptions) {
|
|
265
190
|
this.addUnsubscribeFunction(() => {
|
|
@@ -268,10 +193,8 @@ export class NetworkConnectionObserver extends WithSubscriptions {
|
|
|
268
193
|
this.installedReporter = undefined;
|
|
269
194
|
});
|
|
270
195
|
|
|
271
|
-
// Re-registering
|
|
272
|
-
//
|
|
273
|
-
// deaf, unlike `WSConnection` and `ConnectionRecoveryManager`, which both resubscribe here.
|
|
274
|
-
// Skipped before the first derivation, when there is nothing resolved to install yet.
|
|
196
|
+
// Re-registering reinstalls the listener released by the teardown above. Skipped before the
|
|
197
|
+
// first derivation, when there is nothing resolved to install.
|
|
275
198
|
if (this.configInitialized) this.installConfiguredReporter();
|
|
276
199
|
}
|
|
277
200
|
|