@@ -3,8 +3,82 @@ package io.getstream.android.core.api.watcher
33import io.getstream.android.core.annotations.StreamInternalApi
44import io.getstream.android.core.api.model.StreamCid
55
6+ /* *
7+ * Callback interface invoked when watched resources need to be re-subscribed after a connection
8+ * state change.
9+ *
10+ * This functional interface is used with [StreamCidWatcher] to receive notifications when the
11+ * WebSocket connection state changes (especially during reconnections), allowing the product SDK
12+ * to re-establish server-side watches for all actively monitored resources.
13+ *
14+ * ## When This Is Called
15+ *
16+ * The callback is triggered on every [StreamConnectionState.Connected] event when the watched
17+ * CID registry is non-empty. This ensures that all active subscriptions are restored after:
18+ * - Initial connection establishment
19+ * - Network reconnection after temporary disconnection
20+ * - WebSocket recovery after connection loss
21+ *
22+ * ## Threading
23+ *
24+ * - The callback is invoked asynchronously on an internal coroutine scope
25+ * - Implementations should be thread-safe as concurrent invocations are possible
26+ * - Long-running operations should be dispatched to an appropriate dispatcher
27+ *
28+ * ## Error Handling
29+ *
30+ * - Exceptions thrown by this callback are caught and logged by the watcher
31+ * - Errors are also surfaced via [StreamClientListener.onError] for user-level handling
32+ * - A failing callback will not prevent other listeners from being notified
33+ *
34+ * ## Example Usage
35+ *
36+ * ```kotlin
37+ * val watcher = StreamCidWatcher(logger, rewatchManager, clientManager)
38+ *
39+ * // Register a rewatch listener
40+ * watcher.subscribe(
41+ * listener = StreamCidRewatchListener { cids ->
42+ * logger.i { "Re-watching ${cids.size} channels" }
43+ * cids.forEach { cid ->
44+ * // Re-establish server-side watch for each CID
45+ * channelClient.watch(cid)
46+ * }
47+ * }
48+ * )
49+ *
50+ * watcher.start()
51+ * ```
52+ *
53+ * @see StreamCidWatcher Main component that manages the watch registry and triggers callbacks
54+ * @see StreamCid Channel identifier in format "type:id" (e.g., "messaging:general")
55+ */
656@StreamInternalApi
757public fun interface StreamCidRewatchListener {
858
59+ /* *
60+ * Called when watched resources need to be re-subscribed.
61+ *
62+ * This method is invoked with the complete list of [StreamCid]s currently in the watch
63+ * registry whenever the connection state changes to [StreamConnectionState.Connected] and
64+ * the registry is non-empty.
65+ *
66+ * Implementations should iterate over the provided list and re-establish server-side watches
67+ * for each CID to maintain active subscriptions across reconnection cycles.
68+ *
69+ * ## Contract
70+ *
71+ * - The list is never empty when this method is called
72+ * - The list represents a snapshot of the watch registry at the time of invocation
73+ * - Modifications to the list do not affect the internal registry
74+ * - Multiple calls may occur for the same set of CIDs during reconnection scenarios
75+ *
76+ * ## Error Handling
77+ *
78+ * Exceptions thrown by this method are caught, logged, and surfaced via error callbacks.
79+ * The failure of one listener does not prevent other listeners from being notified.
80+ *
81+ * @param list A non-empty list of [StreamCid]s that require re-watching
82+ */
983 public fun onRewatch (list : List <StreamCid >)
1084}
0 commit comments