Skip to content

Commit

Permalink
feat: multiple mixers - create channel structure and timing in front end
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon authored and olzzon committed Oct 8, 2020
1 parent c2e524f commit c1871f0
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 101 deletions.
19 changes: 11 additions & 8 deletions client/utils/SocketClientHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import {
SOCKET_RETURN_MIXER_PRESET_LIST,
SOCKET_RETURN_PAGES_LIST,
} from '../../server/constants/SOCKET_IO_DISPATCHERS'
import {
IchConnection,
InumberOfChannels,
} from '../../server/reducers/channelsReducer'

export const socketClientHandlers = () => {
window.socketIoClient
Expand All @@ -39,15 +43,14 @@ export const socketClientHandlers = () => {
})
.on(SOCKET_SET_FULL_STORE, (payload: any) => {
// console.log('STATE RECEIVED :', payload)

let numberOfChannels: number[] = []
if (window.mixerProtocol) {
window.mixerProtocol.channelTypes.forEach(
(item: any, index: number) => {
numberOfChannels.push(
payload.settings[0].mixers[0]
.numberOfChannelsInType[index]
)
let numberOfChannels: InumberOfChannels[] = []
payload.channels[0].chConnection.forEach(
(chConnection: IchConnection, mixerIndex: number) => {
numberOfChannels.push({ numberOfTypeInCh: [] })
numberOfChannels[mixerIndex].numberOfTypeInCh = [
chConnection.channel.length,
]
}
)
window.storeRedux.dispatch(
Expand Down
6 changes: 3 additions & 3 deletions server/reducers/channelActions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IChannel, IChannels } from './channelsReducer'
import { IChannel, IChannels, InumberOfChannels } from './channelsReducer'

export const SET_OUTPUT_LEVEL = 'SET_OUTPUT_LEVEL'
export const SET_AUX_LEVEL = 'SET_AUX_LEVEL'
Expand Down Expand Up @@ -36,12 +36,12 @@ export const storeSetAuxLevel = (

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

Expand Down
61 changes: 35 additions & 26 deletions server/reducers/channelsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,27 @@ export interface IChannel {
}
}

const defaultChannelsReducerState = (numberOfChannels: any) => {
let defaultObj: Array<IChannels> = [
export interface InumberOfChannels {
numberOfTypeInCh: number[]
}

const defaultChannelsReducerState = (
numberOfChannels: InumberOfChannels[]
): IChannels[] => {
let defaultObj: IChannels[] = [
{
chConnection: [
{
channel: [],
},
],
chConnection: [],
},
]

for (
let mixerIndex = 0;
mixerIndex++;
mixerIndex < numberOfChannels.length
mixerIndex < numberOfChannels.length;
mixerIndex++
) {
let totalNumberOfChannels = 0
numberOfChannels[mixerIndex].nuberOfTypeChannels.forEach(
defaultObj[0].chConnection.push({ channel: [] })
numberOfChannels[mixerIndex].numberOfTypeInCh.forEach(
(channelTypeSize: any, typeIndex: number) => {
for (let index = 0; index < channelTypeSize; index++) {
defaultObj[0].chConnection[mixerIndex].channel[
Expand All @@ -68,7 +71,7 @@ const defaultChannelsReducerState = (numberOfChannels: any) => {
}

export const channels = (
state = defaultChannelsReducerState([{ numberOfTypeChannels: 1 }]),
state = defaultChannelsReducerState([{ numberOfTypeInCh: [1] }]),
action: any
): Array<IChannels> => {
let nextState = [
Expand All @@ -85,22 +88,28 @@ export const channels = (
return nextState
case SET_COMPLETE_CH_STATE:
nextState = defaultChannelsReducerState(action.numberOfTypeChannels)
if (
action.allState.chConnection[0].channel.length ==
nextState[0].chConnection[0].channel.length
) {
action.allState.chConnection[0].channel.forEach(
(channel: any, index: number) => {
if (
index < nextState[0].chConnection[0].channel.length
) {
nextState[0].chConnection[0].channel[
index
] = channel

nextState[0].chConnection.forEach(
(chConnection: IchConnection, mixerIndex: number) => {
chConnection.channel.forEach(
(channel: any, index: number) => {
if (
index <
action.allState.chConnection[mixerIndex]
?.channel.length
) {
nextState[0].chConnection[mixerIndex].channel[
index
] =
action.allState.chConnection[
mixerIndex
].channel[index]
}
}
}
)
}
)
}
)

return nextState
case SET_SINGLE_CH_STATE:
nextState[0].chConnection[0].channel[action.channelIndex] =
Expand Down
Loading

0 comments on commit c1871f0

Please sign in to comment.