Skip to content

Consolidate smart source websocket subscriptions. (Rebased) - #6029

Open
michelinewu wants to merge 12 commits into
masterfrom
mw_combine_calls_2
Open

Consolidate smart source websocket subscriptions. (Rebased)#6029
michelinewu wants to merge 12 commits into
masterfrom
mw_combine_calls_2

Conversation

@michelinewu

@michelinewu michelinewu commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Consolidate smart source websocket subscriptions

Issue

Each SmartBrowserSourceManager independently subscribed to the websocket and called visionService.ensureRunning() on init. With N smart browser sources active, this created N parallel RxJS subscriptions to the same visionEvent/userStateUpdated events and N redundant Vision startup calls.

Fix

Moved event forwarding and Vision startup out of SmartBrowserSourceManager and into ReactiveDataService, which already held a single socket subscription:

  • ReactiveDataService now forwards visionEvent/userStateUpdated events to every smart source via forwardEventToSources().
  • Vision startup is centralized behind ensureVisionRunning(), which reads isRunning/isStarting from local state and only calls visionService.ensureRunning() when Vision is not already up.
  • SmartBrowserSourceManager loses its own socketSub subscription, its WebsocketService injection, and its destroy() unsubscribe.

Smart-source lookup helpers (SourcesService)

Added two helpers used by the centralized path:

  • hasSmartSources() — cheap existence check (Array.some on propertiesManagerType === 'smartBrowserSource'); used to guard Vision startup on login and on scene-collection switch so we don't start Vision for collections with no smart sources.
  • getSmartSources() — filters the source models by propertiesManagerType before constructing Source instances, so the hot fan-out path (forwardEventToSources, which can fire frequently while live) avoids building Source objects for non-smart sources.

What changed

Area Before After
Socket subscriptions for vision/user-state events N (one per smart source) 1 (in ReactiveDataService)
Event delivery to sources each source subscribes and messages itself one subscription fans out via getSmartSources()obsSource.sendMessage()
visionService.ensureRunning() on startup N (once per source init) guarded; fired at login / collection-switch (only when hasSmartSources()) and on first source registration, skipped when Vision is already running/starting
destroy() / unsubscribe overhead N (one socketSub.unsubscribe() per source) 0

All of the above runs in the worker window — the invisible renderer that hosts the services layer and the OBS backend. WebsocketService, VisionService, SourcesService, and ReactiveDataService are all singleton services, and socketEvent is a plain RxJS Subject on WebsocketService, so these subscriptions and sendMessage() / ensureRunning() calls are in-process RxJS / OBS calls, not per-source IPC. The win is eliminating redundant in-process subscriptions and duplicate Vision startup work, plus a single centralized fan-out — not a reduction in IPC crossings.

Files touched

  • app/services/reactive-data/index.ts — centralized subscription + forwarding, ensureVisionRunning(), forwardEventToSources(), login/collection-switch guards.
  • app/services/sources/properties-managers/smart-browser-source-manager.ts — removed per-source subscription, injection, and destroy().
  • app/services/sources/sources.ts — added getSmartSources() and hasSmartSources().

@bundlemon

bundlemon Bot commented Jul 17, 2026

Copy link
Copy Markdown

BundleMon

Files updated (1)
Status Path Size Limits
renderer.(hash).js
7.86MB (-251B 0%) -
Unchanged files (3)
Status Path Size Limits
vendors~renderer.(hash).js
4.67MB -
updater.js
115.29KB -
guest-api.js
40.23KB -

Total files change -251B 0%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Comment thread app/services/reactive-data/index.ts Outdated
Comment thread app/services/reactive-data/index.ts Outdated
Comment thread app/services/reactive-data/index.ts Outdated
Comment thread app/services/reactive-data/index.ts Outdated
michelinewu and others added 3 commits July 17, 2026 17:25
Co-authored-by: Wes Rupert <wesrupert@users.noreply.github.com>
Co-authored-by: Wes Rupert <wesrupert@users.noreply.github.com>
Co-authored-by: Wes Rupert <wesrupert@users.noreply.github.com>
@michelinewu
michelinewu requested a review from wesrupert July 17, 2026 21:29
UserService,
WebsocketService,
} from 'app-services';
import { VisionService } from 'services/vision';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { VisionService } from 'services/vision';

Comment thread app/services/reactive-data/index.ts Outdated
Co-authored-by: Wes Rupert <wesrupert@users.noreply.github.com>
@michelinewu
michelinewu requested a review from wesrupert July 17, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants