incomplete, not sure of priority of this

This commit is contained in:
talksik
2022-05-09 07:51:34 -05:00
parent c8b460bcbb
commit d849e58049
3 changed files with 59 additions and 1 deletions
+33
View File
@@ -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
+8
View File
@@ -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() {}
}
@@ -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 <span>attempting to connect you for the here and now...</span>;