From d849e58049d76df10ff12bb22b9e78f0171d0609 Mon Sep 17 00:00:00 2001 From: talksik Date: Mon, 9 May 2022 07:51:34 -0500 Subject: [PATCH] incomplete, not sure of priority of this --- packages/api/sockets/index.ts | 33 +++++++++++++++++++ packages/core/sockets/channels.ts | 8 +++++ .../src/controller/lineDataProvider.tsx | 19 ++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/packages/api/sockets/index.ts b/packages/api/sockets/index.ts index 17f029b..c42cd15 100644 --- a/packages/api/sockets/index.ts +++ b/packages/api/sockets/index.ts @@ -264,6 +264,39 @@ export default function InitializeWs(io: any) { } ); + // TODO: not complete + socket.on(ServerRequestChannels.GOING_INTO_FLOW_STATE, () => { + // change user object to persist this state + + // get all of the connectedLine rooms of this person, and tell them that user is going into flow state + + for (const roomName of socket.rooms) { + if (roomName !== socket.id) { + const lineId = roomName.split(":")[1]; + if (roomName.includes("connectedLine")) { + // get fresh list of tuned in folks without me + const clientUserIdsInRoom = [ + ...(io.sockets.adapter.rooms.get(roomName) ?? []), + ] + .filter((mappedSocketId) => mappedSocketId !== socket.id) + .map( + (otherUserSocketId: string) => + socketIdsToUserIds[otherUserSocketId] + ); + + // io.in(roomName).emit( + // ServerResponseChannels.SOMEONE_GOING_INTO_FLOW_STATE, + // new SomeoneGoingIntoFlowState( + + // userInfo.userId + + // ) + // ); + } + } + } + }); + // tell all connected people that I am disconnecting // tell tuned in folks that I am leaving the room // tell the tuned in folks the new list of diff --git a/packages/core/sockets/channels.ts b/packages/core/sockets/channels.ts index 751fb68..eba1417 100644 --- a/packages/core/sockets/channels.ts +++ b/packages/core/sockets/channels.ts @@ -44,6 +44,8 @@ export enum ServerRequestChannels { RTC_CALL_REQUEST = "RTC_CALL_PREFIX", RTC_ANSWER_REQUEST = "RTC_ANSWER_REQUEST_PREFIX", + + GOING_INTO_FLOW_STATE = "GOING_INTO_FLOW_STATE", } export enum ServerResponseChannels { @@ -59,6 +61,8 @@ export enum ServerResponseChannels { // sending to the correct room of tunedin folks AND also making sure it's the right event handler in the right handler for this component RTC_NEW_USER_JOINED_RESPONSE_PREFIX = "RTC_NEW_USER_JOINED_RESPONSE_PREFIX", RTC_RECEIVING_ANSWER_RESPONSE_PREFIX = "RTC_RECEIVING_ANSWER_RESPONSE_PREFIX", + + SOMEONE_GOING_INTO_FLOW_STATE = "SOMEONE_GOING_INTO_FLOW_STATE", } export default SocketChannels; @@ -138,3 +142,7 @@ export class RtcAnswerRequest { export class RtcReceiveAnswerResponse { constructor(public answererUserId: string, public simplePeerSignal: any) {} } + +export class FlowStateRequest { + constructor() {} +} diff --git a/packages/desktop/src/controller/lineDataProvider.tsx b/packages/desktop/src/controller/lineDataProvider.tsx index e100281..c607654 100644 --- a/packages/desktop/src/controller/lineDataProvider.tsx +++ b/packages/desktop/src/controller/lineDataProvider.tsx @@ -1,4 +1,4 @@ -import { $jwtToken, $selectedLineId } from "./recoil"; +import { $desktopMode, $jwtToken, $selectedLineId } from "./recoil"; import { ConnectToLineRequest, ServerRequestChannels, @@ -388,12 +388,29 @@ export function LineDataProvider({ children }) { // persistent store of lines // ?just do simple synchronous axios/fetch in useEffect and manage isLoading ourselves? const { data: basicUserLinesData } = useUserLines(); + const desktopMode = useRecoilValue($desktopMode); // ! passing in the same data of the query passes reference so changes that happen in socketHandler impact react query cache const { linesMap, ...handlers } = useSocketHandler( basicUserLinesData?.data?.masterLines ); + // if we go into flow state + // emit flow state message to all of my rooms + // persist it in my user object + // and then disconnect + useEffect(() => { + return () => { + if (desktopMode === "flowState" && $ws) { + console.log( + "SOCKETS | telling all of my connected rooms that I am unplugging" + ); + + $ws.emit(ServerRequestChannels.GOING_INTO_FLOW_STATE); + } + }; + }, [desktopMode, $ws]); + // avoid children rendering if they don't have the ws to make individual calls with if (!$ws) { return attempting to connect you for the here and now...;