From aabc6cc2e252efc4443816c771a3a32396237c47 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Sun, 16 Jan 2022 12:30:20 -0800 Subject: [PATCH] problem with devices in http...oh well --- components/Dashboard/TeamVoiceLine.tsx | 31 ++++++++++++---------- contexts/audioContext.tsx | 36 +++++++++++++++----------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/components/Dashboard/TeamVoiceLine.tsx b/components/Dashboard/TeamVoiceLine.tsx index 36aa053..a6f1efb 100644 --- a/components/Dashboard/TeamVoiceLine.tsx +++ b/components/Dashboard/TeamVoiceLine.tsx @@ -38,7 +38,12 @@ yesterday.setDate(yesterday.getDate() - 1); export default function TeamVoiceLine() { const { currUser } = useAuth(); - const audioContext = useAudioContext(); + const { + addTeamShortcutBinding, + selectTeamMember, + selectedTeammate, + isRecording, + } = useAudioContext(); const router = useRouter(); const { teamid } = router.query; const { team, user, userTeamMember, teamMembers } = useTeamDashboardContext(); @@ -126,19 +131,21 @@ export default function TeamVoiceLine() { // update map of teammate to relevant messages setMessagesByTeamMate((prevMap) => { + console.log("settting state"); // if the map contains the teammate userid already, then cool, just unshift to that array + const newMap = { ...prevMap }; if (newMessage.receiverUserId in prevMap) { - prevMap[newMessage.receiverUserId] = [ + newMap[newMessage.receiverUserId] = [ newMessage, ...prevMap[newMessage.receiverUserId], ]; } // if this is the first relevant message linked to this receiver, //then create a new array else { - prevMap[newMessage.receiverUserId] = [newMessage]; + newMap[newMessage.receiverUserId] = [newMessage]; } - return prevMap + return newMap; }); } if (change.type === "modified") { @@ -154,7 +161,7 @@ export default function TeamVoiceLine() { return () => unsubscribe(); }, []); - console.log(allMessages); + console.log(messagesByTeamMate); // set up shortcuts for each teammate useEffect(() => { @@ -162,7 +169,7 @@ export default function TeamVoiceLine() { // make sure we don't map a user if they are past the max allowed if (i < maxNumberOfKeyboardMappings) { let shortcut: number = i + 49; // 49 is what number 1 is on the keyboard - audioContext.addTeamShortcutBinding(shortcut, tmUser.id); + addTeamShortcutBinding(shortcut, tmUser.id); } }); }, [teamUsers]); @@ -202,12 +209,10 @@ export default function TeamVoiceLine() { return teamUsers.map((tmember, i) => { return ( audioContext.selectTeamMember(tmember.id)} + onClick={() => selectTeamMember(tmember.id)} key={i} className={`rounded flex flex-row items-center py-2 px-2 justify-items-start ease-in-out duration-300 hover:cursor-pointer ${ - tmember.id == audioContext.selectedTeammate - ? "bg-white scale-150 z-20" - : "" + tmember.id == selectedTeammate ? "bg-white scale-150 z-20" : "" }`} > @@ -223,7 +228,7 @@ export default function TeamVoiceLine() { - {tmember.id == audioContext.selectedTeammate ? ( + {tmember.id == selectedTeammate ? ( <> @@ -255,10 +260,10 @@ export default function TeamVoiceLine() { )} - {tmember.id == audioContext.selectedTeammate ? ( + {tmember.id == selectedTeammate ? ( <> - {audioContext.isRecording ? ( + {isRecording ? ( diff --git a/contexts/audioContext.tsx b/contexts/audioContext.tsx index 1454fec..c4585ae 100644 --- a/contexts/audioContext.tsx +++ b/contexts/audioContext.tsx @@ -153,22 +153,28 @@ export default function AudioContextProvider({ children }) { // first load just force check if permissions enabled // through fake stream useEffect(() => { - navigator.mediaDevices - .getUserMedia({ audio: { deviceId: audioInputDeviceId } }) - .then((stream) => { - // stop playing anything - stopBothVideoAndAudio(stream); + try { + // won't work in https!!! + navigator.mediaDevices + .getUserMedia({ audio: { deviceId: audioInputDeviceId } }) + .then((stream) => { + // stop playing anything + stopBothVideoAndAudio(stream); - console.log("Permission Granted"); - setHasRecPermit(true); - }) - .catch((e) => { - console.log("Permission Denied"); - toast.error( - "Please make sure that you have connected a microphone and given permissions." - ); - setHasRecPermit(false); - }); + console.log("Permission Granted"); + setHasRecPermit(true); + }) + .catch((e) => { + console.log("Permission Denied"); + toast.error( + "Please make sure that you have connected a microphone and given permissions." + ); + setHasRecPermit(false); + }); + } catch (error) { + console.log(error); + toast.error("something went wrong"); + } }, []); // set recording device