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.
Files changed (269) hide show
  1. package/dist/cjs/index.browser.js +2196 -3902
  2. package/dist/cjs/index.browser.js.map +3 -3
  3. package/dist/cjs/index.node.js +2197 -3902
  4. package/dist/cjs/index.node.js.map +3 -3
  5. package/dist/esm/index.mjs +2199 -3905
  6. package/dist/esm/index.mjs.map +4 -4
  7. package/dist/types/ChannelManager.d.ts +120 -233
  8. package/dist/types/CooldownTimer.d.ts +8 -23
  9. package/dist/types/EventHandlerPipeline.d.ts +17 -37
  10. package/dist/types/LiveLocationManager.d.ts +22 -50
  11. package/dist/types/api-client.d.ts +9 -14
  12. package/dist/types/channel.d.ts +253 -448
  13. package/dist/types/channel_state.d.ts +48 -95
  14. package/dist/types/client.d.ts +245 -370
  15. package/dist/types/client_state.d.ts +1 -3
  16. package/dist/types/configuration/ConfigController.d.ts +30 -124
  17. package/dist/types/configuration/InstanceConfigurationRegistry.d.ts +31 -123
  18. package/dist/types/configuration/keys.d.ts +5 -19
  19. package/dist/types/configuration/shape.d.ts +12 -29
  20. package/dist/types/configuration/types.d.ts +59 -87
  21. package/dist/types/configuration/utils/applyInstanceConfiguration.d.ts +13 -35
  22. package/dist/types/configuration/utils/copyConfigPatch.d.ts +8 -0
  23. package/dist/types/configuration/utils/declarativeSlices.d.ts +5 -16
  24. package/dist/types/configuration/utils/deepFreezeConfig.d.ts +3 -17
  25. package/dist/types/configuration/utils/serverAuthority.d.ts +9 -29
  26. package/dist/types/connection/ConnectionIdManager.d.ts +18 -40
  27. package/dist/types/connection/ConnectionRecoveryManager.d.ts +29 -120
  28. package/dist/types/connection/networkConnection/NetworkConnectionObserver.d.ts +32 -103
  29. package/dist/types/connection/networkConnection/reporters.d.ts +9 -32
  30. package/dist/types/connection/networkConnection/types.d.ts +12 -27
  31. package/dist/types/connection/wsConnection/StableWSConnection.d.ts +37 -116
  32. package/dist/types/connection/wsConnection/WSConnection.d.ts +41 -104
  33. package/dist/types/connection/wsConnection/WSConnectionFallback.d.ts +8 -16
  34. package/dist/types/connection/wsConnection/config.d.ts +8 -28
  35. package/dist/types/connection/wsConnection/types.d.ts +17 -70
  36. package/dist/types/entityStore/EntityStore.d.ts +153 -113
  37. package/dist/types/entityStore/StoreBackedItemIndex.d.ts +13 -46
  38. package/dist/types/errors.d.ts +7 -19
  39. package/dist/types/gen/chat/ChannelApi.d.ts +2 -1
  40. package/dist/types/gen/chat/ChatApi.d.ts +28 -14
  41. package/dist/types/gen/models/index.d.ts +769 -86
  42. package/dist/types/gen/moderation/ModerationApi.d.ts +4 -4
  43. package/dist/types/index.d.ts +2 -4
  44. package/dist/types/languageNames.d.ts +9 -24
  45. package/dist/types/logger.d.ts +1 -3
  46. package/dist/types/messageComposer/LocationComposer.d.ts +1 -1
  47. package/dist/types/messageComposer/attachmentIdentity.d.ts +1 -6
  48. package/dist/types/messageComposer/attachmentManager.d.ts +10 -32
  49. package/dist/types/messageComposer/attachmentUtils.d.ts +3 -14
  50. package/dist/types/messageComposer/configuration/configuration.d.ts +2 -5
  51. package/dist/types/messageComposer/configuration/types.d.ts +29 -56
  52. package/dist/types/messageComposer/linkPreviewsManager.d.ts +6 -9
  53. package/dist/types/messageComposer/messageComposer.d.ts +30 -164
  54. package/dist/types/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.d.ts +4 -14
  55. package/dist/types/messageComposer/middleware/messageComposer/attachments.d.ts +2 -9
  56. package/dist/types/messageComposer/middleware/pollComposer/types.d.ts +2 -4
  57. package/dist/types/messageComposer/middleware/pollComposer/validation.d.ts +7 -19
  58. package/dist/types/messageComposer/middleware/textComposer/commands.d.ts +9 -0
  59. package/dist/types/messageComposer/middleware/textComposer/mentions.d.ts +11 -18
  60. package/dist/types/messageComposer/middleware/textComposer/textMiddlewareUtils.d.ts +9 -3
  61. package/dist/types/messageComposer/middleware/textComposer/types.d.ts +1 -6
  62. package/dist/types/messageComposer/pollComposer.d.ts +8 -4
  63. package/dist/types/messageComposer/textComposer.d.ts +3 -9
  64. package/dist/types/messageComposer/types.d.ts +5 -8
  65. package/dist/types/messageDelivery/MessageDeliveryReporter.d.ts +25 -79
  66. package/dist/types/messageDelivery/MessageReceiptsTracker.d.ts +15 -82
  67. package/dist/types/messageOperations/FailedSendCache.d.ts +4 -9
  68. package/dist/types/messageOperations/MessageOperationStatePolicy.d.ts +10 -20
  69. package/dist/types/messageOperations/MessageOperations.d.ts +20 -40
  70. package/dist/types/messageOperations/applyReactionLocally.d.ts +5 -22
  71. package/dist/types/messageOperations/createMessageOperations.d.ts +3 -5
  72. package/dist/types/messageOperations/reflectReactionEvent.d.ts +5 -13
  73. package/dist/types/messageOperations/sendOrdering.d.ts +4 -7
  74. package/dist/types/messageOperations/settlePendingAttachmentUploads.d.ts +7 -15
  75. package/dist/types/messageOperations/types.d.ts +15 -30
  76. package/dist/types/middleware.d.ts +7 -5
  77. package/dist/types/moderation.d.ts +21 -14
  78. package/dist/types/notifications/NotificationManager.d.ts +8 -31
  79. package/dist/types/notifications/types.d.ts +19 -59
  80. package/dist/types/offline-support/offline_support_api.d.ts +145 -539
  81. package/dist/types/offline-support/offline_sync_manager.d.ts +18 -42
  82. package/dist/types/offline-support/queueableOperations.d.ts +24 -52
  83. package/dist/types/offline-support/types.d.ts +24 -187
  84. package/dist/types/pagination/ItemIndex.d.ts +4 -12
  85. package/dist/types/pagination/cursorDerivation/aroundPaginationFlags.d.ts +13 -0
  86. package/dist/types/pagination/cursorDerivation/createdAtAroundPaginationFlags.d.ts +2 -4
  87. package/dist/types/pagination/cursorDerivation/linearPaginationFlags.d.ts +2 -3
  88. package/dist/types/pagination/paginators/BasePaginator.d.ts +235 -622
  89. package/dist/types/pagination/paginators/ChannelPaginator.d.ts +67 -125
  90. package/dist/types/pagination/paginators/MessageIntervalPaginator.d.ts +133 -292
  91. package/dist/types/pagination/paginators/MessagePaginator.d.ts +69 -118
  92. package/dist/types/pagination/paginators/PinnedMessagePaginator.d.ts +7 -26
  93. package/dist/types/pagination/paginators/ReminderPaginator.d.ts +2 -2
  94. package/dist/types/pagination/paginators/ThreadPaginator.d.ts +15 -23
  95. package/dist/types/pagination/paginators/UserGroupPaginator.d.ts +2 -6
  96. package/dist/types/pagination/sortCompiler.d.ts +11 -22
  97. package/dist/types/pagination/utility.normalization.d.ts +5 -23
  98. package/dist/types/pagination/utility.search.d.ts +3 -8
  99. package/dist/types/poll.d.ts +14 -14
  100. package/dist/types/poll_manager.d.ts +11 -2
  101. package/dist/types/poll_optimistic_votes.d.ts +10 -14
  102. package/dist/types/reminders/Reminder.d.ts +4 -4
  103. package/dist/types/reminders/ReminderManager.d.ts +7 -20
  104. package/dist/types/search/BaseSearchSource.d.ts +7 -12
  105. package/dist/types/search/ChannelSearchSource.d.ts +7 -7
  106. package/dist/types/search/MessageSearchSource.d.ts +7 -9
  107. package/dist/types/search/SearchController.d.ts +17 -22
  108. package/dist/types/search/types.d.ts +6 -10
  109. package/dist/types/signing.d.ts +12 -3
  110. package/dist/types/thread.d.ts +23 -71
  111. package/dist/types/thread_manager.d.ts +45 -70
  112. package/dist/types/token_manager.d.ts +8 -13
  113. package/dist/types/types.d.ts +64 -125
  114. package/dist/types/types.utility.d.ts +3 -3
  115. package/dist/types/upload-utils.d.ts +5 -10
  116. package/dist/types/uploadManager.d.ts +17 -45
  117. package/dist/types/utils/FixedSizeQueueCache.d.ts +6 -11
  118. package/dist/types/utils/WithSubscriptions.d.ts +5 -15
  119. package/dist/types/utils/concurrency.d.ts +11 -19
  120. package/dist/types/utils/mergeWith/mergeWith.d.ts +8 -11
  121. package/dist/types/utils/mergeWith/mergeWithCore.d.ts +5 -13
  122. package/dist/types/utils/mergeWith/mergeWithDiff.d.ts +22 -0
  123. package/dist/types/utils/objectPath.d.ts +6 -41
  124. package/dist/types/utils/retryable.d.ts +8 -12
  125. package/dist/types/utils/throttling/throttle.d.ts +8 -23
  126. package/dist/types/utils/time.d.ts +24 -64
  127. package/dist/types/utils.d.ts +40 -86
  128. package/package.json +7 -2
  129. package/src/ChannelManager.ts +159 -300
  130. package/src/CooldownTimer.ts +11 -29
  131. package/src/EventHandlerPipeline.ts +21 -44
  132. package/src/LiveLocationManager.ts +35 -74
  133. package/src/api-client.ts +43 -61
  134. package/src/campaign.ts +1 -1
  135. package/src/channel.ts +396 -749
  136. package/src/channel_batch_updater.ts +1 -1
  137. package/src/channel_state.ts +50 -105
  138. package/src/client.ts +360 -588
  139. package/src/client_state.ts +1 -6
  140. package/src/configuration/ConfigController.ts +41 -157
  141. package/src/configuration/InstanceConfigurationRegistry.ts +42 -171
  142. package/src/configuration/index.ts +1 -1
  143. package/src/configuration/keys.ts +13 -32
  144. package/src/configuration/shape.ts +67 -70
  145. package/src/configuration/types.ts +60 -100
  146. package/src/configuration/utils/applyInstanceConfiguration.ts +21 -53
  147. package/src/configuration/utils/copyConfigPatch.ts +11 -32
  148. package/src/configuration/utils/declarativeSlices.ts +9 -39
  149. package/src/configuration/utils/deepFreezeConfig.ts +3 -17
  150. package/src/configuration/utils/index.ts +2 -4
  151. package/src/configuration/utils/serverAuthority.ts +20 -68
  152. package/src/connection/ConnectionIdManager.ts +20 -49
  153. package/src/connection/ConnectionRecoveryManager.ts +51 -178
  154. package/src/connection/networkConnection/NetworkConnectionObserver.ts +37 -114
  155. package/src/connection/networkConnection/reporters.ts +9 -36
  156. package/src/connection/networkConnection/types.ts +12 -27
  157. package/src/connection/wsConnection/StableWSConnection.ts +73 -193
  158. package/src/connection/wsConnection/WSConnection.ts +56 -131
  159. package/src/connection/wsConnection/WSConnectionFallback.ts +22 -31
  160. package/src/connection/wsConnection/config.ts +13 -48
  161. package/src/connection/wsConnection/types.ts +17 -70
  162. package/src/constants.ts +4 -4
  163. package/src/entityStore/EntityStore.ts +162 -167
  164. package/src/entityStore/StoreBackedItemIndex.ts +14 -47
  165. package/src/errors.ts +7 -19
  166. package/src/formatMessageMemo.ts +3 -9
  167. package/src/gen/chat/ChannelApi.ts +19 -0
  168. package/src/gen/chat/ChatApi.ts +87 -13
  169. package/src/gen/models/index.ts +793 -71
  170. package/src/gen/moderation/ModerationApi.ts +0 -4
  171. package/src/index.ts +10 -14
  172. package/src/languageNames.ts +9 -24
  173. package/src/logger.ts +1 -3
  174. package/src/messageComposer/LocationComposer.ts +7 -23
  175. package/src/messageComposer/MessageComposerEffectHandlers.ts +1 -2
  176. package/src/messageComposer/attachmentIdentity.ts +2 -13
  177. package/src/messageComposer/attachmentManager.ts +17 -63
  178. package/src/messageComposer/attachmentUtils.ts +3 -17
  179. package/src/messageComposer/configuration/configuration.ts +5 -8
  180. package/src/messageComposer/configuration/types.ts +29 -56
  181. package/src/messageComposer/fileUtils.ts +1 -1
  182. package/src/messageComposer/linkPreviewsManager.ts +8 -20
  183. package/src/messageComposer/messageComposer.ts +54 -222
  184. package/src/messageComposer/middleware/attachmentManager/postUpload/attachmentEnrichment.ts +4 -16
  185. package/src/messageComposer/middleware/attachmentManager/postUpload/uploadErrorHandler.ts +1 -2
  186. package/src/messageComposer/middleware/messageComposer/attachments.ts +14 -40
  187. package/src/messageComposer/middleware/messageComposer/linkPreviews.ts +3 -4
  188. package/src/messageComposer/middleware/messageComposer/textComposer.ts +1 -1
  189. package/src/messageComposer/middleware/messageComposer/userDataInjection.ts +4 -11
  190. package/src/messageComposer/middleware/pollComposer/state.ts +2 -2
  191. package/src/messageComposer/middleware/pollComposer/types.ts +2 -4
  192. package/src/messageComposer/middleware/pollComposer/validation.ts +8 -26
  193. package/src/messageComposer/middleware/textComposer/TextComposerMiddlewareExecutor.ts +1 -6
  194. package/src/messageComposer/middleware/textComposer/commandUtils.ts +1 -2
  195. package/src/messageComposer/middleware/textComposer/commands.ts +11 -16
  196. package/src/messageComposer/middleware/textComposer/mentions.ts +32 -70
  197. package/src/messageComposer/middleware/textComposer/textMiddlewareUtils.ts +10 -4
  198. package/src/messageComposer/middleware/textComposer/types.ts +1 -6
  199. package/src/messageComposer/pollComposer.ts +11 -8
  200. package/src/messageComposer/textComposer.ts +9 -59
  201. package/src/messageComposer/types.ts +9 -12
  202. package/src/messageDelivery/MessageDeliveryReporter.ts +60 -113
  203. package/src/messageDelivery/MessageReceiptsTracker.ts +21 -105
  204. package/src/messageOperations/FailedSendCache.ts +4 -9
  205. package/src/messageOperations/MessageOperationStatePolicy.ts +40 -67
  206. package/src/messageOperations/MessageOperations.ts +33 -62
  207. package/src/messageOperations/applyReactionLocally.ts +9 -28
  208. package/src/messageOperations/createMessageOperations.ts +17 -33
  209. package/src/messageOperations/reflectReactionEvent.ts +5 -13
  210. package/src/messageOperations/sendOrdering.ts +4 -7
  211. package/src/messageOperations/settlePendingAttachmentUploads.ts +10 -21
  212. package/src/messageOperations/types.ts +15 -30
  213. package/src/middleware.ts +7 -10
  214. package/src/moderation.ts +25 -21
  215. package/src/notifications/NotificationManager.ts +11 -35
  216. package/src/notifications/types.ts +19 -59
  217. package/src/offline-support/offline_support_api.ts +178 -608
  218. package/src/offline-support/offline_sync_manager.ts +25 -69
  219. package/src/offline-support/queueableOperations.ts +31 -84
  220. package/src/offline-support/types.ts +25 -188
  221. package/src/pagination/ItemIndex.ts +4 -12
  222. package/src/pagination/cursorDerivation/aroundPaginationFlags.ts +29 -0
  223. package/src/pagination/cursorDerivation/createdAtAroundPaginationFlags.ts +13 -62
  224. package/src/pagination/cursorDerivation/idAroundPaginationFlags.ts +11 -39
  225. package/src/pagination/cursorDerivation/linearPaginationFlags.ts +4 -6
  226. package/src/pagination/filterCompiler.ts +11 -25
  227. package/src/pagination/paginators/BasePaginator.ts +422 -976
  228. package/src/pagination/paginators/ChannelPaginator.ts +130 -190
  229. package/src/pagination/paginators/MessageIntervalPaginator.ts +226 -457
  230. package/src/pagination/paginators/MessagePaginator.ts +135 -175
  231. package/src/pagination/paginators/PinnedMessagePaginator.ts +13 -38
  232. package/src/pagination/paginators/ReminderPaginator.ts +12 -15
  233. package/src/pagination/paginators/ThreadPaginator.ts +16 -26
  234. package/src/pagination/paginators/UserGroupPaginator.ts +6 -17
  235. package/src/pagination/paginators/stateThrottling.ts +5 -10
  236. package/src/pagination/sortCompiler.ts +23 -50
  237. package/src/pagination/utility.normalization.ts +8 -30
  238. package/src/pagination/utility.search.ts +4 -11
  239. package/src/poll.ts +19 -19
  240. package/src/poll_manager.ts +16 -20
  241. package/src/poll_optimistic_votes.ts +17 -22
  242. package/src/reminders/Reminder.ts +5 -6
  243. package/src/reminders/ReminderManager.ts +9 -34
  244. package/src/reminders/ReminderTimer.ts +1 -2
  245. package/src/search/BaseSearchSource.ts +14 -29
  246. package/src/search/ChannelSearchSource.ts +8 -8
  247. package/src/search/MessageSearchSource.ts +19 -25
  248. package/src/search/SearchController.ts +18 -24
  249. package/src/search/types.ts +6 -10
  250. package/src/segment.ts +1 -1
  251. package/src/signing.ts +23 -3
  252. package/src/thread.ts +72 -173
  253. package/src/thread_manager.ts +59 -76
  254. package/src/token_manager.ts +11 -21
  255. package/src/types.ts +78 -126
  256. package/src/types.utility.ts +3 -3
  257. package/src/upload-utils.ts +5 -10
  258. package/src/uploadManager.ts +22 -54
  259. package/src/utils/FixedSizeQueueCache.ts +13 -21
  260. package/src/utils/WithSubscriptions.ts +5 -15
  261. package/src/utils/concurrency.ts +16 -55
  262. package/src/utils/mergeWith/mergeWith.ts +10 -13
  263. package/src/utils/mergeWith/mergeWithCore.ts +24 -81
  264. package/src/utils/mergeWith/mergeWithDiff.ts +15 -33
  265. package/src/utils/objectPath.ts +6 -41
  266. package/src/utils/retryable.ts +10 -14
  267. package/src/utils/throttling/throttle.ts +9 -25
  268. package/src/utils/time.ts +26 -66
  269. package/src/utils.ts +72 -128
