trying things but not working on that particular case

This commit is contained in:
talksik
2022-07-06 08:18:45 -05:00
parent 67d41a17ac
commit 5062b39c82
3 changed files with 139 additions and 122 deletions
+2 -2
View File
@@ -42,8 +42,8 @@
[ [
"@electron-forge/plugin-webpack", "@electron-forge/plugin-webpack",
{ {
"port": "4010", "port": "4000",
"loggerPort": "9010", "loggerPort": "9000",
"mainConfig": "./webpack.main.config.js", "mainConfig": "./webpack.main.config.js",
"devContentSecurityPolicy": "default-src * self blob: data: gap:; style-src * self 'unsafe-inline' blob: data: gap:; script-src * 'self' 'unsafe-eval' 'unsafe-inline' blob: data: gap:; object-src * 'self' blob: data: gap:; img-src * self 'unsafe-inline' blob: data: gap:; connect-src self * 'unsafe-inline' blob: data: gap:; frame-src * self blob: data: gap:;", "devContentSecurityPolicy": "default-src * self blob: data: gap:; style-src * self 'unsafe-inline' blob: data: gap:; script-src * 'self' 'unsafe-eval' 'unsafe-inline' blob: data: gap:; object-src * 'self' blob: data: gap:; img-src * self 'unsafe-inline' blob: data: gap:; connect-src self * 'unsafe-inline' blob: data: gap:; frame-src * self blob: data: gap:;",
"renderer": { "renderer": {
@@ -627,7 +627,6 @@ function Room({
// handle incoming calls and accept calls and create objects for them // handle incoming calls and accept calls and create objects for them
useEffectOnce(() => { useEffectOnce(() => {
(async () => {
// TODO : bring this stream object higher and add this later to the room // TODO : bring this stream object higher and add this later to the room
// set up local stream for this room - temporary until we figure out global stream handling and passing down // set up local stream for this room - temporary until we figure out global stream handling and passing down
// const localMediaStream = await navigator.mediaDevices.getUserMedia({ // const localMediaStream = await navigator.mediaDevices.getUserMedia({
@@ -706,7 +705,7 @@ function Room({
}); });
localPeerConnection.on('connect', () => { localPeerConnection.on('connect', () => {
// toast.success('successfully connected to another peer'); console.log('successfully connected to another peer');
setConversationMap((draft) => { setConversationMap((draft) => {
if (draft[conversation._id.toString()].room[otherUserId]) { if (draft[conversation._id.toString()].room[otherUserId]) {
draft[conversation._id.toString()].room[otherUserId].isConnecting = false; draft[conversation._id.toString()].room[otherUserId].isConnecting = false;
@@ -715,7 +714,7 @@ function Room({
}); });
localPeerConnection.on('track', (track, stream) => { localPeerConnection.on('track', (track, stream) => {
// TODO: add to room contents // TODO: add to room peer stream or replace the entire stream
toast('a peer added a track to a stream'); toast('a peer added a track to a stream');
}); });
@@ -725,6 +724,8 @@ function Room({
// we want to manage the room within the master conversation and remove it for ourselves // we want to manage the room within the master conversation and remove it for ourselves
// !this is false, see unmount, we are relying on tuned list for disconnections // !this is false, see unmount, we are relying on tuned list for disconnections
console.error('peer connection was closed');
setConversationMap((draft) => { setConversationMap((draft) => {
if (draft[conversation._id.toString()].room[otherUserId]) { if (draft[conversation._id.toString()].room[otherUserId]) {
draft[conversation._id.toString()].room[otherUserId].peer?.destroy(); draft[conversation._id.toString()].room[otherUserId].peer?.destroy();
@@ -738,10 +739,16 @@ function Room({
localPeerConnection.on('error', (err) => { localPeerConnection.on('error', (err) => {
console.error(err); console.error(err);
toast.error('there was a problem with the connecting'); toast.error('there was a problem with the connecting');
setConversationMap((draft) => {
if (draft[conversation._id.toString()].room[otherUserId]) {
draft[conversation._id.toString()].room[otherUserId].peer?.destroy();
delete draft[conversation._id.toString()].room[otherUserId];
}
});
}); });
}); });
} }
})();
}); });
// ======= LISTEN FOR INCOMING CALLS AND RETURN SIGNALS AND ACCEPT THEM // ======= LISTEN FOR INCOMING CALLS AND RETURN SIGNALS AND ACCEPT THEM
@@ -839,6 +846,13 @@ function Room({
peerForMeAndNewbie.on('error', (err) => { peerForMeAndNewbie.on('error', (err) => {
console.error(err); console.error(err);
toast.error('there was a problem with connecting'); toast.error('there was a problem with connecting');
setConversationMap((draft) => {
if (draft[conversation._id.toString()].room[res.userWhoCalled]) {
draft[conversation._id.toString()].room[res.userWhoCalled].peer?.destroy();
delete draft[conversation._id.toString()].room[res.userWhoCalled];
}
});
}); });
}); });
@@ -867,20 +881,23 @@ function Room({
useEffect(() => { useEffect(() => {
// go through tuned in users // go through tuned in users
// if we have someone in room who is not in tuned in, then destroy + delete // if we have someone in room who is not in tuned in, then destroy + delete
if (conversation.room) {
Object.entries(conversation.room).forEach(([roomUserId, roomContents]) => { setConversationMap((draft) => {
if (draft[conversation._id.toString()].room) {
Object.entries(draft[conversation._id.toString()].room).forEach(
([roomUserId, roomContents]) => {
if (!conversation.tunedInUsers.includes(roomUserId)) { if (!conversation.tunedInUsers.includes(roomUserId)) {
console.log('someone left the room!!!'); console.log('someone left the room!!!');
roomContents.peer.destroy(); roomContents.peer.destroy();
setConversationMap((draft) => {
delete draft[conversation._id.toString()].room[roomUserId]; delete draft[conversation._id.toString()].room[roomUserId];
}); }
},
);
} }
}); });
} }, [conversation.tunedInUsers, setConversationMap]);
}, [conversation.tunedInUsers, conversation.room]);
// go through all of the peers and destroy and update conversation map // go through all of the peers and destroy and update conversation map
useUnmount(() => { useUnmount(() => {
@@ -934,7 +951,7 @@ function Room({
// close peer connections here // close peer connections here
// update the conversation map as well with proper states and data // update the conversation map as well with proper states and data
}; };
}, []); }, [conversation.tunedInUsers]);
return null; return null;
} }
+4 -4
View File
@@ -323,11 +323,13 @@ function OverlayConversationAvatars({
isConversationSelected: boolean; isConversationSelected: boolean;
tunedInUserIds: string[]; tunedInUserIds: string[];
conversationUserMembers: ConversationUserMember[]; conversationUserMembers: ConversationUserMember[];
roomPeers: RoomMap; roomPeers?: RoomMap;
localStreamToPeers: MediaStream; localStreamToPeers?: MediaStream;
}) { }) {
const { user } = useAuth(); const { user } = useAuth();
console.log(roomPeers);
const sortedMembers = useMemo(() => { const sortedMembers = useMemo(() => {
const sortedUserMembers = [...conversationUserMembers]; const sortedUserMembers = [...conversationUserMembers];
sortedUserMembers.sort((convoUserA, convoUserB) => { sortedUserMembers.sort((convoUserA, convoUserB) => {
@@ -343,8 +345,6 @@ function OverlayConversationAvatars({
return sortedUserMembers; return sortedUserMembers;
}, [conversationUserMembers, user, tunedInUserIds]); }, [conversationUserMembers, user, tunedInUserIds]);
console.log(roomPeers);
return ( return (
<AvatarGroup <AvatarGroup
variant={'rounded'} variant={'rounded'}