Skip to content

Commit

Permalink
fix: Mixer Online did not turn red when connection was lost - fixed o…
Browse files Browse the repository at this point in the history
…n OSC protocols and on Vista mixer
  • Loading branch information
olzzon authored and olzzon committed Apr 27, 2020
1 parent e0175fc commit 52c429d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 13 deletions.
7 changes: 7 additions & 0 deletions client/utils/SocketClientHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
SOCKET_SET_STORE_CHANNEL,
SOCKET_RETURN_CCG_LIST,
SOCKET_SET_VU_REDUCTION,
SOCKET_SET_MIXER_ONLINE,
} from '../../server/constants/SOCKET_IO_DISPATCHERS'

export const socketClientHandlers = () => {
Expand Down Expand Up @@ -84,6 +85,12 @@ export const socketClientHandlers = () => {
window.mixerProtocolPresets = payload.mixerProtocolPresets
window.mixerProtocolList = payload.mixerProtocolList
})
.on(SOCKET_SET_MIXER_ONLINE, (payload: any) => {
window.storeRedux.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: payload.mixerOnline,
})
})
.on(SOCKET_SET_STORE_FADER, (payload: any) => {
window.storeRedux.dispatch({
type: SET_SINGLE_FADER_STATE,
Expand Down
1 change: 1 addition & 0 deletions server/constants/SOCKET_IO_DISPATCHERS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ export const SOCKET_SAVE_CCG_FILE = 'saveCcgFile'
export const SOCKET_SET_FULL_STORE = 'setFullStore'
export const SOCKET_SET_STORE_FADER = 'setStoreFader'
export const SOCKET_SET_STORE_CHANNEL = 'setStoreChannel'
export const SOCKET_SET_MIXER_ONLINE = 'setStoreSettings'
29 changes: 17 additions & 12 deletions server/utils/mixerConnections/OscMixerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import {
SOCKET_SET_VU,
SOCKET_SET_VU_REDUCTION,
SOCKET_SET_MIXER_ONLINE,
} from '../../constants/SOCKET_IO_DISPATCHERS'
import { logger } from '../logger'

Expand Down Expand Up @@ -67,24 +68,27 @@ export class OscMixerConnection {
this.setupMixerConnection()
}

mixerOnline(state: boolean) {
store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: state,
})
socketServer.emit(SOCKET_SET_MIXER_ONLINE, {
mixerOnline: state,
})
}

setupMixerConnection() {
this.oscConnection
.on('ready', () => {
logger.info('Receiving state of desk', {})
this.initialCommands()

store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: true,
})
this.mixerOnline(true)
global.mainThreadHandler.updateFullClientStore()
})
.on('message', (message: any) => {
clearTimeout(this.mixerOnlineTimer)
store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: true,
})
logger.verbose('Received OSC message: ' + message.address, {})

if (
Expand Down Expand Up @@ -434,14 +438,15 @@ export class OscMixerConnection {
}
})
.on('error', (error: any) => {
store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: false,
})
this.mixerOnline(false)
global.mainThreadHandler.updateFullClientStore()
logger.error('Error : ' + String(error), {})
logger.info('Lost OSC connection', {})
})
.on('disconnect', () => {
this.mixerOnline(false)
logger.info('Lost OSC connection', {})
})

this.oscConnection.open()
logger.info(
Expand Down
21 changes: 20 additions & 1 deletion server/utils/mixerConnections/StuderVistaMixerConnection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//@ts-ignore
import { BER } from 'node-emberplus'
import { state } from '../../reducers/store'
import { store, state } from '../../reducers/store'
const net = require('net')

//Utils:
import { IMixerProtocol } from '../../constants/MixerProtocolInterface'
import { logger } from '../logger'
import { SET_MIXER_ONLINE } from '../../reducers/settingsActions'
import { socketServer } from '../../expressHandler'
import { SOCKET_SET_MIXER_ONLINE } from '../../constants/SOCKET_IO_DISPATCHERS'

export class StuderVistaMixerConnection {
mixerProtocol: IMixerProtocol
Expand All @@ -20,6 +23,8 @@ export class StuderVistaMixerConnection {
this.emberNodeObject = new Array(200)
this.mixerProtocol = mixerProtocol

this.mixerOnline(false)

logger.info('Setting up Ember connection')

this.socket = net.createConnection(
Expand All @@ -38,9 +43,11 @@ export class StuderVistaMixerConnection {
.on('end', () => {
// When connection disconnected.
logger.info('Ember Client socket disconnect. ')
this.mixerOnline(false)
})
.on('error', (err: any) => {
logger.error(JSON.stringify(err))
this.mixerOnline(false)
})
.on('connect', () => {
this.setupMixerConnection()
Expand All @@ -50,6 +57,8 @@ export class StuderVistaMixerConnection {
setupMixerConnection() {
logger.info('Ember connection established')

this.mixerOnline(true)

//Ping OSC mixer if mixerProtocol needs it.
if (this.mixerProtocol.pingTime > 0) {
let emberTimer = setInterval(() => {
Expand All @@ -58,6 +67,16 @@ export class StuderVistaMixerConnection {
}
}

mixerOnline(state: boolean) {
store.dispatch({
type: SET_MIXER_ONLINE,
mixerOnline: state,
})
socketServer.emit(SOCKET_SET_MIXER_ONLINE, {
mixerOnline: state,
})
}

subscribeFaderLevel(
ch: number,
typeIndex: number,
Expand Down

0 comments on commit 52c429d

Please sign in to comment.