Skip to content

Commit

Permalink
blub
Browse files Browse the repository at this point in the history
  • Loading branch information
laubsauger committed Jan 16, 2024
1 parent 2212b0c commit 43fc591
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
31 changes: 30 additions & 1 deletion public/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 0 additions & 1 deletion src/components/App/Pages/Session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const Session: React.FC = (props) => {

<Col xs={12} md={6} className="text-center">
<Button className="mb-3" onClick={onBtnStopServerClick}>Disconnect from Session</Button>

<SessionState />
</Col>

Expand Down
2 changes: 1 addition & 1 deletion src/components/SessionLog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 43fc591

Please sign in to comment.