This commit is contained in:
talksik
2022-06-02 03:37:36 -05:00
parent 8abc54f84d
commit 885f0039d8
5 changed files with 59 additions and 152 deletions
+3 -1
View File
@@ -95,6 +95,8 @@
"typescript": "~4.5.4"
},
"dependencies": {
"@daily-co/daily-js": "^0.26.0",
"@daily-co/daily-react-hooks": "^0.2.3",
"@emotion/react": "^11.9.0",
"@emotion/styled": "^11.8.1",
"@getstation/electron-google-oauth2": "^2.1.0",
@@ -110,7 +112,7 @@
"react-error-boundary": "^3.1.4",
"react-icons": "^4.3.1",
"react-use": "^17.4.0",
"twilio-video": "^2.21.1",
"recoil": "^0.7.3-alpha.2",
"use-immer": "^0.7.0"
}
}
@@ -1,6 +1,5 @@
/* eslint-disable jsx-a11y/media-has-caption */
/* eslint-disable react/jsx-no-comment-textnodes */
import { ConnectOptions, Room, connect } from 'twilio-video';
import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
import { useMediaDevices, useMount } from 'react-use';
@@ -58,13 +57,9 @@ interface ICommunicationsContext {
userLocalStream?: MediaStream;
userDeviceSelections?: DeviceSelections;
room: Room | null;
}
const CommunicationsContext = React.createContext<ICommunicationsContext>({
room: null,
});
const CommunicationsContext = React.createContext<ICommunicationsContext>({});
// todo save the selected devices in localstorage
export function CommunicationsProvider({ children }: { children: React.ReactNode }) {
@@ -75,61 +70,18 @@ export function CommunicationsProvider({ children }: { children: React.ReactNode
const devices = useUserDevices();
const [room, setRoom] = useState<Room | null>(null);
const localAudioRef = useRef<HTMLAudioElement>(null);
const getAuthToken = useCallback(async () => {
const result = await getTwilioAccessToken();
const data = result.data as TwilioAccessToken;
enqueueSnackbar('got token data');
return data.token;
}, [enqueueSnackbar]);
const connectToRoom = useCallback(
async (conversationId: string) => {
try {
const token = await getAuthToken();
connect(token, {
name: conversationId,
audio: true,
}).then(
(room) => {
enqueueSnackbar('joined room', { variant: 'success' });
// Log your Client's LocalParticipant in the Room
const localParticipant = room.localParticipant;
console.log(`Connected to the Room as LocalParticipant "${localParticipant.identity}"`);
// Log any Participants already connected to the Room
room.participants.forEach((participant) => {
console.log(`Participant "${participant.identity}" is connected to the Room`);
});
// Log new Participants as they connect to the Room
room.once('participantConnected', (participant) => {
console.log(`Participant "${participant.identity}" has connected to the Room`);
});
// Log Participants as they disconnect from the Room
room.once('participantDisconnected', (participant) => {
console.log(`Participant "${participant.identity}" has disconnected from the Room`);
});
setRoom(room);
},
(error) => {
console.error(`Unable to connect to Room: ${error.message}`);
},
);
console.log('hey');
} catch (error) {
console.error(error);
enqueueSnackbar('something went wrong trying to set up calls', { variant: 'error' });
}
},
[getAuthToken, enqueueSnackbar, setRoom],
[enqueueSnackbar],
);
// every time conversation is selected
@@ -140,8 +92,6 @@ export function CommunicationsProvider({ children }: { children: React.ReactNode
connectToRoom(selectedConversation.id);
} else {
// leave room
setRoom(null);
}
}, [selectedConversation?.id, connectToRoom]);
@@ -161,7 +111,7 @@ export function CommunicationsProvider({ children }: { children: React.ReactNode
});
return (
<CommunicationsContext.Provider value={{ userDeviceSelections, room }}>
<CommunicationsContext.Provider value={{ userDeviceSelections }}>
<audio autoPlay controls ref={localAudioRef} />
{children}
View File
+2 -3
View File
@@ -9,7 +9,6 @@
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
"include": ["src"],
"exclude": ["**/.env"]
}