Skip to content

Commit

Permalink
feat: preparing multiple mixer connections in channel store.
Browse files Browse the repository at this point in the history
chore: refactor channel store with Action Creators for better type safety
  • Loading branch information
olzzon authored and olzzon committed Oct 4, 2020
1 parent 475176a commit c1ba41d
Show file tree
Hide file tree
Showing 22 changed files with 822 additions and 509 deletions.
4 changes: 2 additions & 2 deletions client/components/CcgChannelSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ const mapStateToProps = (
props: any
): IChannelSettingsInjectProps => {
return {
label: state.channels[0].channel[props.channelIndex].label,
label: state.channels[0].channelConnection[0].channel[props.channelIndex].label,
mixerProtocol: state.settings[0].mixerProtocol,
sourceOption: (state.channels[0].channel[props.channelIndex].private ||
sourceOption: (state.channels[0].channelConnection[0].channel[props.channelIndex].private ||
{})['channel_layout'],
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/components/MiniChannel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const mapStateToProps = (state: any, props: any): IChannelInjectProps => {
settings: state.settings[0],
channelType: 0 /* TODO: state.channels[0].channel[props.channelIndex].channelType, */,
channelTypeIndex:
props.faderIndex /* TODO: state.channels[0].channel[props.channelIndex].channelTypeIndex, */,
props.faderIndex /* TODO: state.channels[0].channelConnection[0].channel[props.channelIndex].channelTypeIndex, */,
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Settings extends React.PureComponent<IAppProps & Store, IState> {
}

handleShowAllChannels = () => {
this.props.store.channels[0].channel.forEach(
this.props.store.channels[0].channelConnection[0].channel.forEach(
(channel: any, index: number) => {
this.props.dispatch({
type: SHOW_CHANNEL,
Expand All @@ -140,7 +140,7 @@ class Settings extends React.PureComponent<IAppProps & Store, IState> {
}

handleHideAllChannels = () => {
this.props.store.channels[0].channel.forEach(
this.props.store.channels[0].channelConnection[0].channel.forEach(
(channel: any, index: number) => {
this.props.dispatch({
type: SHOW_CHANNEL,
Expand Down
23 changes: 11 additions & 12 deletions client/utils/SocketClientHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
SET_VU_REDUCTION_LEVEL,
} from '../../server/reducers/faderActions'
import {
SET_COMPLETE_CH_STATE,
SET_SINGLE_CH_STATE,
storeSetCompleteChState,
storeSetSingleChState,
} from '../../server/reducers/channelActions'
import {
UPDATE_SETTINGS,
Expand Down Expand Up @@ -55,11 +55,12 @@ export const socketClientHandlers = () => {
)
}
)
window.storeRedux.dispatch({
type: SET_COMPLETE_CH_STATE,
allState: payload.channels[0],
numberOfTypeChannels: numberOfChannels,
})
window.storeRedux.dispatch(
storeSetCompleteChState(
payload.channels[0],
numberOfChannels
)
)
window.storeRedux.dispatch({
type: SET_COMPLETE_FADER_STATE,
allState: payload.faders[0],
Expand Down Expand Up @@ -102,11 +103,9 @@ export const socketClientHandlers = () => {
})
})
.on(SOCKET_SET_STORE_CHANNEL, (payload: any) => {
window.storeRedux.dispatch({
type: SET_SINGLE_CH_STATE,
channelIndex: payload.channelIndex,
state: payload.state,
})
window.storeRedux.dispatch(
storeSetSingleChState(payload.channelIndex, payload.state)
)
})
.on(SOCKET_SET_ALL_VU, (payload: any) => {
payload.vuMeters.forEach((meterLevel: number, index: number) => {
Expand Down
28 changes: 15 additions & 13 deletions server/MainThreadHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ import {
TOGGLE_AMIX,
} from './reducers/faderActions'
import { SET_FADER_LEVEL } from './reducers/faderActions'
import { SET_ASSIGNED_FADER, SET_AUX_LEVEL } from './reducers/channelActions'
import {
storeSetAssignedFader,
storeSetAuxLevel,
} from './reducers/channelActions'
import { IChannel } from './reducers/channelsReducer'
import { logger } from './utils/logger'
const path = require('path')
Expand All @@ -111,7 +114,7 @@ export class MainThreadHandlers {
faderIndex: faderIndex,
state: state.faders[0].fader[faderIndex],
})
state.channels[0].channel.forEach(
state.channels[0].channelConnection[0].channel.forEach(
(channel: IChannel, index: number) => {
if (channel.assignedFader === faderIndex) {
socketServer.emit(SOCKET_SET_STORE_CHANNEL, {
Expand Down Expand Up @@ -216,11 +219,9 @@ export class MainThreadHandlers {
String(payload.faderAssign),
{}
)
store.dispatch({
type: SET_ASSIGNED_FADER,
channel: payload.channel,
faderNumber: payload.faderAssign,
})
store.dispatch(
storeSetAssignedFader(payload.channel, payload.faderAssign)
)
this.updateFullClientStore()
})
.on(SOCKET_SET_FADER_MONITOR, (payload: any) => {
Expand Down Expand Up @@ -251,12 +252,13 @@ export class MainThreadHandlers {
'Set Auxlevel Channel:' + String(payload.channel),
{}
)
store.dispatch({
type: SET_AUX_LEVEL,
channel: payload.channel,
auxIndex: payload.auxIndex,
level: payload.level,
})
store.dispatch(
storeSetAuxLevel(
payload.channel,
payload.auxIndex,
payload.level
)
)
mixerGenericConnection.updateAuxLevel(
payload.channel,
payload.auxIndex
Expand Down
7 changes: 2 additions & 5 deletions server/__tests__/channelReducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
SET_ASSIGNED_FADER,
SET_COMPLETE_CH_STATE,
SET_OUTPUT_LEVEL,
storeSetOutputLevel,
} from '../reducers/channelActions'
import { IChannel } from '../reducers/channelsReducer'

Expand All @@ -22,11 +23,7 @@ describe('Test redux channelReducer actions', () => {
let nextState = JSON.parse(parsedFullStoreJSON)
nextState.channels[0].channel[10].outputLevel = 0.5
expect(
indexReducer(parsedFullStore, {
type: SET_OUTPUT_LEVEL,
channel: 10,
level: '0.5',
})
indexReducer(parsedFullStore, storeSetOutputLevel(10, 0.5))
).toEqual(nextState)
})

Expand Down
70 changes: 70 additions & 0 deletions server/reducers/channelActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,77 @@
import { IChannel, IChannels } from './channelsReducer'

export const SET_OUTPUT_LEVEL = 'SET_OUTPUT_LEVEL'
export const SET_AUX_LEVEL = 'SET_AUX_LEVEL'
export const SET_COMPLETE_CH_STATE = 'SET_COMPLETE_CH_STATE'
export const SET_SINGLE_CH_STATE = 'SET_SINGLE_CH_STATE'
export const FADE_ACTIVE = 'FADE_ACTIVE'
export const SET_ASSIGNED_FADER = 'SET_ASSIGNED_FADER'
export const SET_PRIVATE = 'SET_PRIVATE'

export const storeSetOutputLevel = (channel: number, level: number) => {
return {
type: SET_OUTPUT_LEVEL,
channel: channel,
level: level,
}
}

export const storeSetAuxLevel = (
channel: number,
auxIndex: number,
level: number
) => {
return {
type: SET_AUX_LEVEL,
channel: channel,
auxIndex: auxIndex,
level: level,
}
}

export const storeSetCompleteChState = (
allState: IChannels,
numberOfTypeChannels: number[]
) => {
return {
type: SET_COMPLETE_CH_STATE,
allState: allState,
numberOfTypeChannels: numberOfTypeChannels,
}
}

export const storeSetSingleChState = (
channelIndex: number,
state: IChannel
) => {
return {
type: SET_SINGLE_CH_STATE,
channelIndex: channelIndex,
state: state,
}
}

export const storeFadeActive = (channelIndex: number, active: boolean) => {
return {
type: FADE_ACTIVE,
channel: channelIndex,
active: active,
}
}

export const storeSetAssignedFader = (channel: number, faderNumber: number) => {
return {
type: SET_ASSIGNED_FADER,
channel: channel,
faderNumber: faderNumber,
}
}

export const storeSetChPrivate = (channel: number, tag: string, value: any) => {
return {
type: SET_PRIVATE,
channel: channel,
tag: tag,
value: value,
}
}
64 changes: 46 additions & 18 deletions server/reducers/channelsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import {
} from './channelActions'

export interface IChannels {
channelConnection: IChannelConnections[]
}

export interface IChannelConnections {
channel: Array<IChannel>
}

Expand All @@ -27,14 +31,20 @@ export interface IChannel {
const defaultChannelsReducerState = (numberOfTypeChannels: Array<number>) => {
let defaultObj: Array<IChannels> = [
{
channel: [],
channelConnection: [
{
channel: [],
},
],
},
]

let totalNumberOfChannels = 0
numberOfTypeChannels.forEach((numberOfChannels, typeIndex) => {
for (let index = 0; index < numberOfChannels; index++) {
defaultObj[0].channel[totalNumberOfChannels] = {
defaultObj[0].channelConnection[0].channel[
totalNumberOfChannels
] = {
channelType: typeIndex,
channelTypeIndex: index,
assignedFader: totalNumberOfChannels,
Expand All @@ -54,49 +64,67 @@ export const channels = (
): Array<IChannels> => {
let nextState = [
{
channel: [...state[0].channel],
channelConnection: [...state[0].channelConnection],
},
]

switch (action.type) {
case SET_OUTPUT_LEVEL: //channel: level:
nextState[0].channel[action.channel].outputLevel = parseFloat(
action.level
)
nextState[0].channelConnection[0].channel[
action.channel
].outputLevel = parseFloat(action.level)
return nextState
case SET_COMPLETE_CH_STATE: //allState //numberOfChannels
nextState = defaultChannelsReducerState(action.numberOfTypeChannels)
if (action.allState.channel.length == nextState[0].channel.length) {
if (
action.allState.channel.length ==
nextState[0].channelConnection[0].channel.length
) {
action.allState.channel.forEach(
(channel: any, index: number) => {
if (index < nextState[0].channel.length) {
nextState[0].channel[index] = channel
if (
index <
nextState[0].channelConnection[0].channel.length
) {
nextState[0].channelConnection[0].channel[
index
] = channel
}
}
)
}
return nextState
case SET_SINGLE_CH_STATE: //channelIndex //state
nextState[0].channel[action.channelIndex] = action.state
nextState[0].channelConnection[0].channel[action.channelIndex] =
action.state
return nextState
case FADE_ACTIVE:
nextState[0].channel[action.channel].fadeActive = !!action.active
nextState[0].channelConnection[0].channel[
action.channel
].fadeActive = !!action.active
return nextState
case SET_ASSIGNED_FADER: //channel: faderNumber:
nextState[0].channel[action.channel].assignedFader =
action.faderNumber
nextState[0].channelConnection[0].channel[
action.channel
].assignedFader = action.faderNumber
return nextState
case SET_AUX_LEVEL: //channel: auxIndex: level:
nextState[0].channel[action.channel].auxLevel[
nextState[0].channelConnection[0].channel[action.channel].auxLevel[
action.auxIndex
] = parseFloat(action.level)
return nextState
case SET_PRIVATE:
if (!nextState[0].channel[action.channel].private) {
nextState[0].channel[action.channel].private = {}
if (
!nextState[0].channelConnection[0].channel[action.channel]
.private
) {
nextState[0].channelConnection[0].channel[
action.channel
].private = {}
}
nextState[0].channel[action.channel].private![action.tag] =
action.value
nextState[0].channelConnection[0].channel[action.channel].private![
action.tag
] = action.value
return nextState
default:
return nextState
Expand Down
Loading

0 comments on commit c1ba41d

Please sign in to comment.