From 998b415d70775f66dc20ff8a445d19a9f5a8be1b Mon Sep 17 00:00:00 2001 From: Andy Creeth Date: Tue, 12 Jul 2022 14:52:26 -0700 Subject: [PATCH] Collab cam more changes (#4219) * emit chat url * persist webcam/mic settings in scene collection * properly save guest cam * fix saving * add guest cam node to list of node types * fix scene collection loading --- .../windows/GuestCamProperties.tsx | 2 - app/services/guest-cam/index.ts | 48 +++++++++++-------- .../scene-collections/nodes/guest-cam.ts | 26 ++++++++++ app/services/scene-collections/nodes/root.ts | 10 ++++ .../scene-collections/scene-collections.ts | 2 + 5 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 app/services/scene-collections/nodes/guest-cam.ts diff --git a/app/components-react/windows/GuestCamProperties.tsx b/app/components-react/windows/GuestCamProperties.tsx index 7dcce4d8b118..f0e022f27399 100644 --- a/app/components-react/windows/GuestCamProperties.tsx +++ b/app/components-react/windows/GuestCamProperties.tsx @@ -177,14 +177,12 @@ export default function GuestCamProperties() { options={videoSources} value={videoSourceId} onChange={s => GuestCamService.actions.setVideoSource(s)} - allowClear={true} /> GuestCamService.actions.setAudioSource(s)} - allowClear={true} /> {(!videoSourceExists || !audioSourceExists) && ( diff --git a/app/services/guest-cam/index.ts b/app/services/guest-cam/index.ts index b7e01fe12f57..51244a2907a7 100644 --- a/app/services/guest-cam/index.ts +++ b/app/services/guest-cam/index.ts @@ -1,13 +1,6 @@ import { authorizedHeaders, jfetch } from 'util/requests'; import { importSocketIOClient } from 'util/slow-imports'; -import { - InitAfter, - Inject, - mutation, - PersistentStatefulService, - Service, - ViewHandler, -} from 'services/core'; +import { InitAfter, Inject, mutation, StatefulService, Service, ViewHandler } from 'services/core'; import { UserService } from 'services/user'; import uuid from 'uuid/v4'; import { SourcesService } from 'services/sources'; @@ -202,7 +195,7 @@ class GuestCamViews extends ViewHandler { } @InitAfter('SceneCollectionsService') -export class GuestCamService extends PersistentStatefulService { +export class GuestCamService extends StatefulService { @Inject() userService: UserService; @Inject() sourcesService: SourcesService; @Inject() scenesService: ScenesService; @@ -214,7 +207,7 @@ export class GuestCamService extends PersistentStatefulService { + // Make sure we do this after every single load of the scene collection. + // This will ensure that if the scene collection did not contain valid + // sources, we will choose the best ones we can. + this.sceneCollectionsService.collectionSwitched.subscribe(() => { this.findDefaultSources(); }); @@ -301,7 +292,10 @@ export class GuestCamService extends PersistentStatefulService s.type === sourceType); @@ -340,6 +337,7 @@ export class GuestCamService extends PersistentStatefulService { + schemaVersion = 1; + + @Inject() guestCamService: GuestCamService; + + async save() { + this.data = { + audioSourceId: this.guestCamService.state.audioSourceId, + videoSourceId: this.guestCamService.state.videoSourceId, + }; + } + + async load() { + if (this.data.audioSourceId) this.guestCamService.setAudioSource(this.data.audioSourceId); + if (this.data.videoSourceId) this.guestCamService.setVideoSource(this.data.videoSourceId); + } +} diff --git a/app/services/scene-collections/nodes/root.ts b/app/services/scene-collections/nodes/root.ts index 0a255d83a595..1489eea4951a 100644 --- a/app/services/scene-collections/nodes/root.ts +++ b/app/services/scene-collections/nodes/root.ts @@ -7,6 +7,7 @@ import { Inject } from 'services/core'; import { VideoService } from 'services/video'; import { StreamingService } from 'services/streaming'; import { OS } from 'util/operating-systems'; +import { GuestCamNode } from './guest-cam'; interface ISchema { baseResolution: { @@ -19,6 +20,8 @@ interface ISchema { hotkeys?: HotkeysNode; transitions?: TransitionsNode; // V2 Transitions + guestCam?: GuestCamNode; + operatingSystem?: OS; } @@ -34,17 +37,20 @@ export class RootNode extends Node { const scenes = new ScenesNode(); const transitions = new TransitionsNode(); const hotkeys = new HotkeysNode(); + const guestCam = new GuestCamNode(); await sources.save({}); await scenes.save({}); await transitions.save(); await hotkeys.save({}); + await guestCam.save(); this.data = { sources, scenes, transitions, hotkeys, + guestCam, baseResolution: this.videoService.baseResolution, selectiveRecording: this.streamingService.state.selectiveRecording, operatingSystem: process.platform as OS, @@ -62,6 +68,10 @@ export class RootNode extends Node { if (this.data.hotkeys) { await this.data.hotkeys.load({}); } + + if (this.data.guestCam) { + await this.data.guestCam.load(); + } } migrate(version: number) { diff --git a/app/services/scene-collections/scene-collections.ts b/app/services/scene-collections/scene-collections.ts index 07e4506a88cc..e9f8e634d385 100644 --- a/app/services/scene-collections/scene-collections.ts +++ b/app/services/scene-collections/scene-collections.ts @@ -38,6 +38,7 @@ import { byOS, OS, getOS } from 'util/operating-systems'; import Utils from 'services/utils'; import { OutputSettingsService } from '../settings'; import * as remote from '@electron/remote'; +import { GuestCamNode } from './nodes/guest-cam'; const uuid = window['require']('uuid/v4'); @@ -49,6 +50,7 @@ export const NODE_TYPES = { TransitionsNode, HotkeysNode, SceneFiltersNode, + GuestCamNode, TransitionNode: TransitionsNode, // Alias old name to new node };