@@ -19,69 +19,45 @@ import type { Unsubscribe } from '@stream-io/state-store';
19
19
  const logger = chatLoggerSystem.getLogger('client');
20
20
 
21
21
  /**
22
- * This client's WebSocket, as a stable object: `client.wsConnection` is created once with the client
23
- * and never replaced, so `state` is safe to subscribe to for the client's whole lifetime.
22
+ * This client's WebSocket as a stable object: `client.wsConnection` is created once with the client,
23
+ * so `state` can be subscribed to for its whole lifetime. The socket ({@link StableWSConnection}, in
24
+ * {@link connection}) is replaced on every {@link connect}, so a store living on it would be
25
+ * unreadable before `connectUser` and strand subscribers across `closeConnection()` and
26
+ * `openConnection()`.
24
27
  *
25
- * The socket itself — {@link StableWSConnection}, which does the connecting, pinging and
26
- * reconnecting — hangs off {@link connection} and **is** replaced: `client.connect()` builds a new one
27
- * on every call. That is the reason this wrapper exists. Without it the status store would live on the
28
- * socket, where two things would go wrong: it would be unreadable before `connectUser` (the field
29
- * is `null` until the first connect), and every `closeConnection()` → `openConnection()` cycle — the
30
- * documented mobile background/foreground flow — would strand anyone already subscribed.
31
- *
32
- * The members below forward to the current socket so existing call sites keep working, with one
33
- * deliberate exception: {@link isHealthy} is answered from `state`, not from `connection`, so it stays
34
- * correct across a replacement and while no socket exists yet.
35
- *
36
- * It also owns the **network-status subscription**, for the same reason it owns the store: subscribing
37
- * here means one subscription for the client's lifetime, routed to whichever socket is current. Per
38
- * socket it would leak — `client.connect()` overwrites `connection` without disconnecting the
39
- * previous one, leaving a dead socket still listening and still able to call `_reconnect()` on
40
- * itself.
41
- *
42
- * **With `enableWSFallback`, the store can describe the long-poll instead.** Once {@link connect}
43
- * has switched to `WSConnectionFallback` ({@link fallback}).
28
+ * It also owns the single network-status subscription, routed to the current socket. After an
29
+ * `enableWSFallback` switch `state` and that routing describe the long-poll ({@link fallback}).
44
30
  */
