Skip to content

Commit

Permalink
feat: Implemented type safety for ChannelReducer
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Jan 24, 2024
1 parent a7998dc commit a2c10b5
Show file tree
Hide file tree
Showing 22 changed files with 582 additions and 493 deletions.
6 changes: 4 additions & 2 deletions client/src/components/Labels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
import { ICustomPages } from '../../../shared/src/reducers/settingsReducer'
import { getChannelLabel } from '../utils/labels'
import { flushExtLabels, updateLabels } from '../../../shared/src/actions/faderActions'
import { storeFlushChLabels } from '../../../shared/src/actions/channelActions'
import { ChannelActionTypes, ChannelActions } from '../../../shared/src/actions/channelActions'
import { Dispatch } from '@reduxjs/toolkit'

interface ILabelSettingsInjectProps {
customPages: ICustomPages[]
Expand All @@ -27,6 +28,7 @@ class LabelSettings extends React.PureComponent<
state = {
mutations: {} as Record<string, string>
}
dispatch: Dispatch<ChannelActions> = this.props.dispatch

constructor(props: any) {
super(props)
Expand Down Expand Up @@ -57,7 +59,7 @@ class LabelSettings extends React.PureComponent<
handleFlushLabels() {
if (window.confirm('Flush all external (automation and channel) labels?')) {
this.props.dispatch(flushExtLabels())
this.props.dispatch(storeFlushChLabels())
this.dispatch({ type: ChannelActionTypes.FLUSH_CHANNEL_LABELS })
window.socketIoClient.emit(SOCKET_FLUSH_LABELS)
}
}
Expand Down
25 changes: 14 additions & 11 deletions client/src/utils/SocketClientHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
storeVuReductionLevel,
} from '../../../shared/src/actions/faderActions'
import {
storeSetCompleteChState,
storeSetSingleChState,
ChannelActionTypes,
ChannelActions,
} from '../../../shared/src/actions/channelActions'
import {
storeSetMixerOnline,
Expand All @@ -29,10 +29,12 @@ import {
} from '../../../shared/src/reducers/channelsReducer'
import { VuType } from '../../../shared/src/utils/vu-server-types'
import { IMixerSettings } from '../../../shared/src/reducers/settingsReducer'
import { Dispatch } from '@reduxjs/toolkit'

export const vuMeters: number[][] = []

export const socketClientHandlers = () => {
const dispatch: Dispatch<ChannelActions> = window.storeRedux.dispatch
window.socketIoClient
.on('connect', () => {
window.storeRedux.dispatch(storeSetServerOnline(true))
Expand Down Expand Up @@ -64,12 +66,11 @@ export const socketClientHandlers = () => {
]
}
)
window.storeRedux.dispatch(
storeSetCompleteChState(
payload.channels[0],
numberOfChannels
)
)
dispatch({
type: ChannelActionTypes.SET_COMPLETE_CH_STATE,
numberOfTypeChannels: numberOfChannels,
allState: payload.channels[0],
})
window.storeRedux.dispatch(
storeSetCompleteFaderState(
payload.faders[0],
Expand Down Expand Up @@ -109,9 +110,11 @@ export const socketClientHandlers = () => {
}
})
.on(SOCKET_SET_STORE_CHANNEL, (payload: any) => {
window.storeRedux.dispatch(
storeSetSingleChState(payload.channelIndex, payload.state)
)
dispatch({
type: ChannelActionTypes.SET_SINGLE_CH_STATE,
channelIndex: payload.channelIndex,
state: payload.state,
})
})
.on(SOCKET_RETURN_SNAPSHOT_LIST, (payload: any) => {
window.snapshotFileList = payload
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
]
},
"dependencies": {
"@reduxjs/toolkit": "^2.1.0",
"cross-env": "^7.0.3"
},
"devDependencies": {
Expand All @@ -83,4 +84,4 @@
"xml2js": "^0.5.0",
"socket.io-parser": "^4.2.3"
}
}
}
40 changes: 19 additions & 21 deletions server/src/MainThreadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { socketServer } from './expressHandler'
import { storeUpdateSettings } from '../../shared/src/actions/settingsActions'
import * as IO from '../../shared/src/constants/SOCKET_IO_DISPATCHERS'
import * as FADER_ACTIONS from '../../shared/src/actions/faderActions'
import * as CHANNEL_ACTIONS from '../../shared/src/actions/channelActions'
import { ChannelActionTypes, ChannelActions } from '../../shared/src/actions/channelActions'

import {
loadSettings,
Expand All @@ -25,19 +25,17 @@ import {
STORAGE_FOLDER,
} from './utils/SettingsStorage'

import {
storeFlushChLabels,
storeSetAuxLevel,
} from '../../shared/src/actions/channelActions'
import { logger } from './utils/logger'
import { ICustomPages } from '../../shared/src/reducers/settingsReducer'
import { fxParamsList } from '../../shared/src/constants/MixerProtocolInterface'
import path from 'path'
import { IChannel } from '../../shared/src/reducers/channelsReducer'
import { IChannelReference } from '../../shared/src/reducers/fadersReducer'
import { Dispatch } from '@reduxjs/toolkit'

export class MainThreadHandlers {
snapshotHandler: SnapshotHandler
dispatch: Dispatch<ChannelActions> = store.dispatch

constructor() {
logger.info('Setting up MainThreadHandlers')
Expand Down Expand Up @@ -85,13 +83,12 @@ export class MainThreadHandlers {
})
state.faders[0].fader.forEach((fader, faderIndex) => {
fader.assignedChannels?.forEach((channel: IChannelReference) => {
store.dispatch(
CHANNEL_ACTIONS.storeSetAssignedFader(
channel.mixerIndex,
channel.channelIndex,
faderIndex
)
)
this.dispatch({
type: ChannelActionTypes.SET_ASSIGNED_FADER,
mixerIndex: channel.mixerIndex,
channel: channel.channelIndex,
faderNumber: faderIndex,
})
})
})
}
Expand Down Expand Up @@ -294,14 +291,13 @@ export class MainThreadHandlers {
logger.trace(
`Set Auxlevel Channel: ${payload.channel} Auxindex : ${payload.auxIndex} level : ${payload.level}`
)
store.dispatch(
storeSetAuxLevel(
0,
payload.channel,
payload.auxIndex,
payload.level
)
)
this.dispatch({
type: ChannelActionTypes.SET_AUX_LEVEL,
mixerIndex: 0,
channel: payload.channel,
auxIndex: payload.auxIndex,
level: payload.level,
})
mixerGenericConnection.updateAuxLevel(
payload.channel,
payload.auxIndex
Expand Down Expand Up @@ -438,7 +434,9 @@ export class MainThreadHandlers {
})
.on(IO.SOCKET_FLUSH_LABELS, () => {
store.dispatch(FADER_ACTIONS.flushExtLabels())
store.dispatch(storeFlushChLabels())
this.dispatch({
type: ChannelActionTypes.FLUSH_CHANNEL_LABELS,
})
})
}
}
74 changes: 44 additions & 30 deletions server/src/utils/MixerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ import { LawoRubyMixerConnection } from './mixerConnections/LawoRubyConnection'
import { StuderMixerConnection } from './mixerConnections/StuderMixerConnection'
import { StuderVistaMixerConnection } from './mixerConnections/StuderVistaMixerConnection'
import { CasparCGConnection } from './mixerConnections/CasparCGConnection'
import { IchMixerConnection } from '../../../shared/src/reducers/channelsReducer'
import {
IchMixerConnection,
} from '../../../shared/src/reducers/channelsReducer'
import {
storeFadeActive,
storeSetOutputLevel,
ChannelActionTypes,
ChannelActions,
} from '../../../shared/src/actions/channelActions'
import { storeFaderLevel } from '../../../shared/src/actions/faderActions'
import { AtemMixerConnection } from './mixerConnections/AtemConnection'
import { IChannelReference } from '../../../shared/src/reducers/fadersReducer'
import { Dispatch } from 'redux'

export class MixerGenericConnection {
store: any
dispatch: Dispatch<ChannelActions> = store.dispatch
mixerProtocol: IMixerProtocolGeneric[]
mixerConnection: any[]
mixerTimers: {
Expand All @@ -47,7 +46,7 @@ export class MixerGenericConnection {
state.settings[0].mixers.forEach((none: any, index: number) => {
this.mixerProtocol.push(
MixerProtocolPresets[
state.settings[0].mixers[index].mixerProtocol
state.settings[0].mixers[index].mixerProtocol
] || MixerProtocolPresets.sslSystemT
)
this.mixerConnection.push({})
Expand Down Expand Up @@ -140,7 +139,12 @@ export class MixerGenericConnection {
delayedFadeActiveDisable = (mixerIndex: number, channelIndex: number) => {
this.mixerTimers[mixerIndex].fadeActiveTimer[channelIndex] = setTimeout(
() => {
store.dispatch(storeFadeActive(mixerIndex, channelIndex, false))
this.dispatch({
type: ChannelActionTypes.FADE_ACTIVE,
mixerIndex: mixerIndex,
channel: channelIndex,
active: false,
})
},
state.settings[0].mixers[0].protocolLatency
)
Expand Down Expand Up @@ -201,15 +205,14 @@ export class MixerGenericConnection {
}
}


state.faders[0].fader[faderIndex].assignedChannels?.forEach(
(assignedChannel: IChannelReference) => {
if (assignedChannel.mixerIndex !== mixerIndexToSkip) {
this.fadeInOut(
assignedChannel.mixerIndex,
assignedChannel.channelIndex,
faderIndex,
fadeTime,
fadeTime
)
}
}
Expand All @@ -227,10 +230,9 @@ export class MixerGenericConnection {
let level = state.faders[0].fader[faderIndex].inputGain
state.faders[0].fader[faderIndex].assignedChannels?.forEach(
(assignedChannel: IChannelReference) => {
this.mixerConnection[assignedChannel.mixerIndex].updateInputGain(
assignedChannel.channelIndex,
level,
)
this.mixerConnection[
assignedChannel.mixerIndex
].updateInputGain(assignedChannel.channelIndex, level)
}
)
}
Expand All @@ -240,9 +242,11 @@ export class MixerGenericConnection {
logger.trace(`${faderIndex} ${inputSelected}`)
state.faders[0].fader[faderIndex].assignedChannels?.forEach(
(assignedChannel: IChannelReference) => {
this.mixerConnection[assignedChannel.mixerIndex].updateInputSelector(
this.mixerConnection[
assignedChannel.mixerIndex
].updateInputSelector(
assignedChannel.channelIndex,
inputSelected,
inputSelected
)
}
)
Expand All @@ -256,9 +260,11 @@ export class MixerGenericConnection {
state.faders[0].fader[faderIndex].assignedChannels?.forEach(
(assignedChannel: IChannelReference) => {
if (assignedChannel.mixerIndex !== mixerIndexToSkip) {
this.mixerConnection[assignedChannel.mixerIndex].updateMuteState(
this.mixerConnection[
assignedChannel.mixerIndex
].updateMuteState(
assignedChannel.channelIndex,
state.faders[0].fader[faderIndex].muteOn,
state.faders[0].fader[faderIndex].muteOn
)
}
}
Expand All @@ -268,9 +274,11 @@ export class MixerGenericConnection {
updateAMixState = (faderIndex: number) => {
state.faders[0].fader[faderIndex].assignedChannels?.forEach(
(assignedChannel: IChannelReference) => {
this.mixerConnection[assignedChannel.mixerIndex].updateAMixState(
this.mixerConnection[
assignedChannel.mixerIndex
].updateAMixState(
assignedChannel.channelIndex,
state.faders[0].fader[faderIndex].amixOn,
state.faders[0].fader[faderIndex].amixOn
)
}
)
Expand All @@ -290,7 +298,7 @@ export class MixerGenericConnection {
(assignedChannel: IChannelReference) => {
this.mixerConnection[assignedChannel.mixerIndex].updateNextAux(
assignedChannel.channelIndex,
level,
level
)
}
)
Expand All @@ -303,7 +311,7 @@ export class MixerGenericConnection {
this.mixerConnection[assignedChannel.mixerIndex].updateFx(
fxParam,
assignedChannel.channelIndex,
level,
level
)
}
)
Expand Down Expand Up @@ -375,7 +383,7 @@ export class MixerGenericConnection {
)
this.clearTimer(mixerIndex, channelIndex)
}
store.dispatch(storeFadeActive(mixerIndex, channelIndex, true))
this.dispatch({type: ChannelActionTypes.FADE_ACTIVE, mixerIndex: mixerIndex, channel: channelIndex, active: true})
if (
state.faders[0].fader[faderIndex].pgmOn ||
state.faders[0].fader[faderIndex].voOn
Expand Down Expand Up @@ -458,26 +466,32 @@ export class MixerGenericConnection {
endLevel
)
this.clearTimer(mixerIndex, channelIndex)
store.dispatch(
storeSetOutputLevel(mixerIndex, channelIndex, endLevel)
)
this.dispatch({
type: ChannelActionTypes.SET_OUTPUT_LEVEL,
mixerIndex: mixerIndex,
channel: channelIndex,
level: endLevel,
})
this.delayedFadeActiveDisable(mixerIndex, channelIndex)
return true
}

const currentOutputLevel =
startLevel +
(endLevel - startLevel) *
Math.max(0, Math.min(1, elapsedTimeMS / fadeTime))
Math.max(0, Math.min(1, elapsedTimeMS / fadeTime))

this.mixerConnection[mixerIndex].updateFadeIOLevel(
channelIndex,
currentOutputLevel
)

store.dispatch(
storeSetOutputLevel(mixerIndex, channelIndex, currentOutputLevel)
)
this.dispatch({
type: ChannelActionTypes.SET_OUTPUT_LEVEL,
mixerIndex: mixerIndex,
channel: channelIndex,
level: currentOutputLevel,
})
}

fadeDown = (mixerIndex: number, channelIndex: number, fadeTime: number) => {
Expand Down
Loading

0 comments on commit a2c10b5

Please sign in to comment.