show call at start of invocation

This commit is contained in:
Roland Osborne 2023-04-14 09:58:00 -07:00
parent 8370ccdf13
commit b246fc8f44
2 changed files with 37 additions and 29 deletions

View File

@ -404,7 +404,7 @@ export function useRingContext() {
} }
calling.current = { }; calling.current = { };
updateState({ callStatus: "dialing" }); updateState({ callStatus: "dialing", callId });
// create call // create call
const { server, token } = access.current; const { server, token } = access.current;
@ -451,7 +451,7 @@ export function useRingContext() {
} }
}, RING); }, RING);
updateState({ callStatus: "ringing", cardId }); updateState({ callStatus: "ringing" });
calling.current = { callId: id, host: true }; calling.current = { callId: id, host: true };
const ice = [{ urls: iceUrl, username: iceUsername, credential: icePassword }]; const ice = [{ urls: iceUrl, username: iceUsername, credential: icePassword }];
await connect('polite', server, callerToken, () => clearInterval(ringInterval), () => clearInterval(aliveInterval), ice); await connect('polite', server, callerToken, () => clearInterval(ringInterval), () => clearInterval(aliveInterval), ice);

View File

@ -136,8 +136,6 @@ export function useRingContext() {
const transmit = async (policy, ice) => { const transmit = async (policy, ice) => {
console.log("TRANSMIT:", ice);
pc.current = new RTCPeerConnection({ iceServers: ice }); pc.current = new RTCPeerConnection({ iceServers: ice });
pc.current.ontrack = (ev) => { pc.current.ontrack = (ev) => {
if (!stream.current) { if (!stream.current) {
@ -186,8 +184,6 @@ console.log("TRANSMIT:", ice);
const connect = async (policy, node, token, clearRing, clearAlive, ice) => { const connect = async (policy, node, token, clearRing, clearAlive, ice) => {
console.log("ICE CONNECT", ice);
// connect signal socket // connect signal socket
connected.current = false; connected.current = false;
candidates.current = []; candidates.current = [];
@ -337,29 +333,30 @@ console.log("TRANSMIT:", ice);
} }
}, },
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; await removeCall(access.current, callId);
if (host) { }
await removeCall(access.current, callId); else {
await removeContactCall(contactNode, contactToken, callId);
}
} }
else { catch (err) {
await removeContactCall(contactNode, contactToken, callId); console.log(err);
}
if (ws.current) {
ws.current.close();
}
if (videoTrack.current) {
videoTrack.current.stop();
videoTrack.current = null;
}
if (audioTrack.current) {
audioTrack.current.stop();
audioTrack.current = null;
} }
}
catch (err) {
console.log(err);
}
ws.current.close();
if (videoTrack.current) {
videoTrack.current.stop();
videoTrack.current = null;
}
if (audioTrack.current) {
audioTrack.current.stop();
audioTrack.current = null;
} }
}, },
call: async (cardId, contactNode, contactToken) => { call: async (cardId, contactNode, contactToken) => {
@ -367,8 +364,19 @@ console.log("TRANSMIT:", ice);
throw new Error("active session"); throw new Error("active session");
} }
calling.current = {};
updateState({ callStatus: "dialing", cardId });
// create call // create call
const call = await addCall(access.current, cardId); let call;
try {
call = await addCall(access.current, cardId);
}
catch (err) {
calling.current = null;
updateState({ callStatus: null });
}
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 });
@ -402,7 +410,7 @@ console.log("TRANSMIT:", ice);
} }
}, RING); }, RING);
updateState({ callStatus: "ringing", cardId }); updateState({ callStatus: "ringing" });
calling.current = { callId: id, host: true }; calling.current = { callId: id, host: true };
const ice = [{ urls: iceUrl, username: iceUsername, credential: icePassword }]; const ice = [{ urls: iceUrl, username: iceUsername, credential: icePassword }];
await connect('polite', window.location.host, callerToken, () => clearInterval(ringInterval), () => clearInterval(aliveInterval), ice); await connect('polite', window.location.host, callerToken, () => clearInterval(ringInterval), () => clearInterval(aliveInterval), ice);