Skip to content

Commit

Permalink
Merge pull request #302 from bbc/feat/mixerOutputLevel
Browse files Browse the repository at this point in the history
Mixer output level subscription
  • Loading branch information
olzzon authored Feb 2, 2024
2 parents 721d7f9 + c9e3db5 commit d61d2f0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
8 changes: 7 additions & 1 deletion server/src/expressHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { logger } from './utils/logger'
import { socketSubscribeVu, socketUnsubscribeVu } from './utils/vuServer'
import { socketSubscribeOutputLevel, socketUnsubscribeOutputLevel } from './utils/outputLevelServer'

import express from 'express'
import path from 'path'
Expand All @@ -21,7 +22,7 @@ const staticPath = path.join(
logger.data(staticPath).debug('Express static file path:')
app.use(ROOT_PATH, express.static(staticPath))
server.listen(SERVER_PORT)
logger.info(`Server started at http://localhost:${SERVER_PORT}/${ROOT_PATH}`)
logger.info(`Server started at http://localhost:${SERVER_PORT}${ROOT_PATH}`)

socketServer.on('connection', (socket: any) => {
logger.info(`Client connected: ${socket.client.id}`)
Expand All @@ -31,8 +32,13 @@ socketServer.on('connection', (socket: any) => {
logger.debug('Socket subscribe vu')
socketSubscribeVu(socket)
})
socket.on('subscribe-output-level', () => {
logger.debug('Socket subscribe output')
socketSubscribeOutputLevel(socket)
})
socket.on('disconnect', () => {
socketUnsubscribeVu(socket)
socketUnsubscribeOutputLevel(socket)
})
})

Expand Down
3 changes: 3 additions & 0 deletions server/src/utils/MixerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from '../../../shared/src/actions/faderActions'
import { AtemMixerConnection } from './mixerConnections/AtemConnection'
import { ChannelReference } from '../../../shared/src/reducers/fadersReducer'
import { sendChLevelsToOuputServer } from './outputLevelServer'

export class MixerGenericConnection {
mixerProtocol: MixerProtocolGeneric[]
Expand Down Expand Up @@ -517,6 +518,7 @@ export class MixerGenericConnection {
channel: channelIndex,
level: endLevel,
})
sendChLevelsToOuputServer(mixerIndex, channelIndex, endLevel)
this.delayedFadeActiveDisable(mixerIndex, channelIndex)
return true
}
Expand All @@ -537,6 +539,7 @@ export class MixerGenericConnection {
channel: channelIndex,
level: endLevel,
})
sendChLevelsToOuputServer(mixerIndex, channelIndex, currentOutputLevel)
}

fadeDown = (mixerIndex: number, channelIndex: number, fadeTime: number) => {
Expand Down
27 changes: 27 additions & 0 deletions server/src/utils/outputLevelServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Socket } from 'socket.io'

const sockets: Array<Socket> = []

export function socketSubscribeOutputLevel(socket: Socket) {
const i = sockets.indexOf(socket)
if (i === -1) {
sockets.push(socket)
}
}

export function socketUnsubscribeOutputLevel(socket: Socket) {
const i = sockets.indexOf(socket)
if (i >= 0) {
sockets.splice(i, 1)
}
}

export function sendChLevelsToOuputServer(
mixerIndex: number,
channelIndex: number,
level: number
) {
sockets.forEach((socket) => {
socket.emit('outputLevel', mixerIndex, channelIndex, level)
})
}
7 changes: 4 additions & 3 deletions server/src/utils/vuServer.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { Socket } from 'socket.io'
import { VuType } from '../../../shared/src/utils/vu-server-types'

const sockets: Array<any> = []
const sockets: Array<Socket> = []

export function socketSubscribeVu(socket: any) {
export function socketSubscribeVu(socket: Socket) {
const i = sockets.indexOf(socket)
if (i === -1) {
sockets.push(socket)
}
}

export function socketUnsubscribeVu(socket: any) {
export function socketUnsubscribeVu(socket: Socket) {
const i = sockets.indexOf(socket)
if (i >= 0) {
sockets.splice(i, 1)
Expand Down

0 comments on commit d61d2f0

Please sign in to comment.