45
31
  export class WSConnection extends WithSubscriptions {
46
32
  state: StateStore<WSConnectionState>;
47
33
  /**
48
- * The live socket, or `null` before the first {@link connect}. Built and replaced here, not from
49
- * outside — reach for {@link isHealthy} rather than this.
34
+ * The live socket, or `null` before the first {@link connect}. Prefer {@link isHealthy} to it.
50
35
  *
51
36
  * @internal
52
37
  */
53
38
  connection: StableWSConnection | null = null;
54
39
  /**
55
- * The long-poll, once `enableWSFallback` has switched to it; `undefined` until then. Built by
56
- * {@link connect} and never cleared: as in v9, the client does not go back to the WebSocket, not
57
- * even across `disconnectUser()`.
40
+ * The long-poll, once `enableWSFallback` has switched to it. Never cleared, not even by
41
+ * `disconnectUser()`.
58
42
  *
59
43
  * @internal
60
44
  */
61
45
  fallback?: WSConnectionFallback;
62
46
  /**
63
- * Readable by the socket this object owns, which reaches the client through its parent rather than
64
- * holding one of its own. Not part of the public surface — `client.wsConnection.client` is a
65
- * round trip back to where you started.
47
+ * For the socket this object owns, which reaches the client through it.
66
48
  *
67
49
  * @internal
68
50
  */
69
51
  readonly client: StreamChat;
70
- /** The shared configuration machinery — see {@link ConfigController}. */
71
52
  private readonly configController: ConfigController<WSConnectionConfig>;
72
- /**
73
- * The out-of-range values already warned about, so a bad setting is reported once rather than on
74
- * every derivation. Configuration is re-derived more than once at construction alone — the client
75
- * calls `initializeConfig` directly and again through the config store's immediate subscribe.
76
- */
53
+ /** Out-of-range values already warned about, so a bad setting is reported once per value. */
77
54
  private warnedClamps = new Map<string, number>();
78
55
 
79
56
  constructor({ client }: { client: StreamChat }) {
80
57
  super();
81
58
  this.configController = new ConfigController<WSConnectionConfig>({
82
59
  defaults: DEFAULT_WS_CONNECTION_CONFIG,
83
- // The bounds hook, not a check in `updateConfig`: it runs on every derivation *and* on every
84
- // patch, so a limit cannot be escaped by setting the field again later.
60
+ // Runs on every derivation and every patch, so a limit cannot be escaped by setting it again.
85
61
  applyAuthority: (requested) => this.applyConfigBounds(requested),
86
62
  });
87
63
  this.client = client;
@@ -92,35 +68,16 @@ export class WSConnection extends WithSubscriptions {
92
68
  });
93
69
  }
