diff --git a/public/server.js b/public/server.js index 188742f..0631743 100644 --- a/public/server.js +++ b/public/server.js @@ -91,10 +91,39 @@ class SocketOSCServer { }); }); + /** + * @param address {string} + * @param args {{ type: 'f'|'s'|'i'|'b', value: string|number|boolean }[]} + * @return {{ address, args: {[key: string]: string|number}} + */ + const parseHostMessagePayload = ({ address, args }) => { + if (address !== '/gs') { + console.log('Unhandled address: ' + address); + this.log('Unhandled address: ' + address) + return + } + + const parsedArgs = args.map(arg => { + const parsedValue = JSON.parse(arg.value) + return { + phase: parsedValue.phase, + data: parsedValue.data, + } + }) + + // console.log(parsedArgs) + + return { + gameState: parsedArgs[0] + } + } + oscServer.on('message', (oscMessage) => { this.log(`osc ⬅ ${JSON.stringify(oscMessage)}`); this.log('ws ⥤ OSC_HOST_MESSAGE ' + JSON.stringify(oscMessage)); - this.socket.emit('OSC_HOST_MESSAGE', { data: oscMessage, room: this.sessionState.room }); + + const parsedOscMessage = parseHostMessagePayload(oscMessage) + this.socket.emit('OSC_HOST_MESSAGE', { data: parsedOscMessage, room: this.sessionState.room }); }); oscServer.on('error', (err) => { diff --git a/src/components/App/Pages/Session.tsx b/src/components/App/Pages/Session.tsx index 95a13f7..aeb43f4 100644 --- a/src/components/App/Pages/Session.tsx +++ b/src/components/App/Pages/Session.tsx @@ -47,7 +47,6 @@ const Session: React.FC = (props) => { - diff --git a/src/components/SessionLog/index.tsx b/src/components/SessionLog/index.tsx index 5150de5..2d026d6 100644 --- a/src/components/SessionLog/index.tsx +++ b/src/components/SessionLog/index.tsx @@ -8,7 +8,7 @@ const SessionLog = () => { // @todo: throttle/batch this to not crash the webview when bursting lots (and avoid rerunning useEffect all the time) const onReceivePushLog = useCallback((data:any) => { const item = { message: data }; - setLogItems([ ...logItems.slice(-100), item]); + setLogItems([ ...logItems.slice(-200), item]); }, [ logItems ]); useEffect(() => {