Skip to content

Commit

Permalink
Merge pull request #97 from tv2/UT-258/fixChannelViewBug
Browse files Browse the repository at this point in the history
fix: fixes channelview 2 and above not working
  • Loading branch information
andr9528 committed Sep 20, 2023
2 parents 5e086e0 + a54ae6d commit b864182
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
31 changes: 31 additions & 0 deletions src/client/shared/services/browser-service.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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.setMinimumOutputSettingsIfMissing()
}

private getCurrentSelectedView(
Expand Down Expand Up @@ -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.
* 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 setMinimumOutputSettingsIfMissing() {
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
Expand Down
9 changes: 6 additions & 3 deletions src/shared/reducers/settings-reducer.ts
Original file line number Diff line number Diff line change
@@ -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: [],
Expand All @@ -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),
]
Expand Down
4 changes: 2 additions & 2 deletions src/shared/services/redux-settings-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
}
Expand Down

0 comments on commit b864182

Please sign in to comment.