94
70
 
95
- /**
96
- * Resolved configuration, as a store — the shape every configurable class exposes
97
- * (`configState` / `config` / `updateConfig`).
98
- */
99
71
  get configState(): StateStore<WSConnectionConfig> {
100
72
  return this.configController.state;
101
73
  }
102
74
 
103
- /**
104
- * The current resolved configuration. `Readonly` — change it through {@link updateConfig}.
105
- *
106
- * The socket reads this **live** rather than snapshotting it, so an update reaches the current
107
- * connection instead of waiting for the next one. That matters here more than for most configurable
108
- * classes, because {@link connect} replaces the socket every time it is called.
109
- */
75
+ /** Read live by the socket, so an update reaches the current connection. */
110
76
  public get config(): Readonly<WSConnectionConfig> {
111
77
  return this.configState.getLatestValue();
112
78
  }
113
79
 
114
- /**
115
- * Holds the timing knobs inside {@link WS_CONNECTION_CONFIG_BOUNDS}, warning once per offending
116
- * value.
117
- *
118
- * Clamps rather than throws. An out-of-range timing value is a misconfiguration, not a
119
- * programming error, and refusing to construct a client over it would take down an application
120
- * that is otherwise fine — while silently using the requested value would break the socket in a
121
- * way that looks like a flaky network. So the socket keeps working at the nearest usable setting
122
- * and says what it did.
123
- */
80
+ /** Clamps the timing knobs into {@link WS_CONNECTION_CONFIG_BOUNDS}, warning once per value. */
124
81
  private applyConfigBounds(requested: WSConnectionConfig): WSConnectionConfig {
125
82
  const { clamped, corrections } = clampWSConnectionConfig(requested);
126
83
 
@@ -139,40 +96,37 @@ export class WSConnection extends WithSubscriptions {
139
96
  return clamped;
140
97
  }
141
98
 
142
- /** Merges a partial configuration into the resolved config and notifies subscribers. */
99
+ /**
100
+ * Merges a partial configuration into the resolved config.
101
+ *
102
+ * @param config - Fields to merge into the resolved config.
103
+ */
143
104
  public updateConfig(config: Partial<WSConnectionConfig>) {
144
105
  this.configController.patch(config);
145
106
  }
146
107
 
147
108
  /**
148
- * Rebuilds the resolved configuration from package defaults plus the declarative slice — the
149
- * derivation entry point every configurable entity exposes.
109
+ * Re-derives the configuration from the declarative slice.
110
+ *
111
+ * @param config - The declarative slice. Leave it out to rebuild from the defaults.
150
112
  */
151
113
  public initializeConfig(config?: Partial<WSConnectionConfig>) {
152
114
  this.configController.initialize(config);
153
115
  }
154
116
 
155
- /**
156
- * Is this WebSocket up — or, after an `enableWSFallback` switch, the long-poll. Read from
157
- * {@link state} rather than from the current socket, so it survives the socket being replaced and
158
- * answers `false` rather than throwing before the first connect.
159
- */
117
+ /** Read from {@link state}, so it survives socket replacement and is `false` before connecting. */
160
118
  get isHealthy(): boolean {
161
119
  return this.state.getLatestValue().isHealthy;
162
120
  }
163
121
 
164
- /** Whether a connection attempt is in flight — the long-poll's after an `enableWSFallback` switch. */
122
+ /** Whether a connection attempt is in flight (the long-poll's, after a fallback switch). */
165
123
  get isConnecting(): boolean {
166
124
  return (this.fallback ?? this.connection)?.isConnecting ?? false;
167
125
  }
168
126
 
169
127
  /**
170
- * Records this connection's status. Returns whether it changed.
171
- *
172
- * {@link StableWSConnection} routes **every** status transition through here — including
173
- * `disconnect()`, which `closeConnection()` uses, and the two error paths. The one other
174
- * caller is {@link fallback}, which takes over once `enableWSFallback` has switched to
175
- * long-polling.
128
+ * Records this connection's status and returns whether it changed. Called by
129
+ * {@link StableWSConnection} on every status transition, and by {@link fallback} once it takes over.
176
130
  *
177
131
  * @internal
178
132
  */
@@ -187,27 +141,15 @@ export class WSConnection extends WithSubscriptions {
187
141
  return true;
188
142
  }
189
143
 
190
- /**
191
- * Routes the device's network status to whichever socket is current.
192
- *
193
- * One subscription, held here rather than on the socket: this object is created with the client and
194
- * never replaced, while a socket is replaced on every connect and may be built before its client
195
- * exists at all.
196
- *
197
- * Read from the store rather than from an event, so there is one description of the device's
198
- * network rather than two that can disagree.
199
- *
200
- * After an `enableWSFallback` switch it routes to {@link fallback} instead, leaving the
201
- * disconnected socket out of it.
202
- */
144
+ /** Routes the device's network status to the current socket, or to {@link fallback} once set. */
203
145
  public registerSubscriptions = (): Unsubscribe => {
204
146
  if (!this.hasSubscriptions) {
205
147
  this.addUnsubscribeFunction(
206
148
  this.client.networkConnection.state.subscribeWithSelector(
207
149
  ({ isOnline }) => ({ isOnline }),
208
150
  ({ isOnline }) => {
209
- // `undefined` is *unknown*, not offline: no reporter has said anything yet, and acting on
210
- // it would tear down a healthy socket on every host that cannot answer the question.
151
+ // `undefined` is unknown, not offline: acting on it would tear down a healthy socket on
152
+ // hosts with no reporter.
211
153
  if (typeof isOnline !== 'boolean') return;
212
154
  (this.fallback ?? this.connection)?._applyNetworkStatus(isOnline);
213
155
  },
@@ -220,22 +162,18 @@ export class WSConnection extends WithSubscriptions {
220
162
  };
221
163
 
222
164
  /**
223
- * Builds a socket and opens it, replacing any previous one.
224
- *
225
- * A fresh `StableWSConnection` per connect is the existing behaviour, kept deliberately: it resets
226
- * `wsID`, the failure counters and the health-check timers, and `wsID` is what makes callbacks from
227
- * an abandoned socket recognisable and ignorable. Reusing one across connect cycles would carry
228
- * that state over.
229
- *
230
- * Creation lives here rather than in the constructor because a client that never calls
231
- * `connectUser` should never build a socket, and here rather than in `client.connect()` because a
232
- * field belongs to the object that owns it.
165
+ * Builds a fresh socket (resetting `wsID`, the failure counters and the health-check timers) and
166
+ * opens it, closing any previous one. A socket injected through `config.connection` (Node only) is
167
+ * reused as is. With `enableWSFallback`, a network failure switches to the long-poll
168
+ * ({@link fallback}), which every later call connects instead.
233
169
  *
234
- * With `enableWSFallback`, a socket that fails with a network error is replaced by the long-poll
235
- * ({@link fallback}), which every later call connects instead of building a socket.
170
+ * @param timeout - Connect timeout for a new socket, in milliseconds; the long-poll ignores it.
171
+ * Defaults to `config.connectTimeoutMs`.
172
+ * @returns The server's `connection.ok` event, or `undefined` when the long-poll is already
173
+ * connecting or connected.
236
174
  */
237
175
  async connect(timeout?: number): ConnectAPIResponse {
238
- // if fallback is used before, continue using it instead of waiting for WS to fail
176
+ // Once switched, stay on the long-poll.
239
177
  if (this.fallback) {
240
178
  return await this.fallback.connect();
241
179
  }
@@ -243,19 +181,12 @@ export class WSConnection extends WithSubscriptions {
243
181
  const next = this.buildConnection();
244
182
  const previous = this.connection;
245
183
 
246
- // Close the socket being replaced. Without this it is abandoned rather than shut down: nothing
247
- // else clears its ping and connection-check timers, and only `disconnect()` sets
248
- // `isDisconnected`, which is the flag `_reconnect()` checks before giving up. So the old socket
249
- // stayed live and kept reconnecting *alongside* the new one — two sockets, two ping loops, and
250
- // whichever answered last winning the client's status.
251
- //
252
- // Safe here because `openConnection()` has already returned early if a healthy connection exists
253
- // or an attempt is in flight, so anything still held at this point is a socket we are done with.
254
- // Skipped when `buildConnection` hands back the same instance, which it does for an injected one.
184
+ // Close the socket being replaced, else it keeps reconnecting alongside the new one (only
185
+ // `disconnect()` sets `isDisconnected`, which `_reconnect()` checks). Safe: `openConnection()`
186
+ // returns early while a healthy connection exists or an attempt is in flight.
255
187
  if (previous && previous !== next) {
256
- // Fire and forget: the parts that neutralise it — bumping `wsID`, clearing the timers, setting
257
- // `isDisconnected` — all happen synchronously, and only the socket close is awaited. Errors are
258
- // swallowed deliberately; this socket is being discarded either way.
188
+ // Fire and forget: the neutralising steps (`wsID`, timers, `isDisconnected`) run synchronously.
189
+ // Errors are ignored since the socket is discarded either way.
259
190
  void Promise.resolve(previous.disconnect()).catch((error) => {
260
191
  logger
261
192
  .withExtraTags('wsConnection')
@@ -268,13 +199,10 @@ export class WSConnection extends WithSubscriptions {
268
199
  this.connection = next;
269
200
 
270
201
  try {
271
- // Left to the socket to default from `config.connectTimeoutMs`, so the value lives in one place.
272
202
  return await next.connect(timeout);
273
203
  } catch (error) {
274
- // run fallback only if it's WS/Network error and not a normal API error
275
- // make sure the device is online before even trying the longpoll. The default reporter on
276
- // hosts without a network API mirrors the WebSocket, so its "offline" only means the socket
277
- // is down, and is ignored.
204
+ // Fall back only on a WS/network error, and not when the device is offline. The socket-mirroring
205
+ // default reporter's "offline" only means the socket is down, so it is ignored.
278
206
  const { networkConnection } = this.client;
279
207
  const isDeviceOffline =
280
208
  networkConnection.isOnline === false &&
@@ -296,7 +224,7 @@ export class WSConnection extends WithSubscriptions {
296
224
  return await this.fallback.connect();
297
225
  }
298
226
 
299
- // A failure the socket does not retry leaves nothing else to settle the pending connection id.
227
+ // A failure the socket does not retry must settle the pending connection ID.
300
228
  if (!isWSFailure(error as APIError)) {
301
229
  this.client.connectionIdManager.rejectConnectionId(error);
302
230
  }
@@ -304,10 +232,7 @@ export class WSConnection extends WithSubscriptions {
304
232
  }
305
233
  }
306
234
 
307
- /**
308
- * `config.connection` lets a caller supply a pre-built socket — used by unit tests, and the reason
309
- * `StableWSConnection` accepts a parent through `setWSConnection` as well as its constructor.
310
- */
235
+ /** Uses the pre-built `config.connection` when given (and `client.node`), else builds a socket. */
311
236
  private buildConnection(): StableWSConnection {
312
237
  const injected = this.config.connection;
313
238
 
@@ -320,13 +245,14 @@ export class WSConnection extends WithSubscriptions {
320
245
  }
321
246
 
322
247
  /**
323
- * Closes the socket and, after an `enableWSFallback` switch, the long-poll too, telling the
324
- * server to close its connection id. The long-poll's close request uses `timeout` as its timeout
325
- * (2s when omitted).
248
+ * Closes the socket and, after an `enableWSFallback` switch, the long-poll too, telling the server
249
+ * to close its connection ID.
250
+ *
251
+ * @param timeout - Bounds the socket's close frame and the long-poll's close request, in
252
+ * milliseconds. Defaults to 1s and 2s respectively.
326
253
  */
327
254
  async disconnect(timeout?: number): Promise<void> {
328
- // Read before the socket's `disconnect()` drops it: after a switch it is the long-poll's id,
329
- // which the long-poll's close request has to carry.
255
+ // Read before the socket's `disconnect()` drops it: the long-poll's close request must carry it.
330
256
  const connectionId = this.client.connectionIdManager.connectionId;
331
257
  await Promise.all([
332
258
  this.connection?.disconnect(timeout),
@@ -335,9 +261,8 @@ export class WSConnection extends WithSubscriptions {
335
261
  }
336
262
 
337
263
  /**
338
- * @deprecated Report network status through `client.networkConnection.setStatus(isOnline)` instead,
339
- * or register a listener with `client.networkConnection.setStatusReporter(…)`. Forwarded
340
- * here only because `stream-chat-react-native` calls it directly.
264
+ * @deprecated Use `client.networkConnection.setStatus(isOnline)` or
265
+ * `client.networkConnection.setStatusReporter(…)` instead.
341
266
  */
342
267
  onlineStatusChanged(event: Event): void {
343
268
  this.connection?.onlineStatusChanged(event);
@@ -29,9 +29,8 @@ export class WSConnectionFallback {
29
29
  }
30
30
 
31
31
  /**
32
- * Applies a change in the device's network status. Stands in for v9's `window` online/offline
33
- * listeners: `WSConnection` routes the network-status store here once it has switched to this
34
- * long-poll.
32
+ * Applies a change in the device's network status; `WSConnection` routes the network-status store
33
+ * here once it has switched to this long-poll.
35
34
  *
36
35
  * @internal
37
36
  */
@@ -55,10 +54,10 @@ export class WSConnectionFallback {
55
54
  };
56
55
 
57
56
  /**
58
- * connect try to open a longpoll request
59
- *
60
- * @param reconnect - should be false for first call and true for subsequent calls to keep the connection alive and settle the connect promises
57
+ * Opens a long-poll connection.
61
58
  *
59
+ * @param reconnect - `true` when the long-poll reconnects itself (retries retryable failures and
60
+ * settles the client's pending connect promises); `false` when `WSConnection.connect()` calls it.
62
61
  * @internal
63
62
  */
64
63
  connect = async (reconnect = false) => {
@@ -72,18 +71,18 @@ export class WSConnectionFallback {
72
71
  }
73
72
 
74
73
  this._setState(WSFallbackConnectionState.Connecting);
75
- // Before anything awaits, so a watch issued now waits for this connection's id.
74
+ // Before anything awaits, so a watch issued now waits for this connection's ID.
76
75
  this.client.connectionIdManager.arm();
77
76
  try {
78
77
  const { event } = await this._req<{ event: ConnectionOpen }>(
79
78
  // Authenticated by the request's `Authorization` header, so the message carries only a
80
79
  // placeholder token.
81
80
  { json: this.client._buildWSAuthPayload() },
82
- { timeout: 8000 }, // 8s
81
+ { timeout: 8000 },
83
82
  reconnect,
84
83
  );
85
84
 
86
- // The id is published before the status says the connection is up, as the WebSocket does.
85
+ // Published before the status says the connection is up, as the WebSocket does.
87
86
  this.client.connectionIdManager.resolveConnectionId(event.connection_id);
88
87
  this._setState(WSFallbackConnectionState.Connected);
89
88
  this.client.dispatchEvent(event);
@@ -93,34 +92,27 @@ export class WSConnectionFallback {
93
92
  }
94
93
  return event;
95
94
  } catch (err) {
96
- // `disconnect()` has already set the state of an attempt it cancelled. Overwriting it with
97
- // Closed would let the next online edge in `_applyNetworkStatus` reconnect it.
95
+ // `disconnect()` already set the state of an attempt it cancelled. Overwriting it with Closed
96
+ // would let the next online edge in `_applyNetworkStatus` reconnect it.
98
97
  if (this.state !== WSFallbackConnectionState.Disconnected)
99
98
  this._setState(WSFallbackConnectionState.Closed);
100
- // Nothing retries a failed connect, so fail whatever is waiting for a connection id. A cancel
101
- // comes from `disconnect()`, which leaves them waiting for the next connection instead.
99
+ // Nothing retries a failed connect, so reject the waiters. A cancel (from `disconnect()`)
100
+ // leaves them waiting for the next connection.
102
101
  if (!axios.isCancel(err)) this.client.connectionIdManager.rejectConnectionId(err);
103
102
  throw err;
104
103
  }
105
104
  };
106
105
 
107
- /**
108
- * Whether a connect request is in flight.
109
- *
110
- * @internal
111
- */
106
+ /** @internal */
112
107
  get isConnecting() {
113
108
  return this.state === WSFallbackConnectionState.Connecting;
114
109
  }
115
110
 
116
111
  /**
117
- * Stops polling and tells the server to close `connectionId`.
112
+ * Stops polling and tells the server to close `connectionId`. The ID is passed in because
113
+ * `WSConnection.disconnect()` disconnects the socket first, which drops the manager's ID.
118
114
  *
119
115
  * @param timeout - The close request's timeout, in milliseconds.
120
- * @param connectionId - The id to close. Passed in rather than read from
121
- * `client.connectionIdManager`, because `WSConnection.disconnect()` disconnects the old socket
122
- * first, and that drops the manager's id.
123
- *
124
116
  * @internal
125
117
  */
126
118
  disconnect = async (timeout = 2000, connectionId?: string) => {
@@ -151,7 +143,6 @@ export class WSConnectionFallback {
151
143
  const previous = this.state;
152
144
  this.state = state;
153
145
 
154
- // transition from connecting => connected
155
146
  if (
156
147
  previous === WSFallbackConnectionState.Connecting &&
157
148
  this.state === WSFallbackConnectionState.Connected
@@ -163,7 +154,7 @@ export class WSConnectionFallback {
163
154
  this.state === WSFallbackConnectionState.Closed ||
164
155
  this.state === WSFallbackConnectionState.Disconnected
165
156
  ) {
166
- // The server keyed watches by this connection id, so no request may carry it any more.
157
+ // The server keyed watches by this connection ID, so no request may carry it any more.
167
158
  this.client.connectionIdManager.invalidate();
168
159
  if (this.client.wsConnection._setStatus({ isHealthy: false })) {
169
160
  this.client.channelManager.markChannelsWatchInterrupted();
@@ -186,7 +177,7 @@ export class WSConnectionFallback {
186
177
  signal: this.abortController?.signal,
187
178
  });
188
179
 
189
- this.consecutiveFailures = 0; // always reset in case of no error
180
+ this.consecutiveFailures = 0;
190
181
  // The spec declares no response body, so the generated response type is `{}`.
191
182
  return res as T;
192
183
  } catch (error: any) {
@@ -195,9 +186,9 @@ export class WSConnectionFallback {
195
186
  if (retry && isErrorRetryable(error)) {
196
187
  this._log(`_req() - Retryable error, retrying request`);
197
188
  await sleep(retryInterval(this.consecutiveFailures));
198
- // A reconnect, `disconnect()` or going offline during the sleep dropped the connection id
199
- // this request carries. Sent anyway, it would come back as a ConnectionIDNotFoundError, and
200
- // `_poll` would tear down the connection that replaced it.
189
+ // A reconnect, `disconnect()` or going offline during the sleep dropped this request's
190
+ // connection ID. Sent anyway, its ConnectionIDNotFoundError would make `_poll` tear down the
191
+ // connection that replaced it.
201
192
  if (
202
193
  params.connection_id &&
203
194
  params.connection_id !== this.client.connectionIdManager.connectionId
@@ -236,7 +227,7 @@ export class WSConnectionFallback {
236
227
  return;
237
228
  }
238
229
 
239
- /** client.longPoll's request layer will take care of TOKEN_EXPIRED error */
230
+ // `client.longPoll`'s request layer handles TOKEN_EXPIRED.
240
231
 
241
232
  if (isConnectionIDError(error)) {
242
233
  this._log(`_poll() - ConnectionID error, connecting without ID...`);
@@ -247,7 +238,7 @@ export class WSConnectionFallback {
247
238
 
248
239
  if (isAPIError(error) && !isErrorRetryable(error)) {
249
240
  this._setState(WSFallbackConnectionState.Closed);
250
- // Nothing reconnects from here, so fail whatever is waiting for a connection id.
241
+ // Nothing reconnects from here, so fail whatever is waiting for a connection ID.
251
242
  this.client.connectionIdManager.rejectConnectionId(error);
252
243
  return;
253
244
  }
@@ -1,13 +1,6 @@
1
1
  import { deepFreezeConfig } from '../../configuration/utils/deepFreezeConfig';
2
2
  import type { WSConnectionConfig } from './types';
3
3
 
4
- /**
5
- * The WebSocket's timing defaults.
6
- *
7
- * In a module of their own rather than beside {@link WSConnection} because `StableWSConnection` needs
8
- * them too — as the fallback for when it has no client to read configuration from — and importing them
9
- * from `WSConnection.ts` would close a cycle, since that file imports `StableWSConnection`.
10
- */
11
4
  export const DEFAULT_WS_CONNECTION_CONFIG: WSConnectionConfig = deepFreezeConfig({
12
5
  connectTimeoutMs: 15 * 1000,
13
6
  enableWSFallback: false,
@@ -20,26 +13,16 @@ export const DEFAULT_WS_CONNECTION_CONFIG: WSConnectionConfig = deepFreezeConfig
20
13
  });
21
14
 
22
15
  /**
23
- * How long to wait before retrying once the device reports its network is back.
24
- *
25
- * Deliberately tiny — it short-circuits the randomised backoff, because a network that has just
26
- * returned is the one moment an immediate retry is likely to succeed. Not zero, so the retry lands in
27
- * a later task, after whatever else is reacting to the same edge.
28
- *
29
- * A constant rather than configuration: it was a bare `_reconnect({ interval: 10 })` nothing could
30
- * reach, so exposing it would add surface rather than preserve it.
16
+ * Delay before reconnecting once the device reports its network is back, bypassing the randomised
17
+ * backoff. Not zero, so the retry lands in a later task, after whatever else reacts to the same edge.
31
18
  */
32
19
  export const WS_NETWORK_RECOVERY_RETRY_MS = 10;
33
20
 
34
21
  /**
35
- * Bounds on the timing knobs, applied to every value that reaches the configuration — see
36
- * {@link clampWSConnectionConfig}.
37
- *
38
- * Three of the fields are bounded. Two of them for the same reason: a value outside the range makes
39
- * the socket fail by itself, with no bad network and nothing for the integrator to see but an
40
- * apparently random disconnect. `connectTimeoutMs` is deliberately unbounded — every value of it is a
41
- * legitimate trade-off rather than a self-inflicted failure, and tests set it absurdly low on
42
- * purpose.
22
+ * Bounds applied to the timing knobs by {@link clampWSConnectionConfig}. A ping interval above its
23
+ * max, or a grace period below its min, makes the socket fail by itself, which looks like a random
24
+ * disconnect. The other bounds reject nonsense values. `connectTimeoutMs` is unbounded: every value
25
+ * is a legitimate trade-off.
43
26
  */
44
27
  export const WS_CONNECTION_CONFIG_BOUNDS: {
45
28
  [Key in
@@ -47,37 +30,20 @@ export const WS_CONNECTION_CONFIG_BOUNDS: {
47
30
  | 'offlineNotificationDisplayDelayMs'
48
31
  | 'pingIntervalMs']: { max?: number; min: number };
49
32
  } = {
50
- /**
51
- * A grace period of zero puts the connection check exactly on the moment the next ping is due, so the socket
52
- * declares itself dead on a healthy connection and does it again after every reconnect. A floor of
53
- * 1s is not a judgement about the right value; it is the point below which the loop cannot work.
54
- */
33
+ /** Zero would put the connection check on the next ping's due time and kill a healthy socket. */
55
34
  healthCheckGracePeriodMs: { min: 1_000 },
56
- /** Zero is legitimate — hold nothing back — so the floor only rejects a negative delay. */
35
+ /** Zero holds nothing back; the floor only rejects a negative delay. */
57
36
  offlineNotificationDisplayDelayMs: { min: 0 },
58
37
  /**
59
- * **The maximum is the default**, which means this setting can only ever make the socket ping
60
- * more* often, never less. That is deliberate rather than an oversight: 25s is the interval the
61
- * server is known to be happy with, and a slower ping risks the connection being closed for
62
- * idleness — by Stream, or by whatever load balancers and proxies sit in between — which surfaces
63
- * as an apparently random disconnect rather than as a setting.
64
- *
65
- * So the useful direction is downward: a client on a flaky network can shorten the interval to
66
- * notice a dead socket sooner, since {@link WSConnectionConfig.healthCheckGracePeriodMs} moves the
67
- * connection check along with it.
68
- *
69
- * The floor exists for the opposite hazard: a few-millisecond interval floods the server with
70
- * health checks and earns a rate limit.
38
+ * The maximum is the default: a slower ping risks an idle close by Stream or an intermediary. The
39
+ * floor stops a tiny interval from flooding the server with health checks.
71
40
  */
72
41
  pingIntervalMs: { max: 25 * 1000, min: 1_000 },
73
42
  };
74
43
 
75
44
  /**
76
- * Clamps the timing knobs into {@link WS_CONNECTION_CONFIG_BOUNDS}, returning both the result and
77
- * what had to be moved, so the caller can say so out loud.
78
- *
79
- * Returns the same object reference when nothing is out of range — `ConfigController` skips a write
80
- * that changes nothing, and handing it a fresh equal object on every derivation would defeat that.
45
+ * Clamps the timing knobs into {@link WS_CONNECTION_CONFIG_BOUNDS} and reports what it moved. Returns
46
+ * the same object when nothing is out of range, so `ConfigController` skips the write.
81
47
  */
82
48
  export const clampWSConnectionConfig = (
83
49
  requested: WSConnectionConfig,
@@ -91,8 +57,7 @@ export const clampWSConnectionConfig = (
91
57
  for (const [field, { max, min }] of Object.entries(WS_CONNECTION_CONFIG_BOUNDS)) {
92
58
  const key = field as keyof typeof WS_CONNECTION_CONFIG_BOUNDS;
93
59
  const value = requested[key];
94
- // A non-finite value is out of range in the way that matters — `setTimeout(fn, NaN)` fires
95
- // immediately, so it would spin rather than fail visibly.
60
+ // Non-finite values are out of range too: `setTimeout(fn, NaN)` fires immediately and would spin.
96
61
  const used = !Number.isFinite(value)
97
62
  ? min
98
63
  : Math.min(max ?? Number.POSITIVE_INFINITY, Math.max(min, value));