displaying call at invocation

This commit is contained in:
Roland Osborne 2023-04-14 09:45:07 -07:00
parent 1544512e4a
commit 8370ccdf13

View File

@ -379,32 +379,45 @@ export function useRingContext() {
} }
}, },
end: async () => { end: async () => {
if (!calling.current) { if (calling.current?.callId) {
throw new Error('inactive session'); try {
} const { host, callId, contactNode, contactToken } = calling.current;
try { if (host) {
const { host, callId, contactNode, contactToken } = calling.current; const { server, token } = access.current;
if (host) { await removeCall(server, token, callId);
const { server, token } = access.current; }
await removeCall(server, token, callId); else {
await removeContactCall(contactNode, contactToken, callId);
}
} }
else { catch (err) {
await removeContactCall(contactNode, contactToken, callId); console.log(err);
}
if (ws.current) {
ws.current.close();
} }
} }
catch (err) {
console.log(err);
}
ws.current.close();
}, },
call: async (cardId, contactNode, contactToken) => { call: async (cardId, contactNode, contactToken) => {
if (calling.current) { if (calling.current) {
throw new Error("active session"); throw new Error("active session");
} }
calling.current = { };
updateState({ callStatus: "dialing" });
// create call // create call
const { server, token } = access.current; const { server, token } = access.current;
const call = await addCall(server, token, cardId); let call;
try {
call = await addCall(server, token, cardId);
}
catch (err) {
calling.current = null;
updateState({ callStatus: null });
throw err;
}
const { id, keepAlive, callerToken, calleeToken, iceUrl, iceUsername, icePassword } = call; const { id, keepAlive, callerToken, calleeToken, iceUrl, iceUsername, icePassword } = call;
try { try {
await addContactRing(contactNode, contactToken, { index, callId: id, calleeToken, iceUrl, iceUsername, icePassword }); await addContactRing(contactNode, contactToken, { index, callId: id, calleeToken, iceUrl, iceUsername, icePassword });