diff --git a/src/web/control.js b/src/web/control.js index 882a9eb..9861ccf 100644 --- a/src/web/control.js +++ b/src/web/control.js @@ -106,6 +106,7 @@ function useStreamwallConnection(wsEndpoint) { const [config, setConfig] = useState({}) const [streams, setStreams] = useState([]) const [customStreams, setCustomStreams] = useState([]) + const [views, setViews] = useState([]) const [stateIdxMap, setStateIdxMap] = useState(new Map()) const [delayState, setDelayState] = useState() const [authState, setAuthState] = useState() @@ -152,9 +153,10 @@ function useStreamwallConnection(wsEndpoint) { auth, } = state const newStateIdxMap = new Map() + const newViews = [] for (const viewState of views) { const { pos } = viewState.context - const state = State.from(viewState.state) + const state = State.from(viewState.state, viewState.context) const isListening = state.matches( 'displaying.running.audio.listening', ) @@ -162,22 +164,25 @@ function useStreamwallConnection(wsEndpoint) { 'displaying.running.audio.background', ) const isBlurred = state.matches('displaying.running.video.blurred') + const viewInfo = { + state, + isListening, + isBackgroundListening, + isBlurred, + spaces: pos.spaces, + } + newViews.push(viewInfo) for (const space of pos.spaces) { if (!newStateIdxMap.has(space)) { newStateIdxMap.set(space, {}) } - Object.assign(newStateIdxMap.get(space), { - state, - isListening, - isBackgroundListening, - isBlurred, - spaces: pos.spaces, - }) + Object.assign(newStateIdxMap.get(space), viewInfo) } } setConfig(newConfig) setStateIdxMap(newStateIdxMap) setStreams(sortBy(newStreams, ['_id'])) + setViews(newViews) setCustomStreams(newStreams.filter((s) => s._dataSource === 'custom')) setDelayState( streamdelay && { @@ -236,6 +241,7 @@ function useStreamwallConnection(wsEndpoint) { config, streams, customStreams, + views, stateIdxMap, delayState, authState, @@ -251,11 +257,12 @@ function App({ wsEndpoint, role }) { config, streams, customStreams, + views, stateIdxMap, delayState, authState, } = useStreamwallConnection(wsEndpoint) - const { gridCount } = config + const { gridCount, width: windowWidth, height: windowHeight } = config const [showDebug, setShowDebug] = useState(false) const handleChangeShowDebug = useCallback((ev) => { @@ -549,39 +556,91 @@ function App({ wsEndpoint, role }) { /> )} -
- {range(0, gridCount).map((y) => ( - - {range(0, gridCount).map((x) => { - const idx = gridCount * y + x - const { - isListening = false, - isBackgroundListening = false, - isBlurred = false, - state, - } = stateIdxMap.get(idx) || {} - const { streamId } = sharedState.views?.[idx] || '' - const isDragHighlighted = - dragStart !== undefined && - idxInBox(gridCount, dragStart, dragEnd, idx) + {gridCount && ( + + + {range(0, gridCount).map((y) => + range(0, gridCount).map((x) => { + const idx = gridCount * y + x + const { state } = stateIdxMap.get(idx) || {} + const { streamId } = sharedState.views?.[idx] ?? {} + const isDragHighlighted = + dragStart !== undefined && + idxInBox(gridCount, dragStart, dragEnd, idx) + return ( + + ) + }), + )} + + + {views.map(({ state, isListening }) => { + const { pos } = state.context + const { streamId } = sharedState.views[pos.spaces[0]] ?? {} + const data = streams.find((d) => d._id === streamId) return ( - + + {streamId} +
{data?.source}
+
+ + ) + })} +
+ {views.map( + ({ state, isListening, isBackgroundListening, isBlurred }) => { + const { pos } = state.context + const { streamId } = sharedState.views[pos.spaces[0]] ?? {} + return ( + ) - })} -
- ))} -
+ }, + )} + + )} {(roleCan(role, 'dev-tools') || roleCan(role, 'browse')) && (