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,9 +333,7 @@ console.log("TRANSMIT:", ice);
} }
}, },
end: async () => { end: async () => {
if (!calling.current) { if (calling.current?.callId) {
throw new Error('inactive session');
}
try { try {
const { host, callId, contactNode, contactToken } = calling.current; const { host, callId, contactNode, contactToken } = calling.current;
if (host) { if (host) {
@ -352,7 +346,9 @@ console.log("TRANSMIT:", ice);
catch (err) { catch (err) {
console.log(err); console.log(err);
} }
if (ws.current) {
ws.current.close(); ws.current.close();
}
if (videoTrack.current) { if (videoTrack.current) {
videoTrack.current.stop(); videoTrack.current.stop();
videoTrack.current = null; videoTrack.current = null;
@ -361,14 +357,26 @@ console.log("TRANSMIT:", ice);
audioTrack.current.stop(); audioTrack.current.stop();
audioTrack.current = null; audioTrack.current = null;
} }
}
}, },
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", 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);