Skip to content

Commit

Permalink
Merge pull request tv2#163 from olzzon/chore/refactor-socket-and-store
Browse files Browse the repository at this point in the history
Chore/refactor socket and store
  • Loading branch information
olzzon authored Oct 17, 2020
2 parents 1eebac4 + 994e42d commit 82ac921
Show file tree
Hide file tree
Showing 22 changed files with 758 additions and 755 deletions.
33 changes: 0 additions & 33 deletions client/components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { IAppProps } from './App'
//Utils:
import '../assets/css/Settings.css'
import { ISettings } from '../../server/reducers/settingsReducer'
import { SHOW_CHANNEL } from '../../server/reducers/faderActions'
import { Store } from 'redux'
import { ChangeEvent } from 'react'
import { SOCKET_SAVE_SETTINGS } from '../../server/constants/SOCKET_IO_DISPATCHERS'
Expand Down Expand Up @@ -166,38 +165,6 @@ class Settings extends React.PureComponent<IAppProps & Store, IState> {
this.setState({ settings: settingsCopy })
}

handleShowChannel = (index: number, event: any) => {
this.props.dispatch({
type: SHOW_CHANNEL,
channel: index,
showChannel: event.target.checked,
})
}

handleShowAllChannels = () => {
this.props.store.channels[0].chConnection[0].channel.forEach(
(channel: any, index: number) => {
this.props.dispatch({
type: SHOW_CHANNEL,
channel: index,
showChannel: true,
})
}
)
}

handleHideAllChannels = () => {
this.props.store.channels[0].chConnection[0].channel.forEach(
(channel: any, index: number) => {
this.props.dispatch({
type: SHOW_CHANNEL,
channel: index,
showChannel: false,
})
}
)
}

handleSave = () => {
let settingsCopy = Object.assign({}, this.state.settings)
settingsCopy.showSettings = false
Expand Down
59 changes: 25 additions & 34 deletions client/utils/SocketClientHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
SET_COMPLETE_FADER_STATE,
SET_VU_LEVEL,
SET_SINGLE_FADER_STATE,
SET_VU_REDUCTION_LEVEL,
storeSetCompleteFaderState,
storeSetSingleFaderState,
storeVuLevel,
storeVuReductionLevel,
} from '../../server/reducers/faderActions'
import {
storeSetCompleteChState,
Expand Down Expand Up @@ -61,11 +61,12 @@ export const socketClientHandlers = () => {
numberOfChannels
)
)
window.storeRedux.dispatch({
type: SET_COMPLETE_FADER_STATE,
allState: payload.faders[0],
numberOfTypeChannels: payload.settings[0].numberOfFaders,
})
window.storeRedux.dispatch(
storeSetCompleteFaderState(
payload.faders[0],
payload.settings[0].numberOfFaders
)
)
window.storeRedux.dispatch(
storeSetMixerOnline(
payload.settings[0].mixers[0].mixerOnline
Expand All @@ -88,11 +89,9 @@ export const socketClientHandlers = () => {
window.storeRedux.dispatch(storeSetMixerOnline(payload.mixerOnline))
})
.on(SOCKET_SET_STORE_FADER, (payload: any) => {
window.storeRedux.dispatch({
type: SET_SINGLE_FADER_STATE,
faderIndex: payload.faderIndex,
state: payload.state,
})
window.storeRedux.dispatch(
storeSetSingleFaderState(payload.faderIndex, payload.state)
)
})
.on(SOCKET_SET_STORE_CHANNEL, (payload: any) => {
window.storeRedux.dispatch(
Expand All @@ -104,20 +103,16 @@ export const socketClientHandlers = () => {
vuUpdateSpeed = Date.now()
payload.vuMeters.forEach(
(meterLevel: number, index: number) => {
window.storeRedux.dispatch({
type: SET_VU_LEVEL,
channel: index,
level: meterLevel,
})
window.storeRedux.dispatch(
storeVuLevel(index, meterLevel)
)
}
)
payload.vuReductionMeters.forEach(
(meterLevel: number, index: number) => {
window.storeRedux.dispatch({
type: SET_VU_REDUCTION_LEVEL,
channel: index,
level: meterLevel,
})
window.storeRedux.dispatch(
storeVuReductionLevel(index, meterLevel)
)
}
)
}
Expand All @@ -126,21 +121,17 @@ export const socketClientHandlers = () => {
if (Date.now() - vuUpdateSpeed > 100) {
vuUpdateSpeed = Date.now()

window.storeRedux.dispatch({
type: SET_VU_LEVEL,
channel: payload.faderIndex,
level: payload.level,
})
window.storeRedux.dispatch(
storeVuLevel(payload.faderIndex, payload.level)
)
}
})
.on(SOCKET_SET_VU_REDUCTION, (payload: any) => {
if (Date.now() - vuReductionUpdateSpeed > 100) {
vuReductionUpdateSpeed = Date.now()
window.storeRedux.dispatch({
type: SET_VU_REDUCTION_LEVEL,
channel: payload.faderIndex,
level: payload.level,
})
window.storeRedux.dispatch(
storeVuReductionLevel(payload.faderIndex, payload.level)
)
}
})
.on(SOCKET_RETURN_SNAPSHOT_LIST, (payload: any) => {
Expand Down
Loading

0 comments on commit 82ac921

Please sign in to comment.