From 94d3d8476c1f09c6f211699a30ef438447c986cc Mon Sep 17 00:00:00 2001 From: andr9528 Date: Wed, 20 Sep 2023 14:36:56 +0200 Subject: [PATCH 1/2] fix: fixes channelview 2 and above not working --- src/client/shared/services/browser-service.ts | 31 +++++++++++++++++++ src/shared/reducers/settings-reducer.ts | 9 ++++-- src/shared/services/redux-settings-service.ts | 4 +-- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/client/shared/services/browser-service.ts b/src/client/shared/services/browser-service.ts index a117363b..ebd7c1ee 100644 --- a/src/client/shared/services/browser-service.ts +++ b/src/client/shared/services/browser-service.ts @@ -1,3 +1,7 @@ +import { ReduxSettingsService } from '../../../shared/services/redux-settings-service' +import { reduxStore, state } from '../../../shared/store' +import { setGenerics } from '../../../shared/actions/settings-action' + enum SelectedView { THUMBNAIL = 'thumbnail', TEXT = 'textview', @@ -12,10 +16,13 @@ interface BrowserSelectedView { export class BrowserService { private view: BrowserSelectedView + private readonly reduxSettingsService: ReduxSettingsService constructor() { + this.reduxSettingsService = new ReduxSettingsService() const search = new URLSearchParams(window.location.search) this.view = this.getCurrentSelectedView(search) + this.temporarilyEnsureSufficientOutputSettingsExist() } private getCurrentSelectedView( @@ -48,6 +55,30 @@ export class BrowserService { } } + /** + * @remarks + * The Redux state is only initialized with 1 output settings, which causes issues for channel view above 1. + * Ones finished connecting to the backend, the actual settings will have been received. + * Until then simply set the redux state to contain default settings, with entries matching the channel number. + * @private + */ + private temporarilyEnsureSufficientOutputSettingsExist() { + if ( + !this.isChannelView() || + this.reduxSettingsService.getAllOutputSettings(state.settings) + .length >= this.view.channel + ) { + return + } + reduxStore.dispatch( + setGenerics( + this.reduxSettingsService.getDefaultGenericSettings( + this.view.channel + ) + ) + ) + } + private getQueryChannel(search: URLSearchParams): number { const channel = search.get(SelectedView.CHANNEL) return channel ? Math.max(parseInt(channel), 1) : 1 diff --git a/src/shared/reducers/settings-reducer.ts b/src/shared/reducers/settings-reducer.ts index 35016d08..0f65221d 100644 --- a/src/shared/reducers/settings-reducer.ts +++ b/src/shared/reducers/settings-reducer.ts @@ -1,14 +1,17 @@ import { + CasparcgConfig, CasparcgConfigChannel, + GenericSettings, OutputSettings, SettingsState, -} from './../models/settings-models' +} from '../models/settings-models' import { ReduxSettingsService } from '../services/redux-settings-service' import { getVideoFormat } from '../video-format' import * as IO from './../actions/settings-action' function defaultSettingsReducerState(): SettingsState { - const generics = new ReduxSettingsService().getDefaultGenericSettings() + const generics: GenericSettings = + new ReduxSettingsService().getDefaultGenericSettings() return { ccgConfig: { channels: [], @@ -35,7 +38,7 @@ export function settings( switch (action.type) { case IO.UPDATE_SETTINGS: { - const config = { ...nextState.ccgConfig } + const config: CasparcgConfig = { ...nextState.ccgConfig } config.channels = [ ...action.channels.map(updateChannelConfigWithVideoFormat), ] diff --git a/src/shared/services/redux-settings-service.ts b/src/shared/services/redux-settings-service.ts index 354be237..b0b3b2da 100644 --- a/src/shared/services/redux-settings-service.ts +++ b/src/shared/services/redux-settings-service.ts @@ -125,10 +125,10 @@ export class ReduxSettingsService { return settingsState.generics } - public getDefaultGenericSettings(): GenericSettings { + public getDefaultGenericSettings(arrayLength: number = 1): GenericSettings { return { ccgSettings: defaultCcgSettingsState, - outputSettings: Array(1).fill({ + outputSettings: Array(arrayLength).fill({ ...defaultOutputSettingsState, }), } From a54ae6da7a5d4c78b29f68dd8e39552dfbd99d57 Mon Sep 17 00:00:00 2001 From: andr9528 Date: Wed, 20 Sep 2023 15:16:05 +0200 Subject: [PATCH 2/2] refactor: renames method to a less hacky sounding one, and fixes a typo. --- src/client/shared/services/browser-service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/shared/services/browser-service.ts b/src/client/shared/services/browser-service.ts index ebd7c1ee..11243fe4 100644 --- a/src/client/shared/services/browser-service.ts +++ b/src/client/shared/services/browser-service.ts @@ -22,7 +22,7 @@ export class BrowserService { this.reduxSettingsService = new ReduxSettingsService() const search = new URLSearchParams(window.location.search) this.view = this.getCurrentSelectedView(search) - this.temporarilyEnsureSufficientOutputSettingsExist() + this.setMinimumOutputSettingsIfMissing() } private getCurrentSelectedView( @@ -58,11 +58,11 @@ export class BrowserService { /** * @remarks * The Redux state is only initialized with 1 output settings, which causes issues for channel view above 1. - * Ones finished connecting to the backend, the actual settings will have been received. + * Once finished connecting to the backend, the actual settings will have been received. * Until then simply set the redux state to contain default settings, with entries matching the channel number. * @private */ - private temporarilyEnsureSufficientOutputSettingsExist() { + private setMinimumOutputSettingsIfMissing() { if ( !this.isChannelView() || this.reduxSettingsService.getAllOutputSettings(state.settings)