Skip to content

Commit

Permalink
add type field to ws event; add beta flag
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Jan 20, 2025
1 parent 52940e3 commit 8bdcc66
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
38 changes: 24 additions & 14 deletions src/components/PixelGraph/PixelGraphCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react'
import useStore from '../../store/useStore'
import { useShallow } from 'zustand/shallow'
import hexColor from '../../pages/Devices/EditVirtuals/EditMatrix/Actions/hexColor'
// import ws from '../../utils/Websocket'
import ws from '../../utils/Websocket'

const PixelGraphCanvas = ({
virtId,
Expand Down Expand Up @@ -35,6 +35,7 @@ const PixelGraphCanvas = ({
config: state.config
}))
)
const features = useStore((state) => state.features)
const smoothing = useStore(
(state) => state.uiPersist.pixelGraphSettings?.smoothing
)
Expand Down Expand Up @@ -88,26 +89,35 @@ const PixelGraphCanvas = ({
}
ctx.putImageData(imageData, 0, 0)

// if (ws && typeof ws !== 'string') {
// const request = {
// event_filter: {
// vis_id: virtId,
// is_device: !!virtuals[virtId]?.is_device
// },
// event_type: 'visualisation_update',
// // id: i,
// type: 'subscribe_event'
// }
// ws.send(JSON.stringify(++request.id && request))
// }
if (features.websocket_debug) {
if (ws && typeof ws !== 'string') {
const request = {
type: 'event',
event_type: 'visualisation_updated',
id: e.detail.rid,
vis_id: virtId,
timestamp: e.detail.timestamp
}
ws.send(JSON.stringify(request))
}
}
}
}

document.addEventListener('visualisation_update', handleWebsockets)
return () => {
document.removeEventListener('visualisation_update', handleWebsockets)
}
}, [virtId, virtuals, pixelGraphs, devices, graphs, config, showMatrix])
}, [
virtId,
virtuals,
pixelGraphs,
devices,
graphs,
config,
showMatrix,
features.websocket_debug
])

const render =
(virtuals[virtId].active && virtuals[virtId].effect?.name) ||
Expand Down
7 changes: 7 additions & 0 deletions src/pages/Settings/BetaFeatures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ const BetaFeatures = () => {
checked={features.wakelock}
onChange={() => setFeatures('wakelock', !features.wakelock)}
/>
<SettingsRow
title="Websocket debug"
checked={features.websocket_debug}
onChange={() =>
setFeatures('websocket_debug', !features.websocket_debug)
}
/>
{showFeatures.integrations ? (
<SettingsRow
title="Integrations"
Expand Down
7 changes: 5 additions & 2 deletions src/store/ui/storeFeatures.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type IFeatures =
| 'gamepad'
| 'wakelock'
| 'melbankGraph'
| 'websocket_debug'

const storeFeatures = (set: any) => ({
features: {
Expand Down Expand Up @@ -62,7 +63,8 @@ const storeFeatures = (set: any) => ({
gamepad: false,
matrix_cam: false,
wakelock: false,
melbankGraph: false
melbankGraph: false,
websocket_debug: false
},
showFeatures: {
dev: false,
Expand Down Expand Up @@ -93,7 +95,8 @@ const storeFeatures = (set: any) => ({
gamepad: false,
matrix_cam: false,
wakelock: false,
melbankGraph: false
melbankGraph: false,
websocket_debug: false
},
setFeatures: (feat: IFeatures, use: boolean): void =>
set(
Expand Down
7 changes: 6 additions & 1 deletion src/utils/Websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,18 @@ function createSocket() {
},
onmessage: (event) => {
const data = JSON.parse(event.data)
if (!data?.event_type) {
return
}
if (data.event_type === 'visualisation_update') {
document.dispatchEvent(
new CustomEvent('visualisation_update', {
detail: {
id: data.vis_id,
pixels: data.pixels,
shape: data.shape
shape: data.shape,
rid: data.id,
timestamp: data.timestamp
}
})
)
Expand Down

0 comments on commit 8bdcc66

Please sign in to comment.