Skip to content

Commit

Permalink
fix: put vu messages back on main socket
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Nov 10, 2020
1 parent 5447042 commit d23d3ca
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 26 deletions.
17 changes: 1 addition & 16 deletions client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,8 @@ socketClientHandlers()
window.socketIoClient.emit('get-store', 'update local store')
window.socketIoClient.emit('get-settings', 'update local settings')
window.socketIoClient.emit('get-mixerprotocol', 'get selected mixerprotocol')

if (!window.location.search.includes('vu=0')) {
window.socketIoVuClient = io(
document.location.protocol + '//' + document.location.hostname + ':1178'
)
window.socketIoVuClient.on('connect', () => console.log('connection!'))
window.socketIoVuClient.on(
'channel',
(faderIndex: number, channelIndex: number, level: number) => {
// console.log('got vu!', ...payload)
if (!vuMeters[faderIndex]) vuMeters[faderIndex] = []
vuMeters[faderIndex][channelIndex] = level
}
)
// window.socketIoVuClient.on('reduction', (...payload: any[]) =>
// console.log('got reduction!', ...payload)
// )
window.socketIoClient.emit('subscribe-vu-meter', 'subscribe to vu meters')
}

ReactDom.render(
Expand Down
8 changes: 8 additions & 0 deletions client/utils/SocketClientHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
IchConnection,
InumberOfChannels,
} from '../../server/reducers/channelsReducer'
import { VuType } from '../../server/utils/vuServer'

export const vuMeters: number[][] = []

Expand Down Expand Up @@ -119,4 +120,11 @@ export const socketClientHandlers = () => {
.on(SOCKET_RETURN_PAGES_LIST, (payload: any) => {
window.storeRedux.dispatch(storeUpdatePagesList(payload))
})
.on(
VuType.Channel,
(faderIndex: number, channelIndex: number, level: number) => {
if (!vuMeters[faderIndex]) vuMeters[faderIndex] = []
vuMeters[faderIndex][channelIndex] = level
}
)
}
15 changes: 10 additions & 5 deletions server/expressHandler.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { logger } from './utils/logger'
import { socketSubscribeVu, socketUnsubscribeVu } from './utils/vuServer'

const express = require('express')
const path = require('path')
const app = express()
const server = require('http').Server(app)
const socketServer = require('socket.io')(server)
const vuServer = require('socket.io')({
perMessageDeflate: false, // disable for cpu performance
})
const SERVER_PORT = 1176

app.use('/', express.static(path.join(__dirname, '..')))
server.listen(SERVER_PORT)
vuServer.listen(SERVER_PORT + 2)
logger.info(`Server started at http://localhost:${SERVER_PORT}`)

server.on('connection', () => {
Expand All @@ -24,10 +21,18 @@ server.on('connection', () => {
socketServer.on('connection', (socket: any) => {
logger.info('Client connected :' + String(socket.client.id), {})
global.mainThreadHandler.socketServerHandlers(socket)

socket.on('subscribe-vu-meter', () => {
console.log('socket subscribe vu')
socketSubscribeVu(socket)
})
socket.on('disconnect', () => {
socketUnsubscribeVu(socket)
})
})

export const expressInit = () => {
logger.info('Initialising WebServer')
}

export { socketServer, vuServer }
export { socketServer }
23 changes: 18 additions & 5 deletions server/utils/vuServer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { vuServer } from '../expressHandler'

export enum VuType {
Channel = 'channel',
Reduction = 'reduction',
Channel = 'vuChannel',
Reduction = 'vuReduction',
}

const sockets: Array<any> = []

export function socketSubscribeVu(socket: any) {
sockets.push(socket)
}

export function socketUnsubscribeVu(socket: any) {
const i = sockets.indexOf(socket)
if (i) {
sockets.splice(i, 1)
}
}

export function sendVuLevel(
Expand All @@ -11,5 +22,7 @@ export function sendVuLevel(
channelIndex: number,
level: number
) {
vuServer.emit(type, faderIndex, channelIndex, level)
sockets.forEach((socket) => {
socket.emit(type, faderIndex, channelIndex, level)
})
}

0 comments on commit d23d3ca

Please sign in to comment.