Skip to content

Commit 3061fd4

Browse files
committed
feat(MonitorScope): add refresh() for force-resubscribe after external write
After an embedded bridge writes events from a different access token, the user's primary connection's socket may miss them (the bridge also creates streams the socket didn't have at attach time). Without an external trigger the new events don't surface until the next visibility- change cycle. refresh() tears down the current Monitor and re-attaches with the latest maxModified. Re-attach catches up via events.get(modifiedSince=…) AND re-subscribes the socket on the now-current stream tree, so any bridge-created stream enters live scope. No-op when stopped or paused; safe to call repeatedly from hds-webapp's hds-bridge-done handler.
1 parent 9e367d1 commit 3061fd4

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

ts/MonitorScope.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,31 @@ export class MonitorScope {
206206
await this.attachLiveMonitor();
207207
}
208208

209+
/**
210+
* Force a live-monitor refresh: tear down the current Monitor (if any)
211+
* and re-attach. The fresh `attachLiveMonitor` re-runs
212+
* `events.get(modifiedSince=maxModified)` to catch up any events the
213+
* socket may have missed, and re-subscribes the socket — picking up
214+
* streams that didn't exist when the previous subscription was
215+
* established (e.g. streams created by an embedded bridge after our
216+
* connection's socket attached).
217+
*
218+
* Use after a known-good external write (e.g. on `hds-bridge-done`
219+
* postMessage) to surface the new events without waiting for the next
220+
* visibility-change cycle or user-driven action.
221+
*
222+
* No-op if already stopped. If currently paused, stays paused.
223+
*/
224+
async refresh (): Promise<void> {
225+
if (this.stopped) return;
226+
if (this.paused) return;
227+
if (this.monitor) {
228+
try { this.monitor.stop(); } catch (_) { /* ignore */ }
229+
this.monitor = null;
230+
}
231+
await this.attachLiveMonitor();
232+
}
233+
209234
/**
210235
* Load older events beyond current scope (triggered by scroll-up).
211236
* Loads pageSize events older than the oldest currently loaded.

0 commit comments

Comments
 (0)