Skip to content

Commit

Permalink
Merge branch 'staging' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
SLOBS-Release committed Jul 12, 2022
2 parents 548212a + 998b415 commit 824872c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 22 deletions.
2 changes: 0 additions & 2 deletions app/components-react/windows/GuestCamProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,12 @@ export default function GuestCamProperties() {
options={videoSources}
value={videoSourceId}
onChange={s => GuestCamService.actions.setVideoSource(s)}
allowClear={true}
/>
<ListInput
label={$t('Microphone Source')}
options={audioSources}
value={audioSourceId}
onChange={s => GuestCamService.actions.setAudioSource(s)}
allowClear={true}
/>
</Form>
{(!videoSourceExists || !audioSourceExists) && (
Expand Down
48 changes: 28 additions & 20 deletions app/services/guest-cam/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -202,7 +195,7 @@ class GuestCamViews extends ViewHandler<IGuestCamServiceState> {
}

@InitAfter('SceneCollectionsService')
export class GuestCamService extends PersistentStatefulService<IGuestCamServiceState> {
export class GuestCamService extends StatefulService<IGuestCamServiceState> {
@Inject() userService: UserService;
@Inject() sourcesService: SourcesService;
@Inject() scenesService: ScenesService;
Expand All @@ -214,7 +207,7 @@ export class GuestCamService extends PersistentStatefulService<IGuestCamServiceS
@Inject() urlService: UrlService;
@Inject() streamingService: StreamingService;

static defaultState: IGuestCamServiceState = {
static initialState: IGuestCamServiceState = {
produceOk: false,
videoSourceId: '',
audioSourceId: '',
Expand Down Expand Up @@ -252,11 +245,6 @@ export class GuestCamService extends PersistentStatefulService<IGuestCamServiceS
init() {
super.init();

// TODO: Add setting that allows auto-starting producer?
this.SET_PRODUCE_OK(false);
this.SET_INVITE_HASH('');
this.SET_GUEST(null);

if (this.views.sourceId) {
this.startListeningForGuests();
}
Expand Down Expand Up @@ -289,7 +277,10 @@ export class GuestCamService extends PersistentStatefulService<IGuestCamServiceS
}
});

this.sceneCollectionsService.collectionInitialized.subscribe(() => {
// 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();
});

Expand All @@ -301,7 +292,10 @@ export class GuestCamService extends PersistentStatefulService<IGuestCamServiceS
}

findDefaultSources() {
if (!this.state.audioSourceId) {
if (
!this.state.audioSourceId ||
!this.sourcesService.views.getSource(this.state.audioSourceId)
) {
// Check input channels first
let audioSource = [
E_AUDIO_CHANNELS.INPUT_1,
Expand All @@ -326,7 +320,10 @@ export class GuestCamService extends PersistentStatefulService<IGuestCamServiceS
if (audioSource) this.SET_AUDIO_SOURCE(audioSource.sourceId);
}

if (!this.state.videoSourceId) {
if (
!this.state.videoSourceId ||
!this.sourcesService.views.getSource(this.state.videoSourceId)
) {
const sourceType = byOS({ [OS.Windows]: 'dshow_input', [OS.Mac]: 'av_capture_input' });
const videoSource = this.sourcesService.views.sources.find(s => s.type === sourceType);

Expand All @@ -340,6 +337,7 @@ export class GuestCamService extends PersistentStatefulService<IGuestCamServiceS
this.socket.emit('message', {
type: 'streamingStatusChange',
live: this.streamingService.views.streamingStatus === EStreamingState.Live,
chatUrl: this.streamingService.views.chatUrl,
});
}

Expand Down Expand Up @@ -756,13 +754,23 @@ export class GuestCamService extends PersistentStatefulService<IGuestCamServiceS
}

setVideoSource(sourceId: string) {
if (!this.sourcesService.views.getSource(sourceId)) return;

this.SET_VIDEO_SOURCE(sourceId);
this.ensureSourceAndFilters();

if (this.producer && this.views.sourceId) {
this.ensureSourceAndFilters();
}
}

setAudioSource(sourceId: string) {
if (!this.sourcesService.views.getSource(sourceId)) return;

this.SET_AUDIO_SOURCE(sourceId);
this.ensureSourceAndFilters();

if (this.producer && this.views.sourceId) {
this.ensureSourceAndFilters();
}
}

@mutation()
Expand Down
26 changes: 26 additions & 0 deletions app/services/scene-collections/nodes/guest-cam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { GuestCamService } from 'app-services';
import { Inject } from 'services/core';
import { Node } from './node';

interface ISchema {
audioSourceId: string;
videoSourceId: string;
}

export class GuestCamNode extends Node<ISchema, {}> {
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);
}
}
10 changes: 10 additions & 0 deletions app/services/scene-collections/nodes/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -19,6 +20,8 @@ interface ISchema {
hotkeys?: HotkeysNode;
transitions?: TransitionsNode; // V2 Transitions

guestCam?: GuestCamNode;

operatingSystem?: OS;
}

Expand All @@ -34,17 +37,20 @@ export class RootNode extends Node<ISchema, {}> {
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,
Expand All @@ -62,6 +68,10 @@ export class RootNode extends Node<ISchema, {}> {
if (this.data.hotkeys) {
await this.data.hotkeys.load({});
}

if (this.data.guestCam) {
await this.data.guestCam.load();
}
}

migrate(version: number) {
Expand Down
2 changes: 2 additions & 0 deletions app/services/scene-collections/scene-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -49,6 +50,7 @@ export const NODE_TYPES = {
TransitionsNode,
HotkeysNode,
SceneFiltersNode,
GuestCamNode,
TransitionNode: TransitionsNode, // Alias old name to new node
};

Expand Down

0 comments on commit 824872c

Please sign in to comment.