From 309e74ff94af4789f03bb0bb0858c7d087062710 Mon Sep 17 00:00:00 2001 From: talksik Date: Fri, 6 May 2022 12:06:16 -0500 Subject: [PATCH] handling starting and stopping broadcast --- .../src/controller/lineDataProvider.tsx | 3 +- packages/desktop/src/pages/terminal/index.tsx | 38 ++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/packages/desktop/src/controller/lineDataProvider.tsx b/packages/desktop/src/controller/lineDataProvider.tsx index a9848bd..9d8c1e6 100644 --- a/packages/desktop/src/controller/lineDataProvider.tsx +++ b/packages/desktop/src/controller/lineDataProvider.tsx @@ -81,6 +81,7 @@ export function LineDataProvider({ children }) { // whether toggle tuned or temporarily $ws.on(SocketChannels.SOMEONE_TUNED_TO_LINE, (res: SomeoneTuned) => { // TODO: change the correct master line data to show user who's tuned in + toast( `another user (${res.userId}) tuned into line ${res.lineId} that you are in also` ); @@ -104,7 +105,7 @@ export function LineDataProvider({ children }) { // todo: check if it's the user or someone else broadcasting if (newMap[pull.lineId]) - newMap[pull.lineId].isUserBroadcasting = true; + newMap[pull.lineId].isUserBroadcasting = pull.isTurningOn; return newMap; }); diff --git a/packages/desktop/src/pages/terminal/index.tsx b/packages/desktop/src/pages/terminal/index.tsx index c72565e..e2973e9 100644 --- a/packages/desktop/src/pages/terminal/index.tsx +++ b/packages/desktop/src/pages/terminal/index.tsx @@ -53,14 +53,39 @@ export default function NirvanaTerminal() { setSelectedLineId(null); }, [setSelectedLineId]); - const handleStartBroadcast = useCallback(() => { - if (selectedLineId) handleUserBroadcast(selectedLineId, true); - }, [selectedLineId]); + const handleStartBroadcast = useCallback( + (lineId: string) => () => { + console.log(`starting broadcast for ${lineId}!!!`); + + // todo: enable stream in this tuned in channel + + if (lineId) handleUserBroadcast(lineId, true); + }, + [] + ); + + const handleStopBroadcast = useCallback( + (lineId: string) => () => { + console.log(`stopping broadcast for ${lineId}!!!`); + + // todo: disable stream in this tuned in channel + + if (lineId) handleUserBroadcast(lineId, false); + }, + [] + ); const keyMap: KeyMap = useMemo( () => ({ DESELECT_LINE: "esc", - START_BROADCAST: "`", + START_BROADCAST: { + sequence: "`", + action: "keydown", + }, + STOP_BROADCAST: { + sequence: "`", + action: "keyup", + }, }), [] ); @@ -68,9 +93,10 @@ export default function NirvanaTerminal() { const handlers = useMemo( () => ({ DESELECT_LINE: handleEscape, - START_BROADCAST: handleStartBroadcast, + START_BROADCAST: handleStartBroadcast(selectedLineId), + STOP_BROADCAST: handleStopBroadcast(selectedLineId), }), - [handleEscape, handleStartBroadcast] + [selectedLineId] ); return (