export const NO_ANSWER_MS = 60_000;
* The same when the callee's app was closed and they got a notification
* instead: time to see it, open Quple, and answer (its invite is kept 2 min).
*/
export const NOTIFIED_NO_ANSWER_MS = 100_000;
export const PEER_LOST_MS = 45_000;
export const JOIN_TIMEOUT_MS = 45_000;
* Alone in the room this long while the other side's call screen has been
* up just as long (their heartbeats): one of us is stuck, rejoin. Counted
* from whichever came later, so a callee still loading Jitsi isn't it.
*/
export const ALONE_REJOIN_MS = 30_000;
export const ALONE_END_MS = 120_000;
export const MAX_REJOINS = 3;
* Whether the other side hung up: the server's peerEnded (in a call to
* yourself, endedBy is you either way), or, from a server without it,
* endedBy not being me.
*/
export function peerEnded(st, me) {
return st.peerEnded ?? (!!st.endedBy && st.endedBy !== me);
}
export function decide(s) {
const st = s.status;
const fresh = st !== null && s.statusAt !== null && s.now - s.statusAt < 10_000;
if (st && peerEnded(st, s.me)) {
return { action: 'end', reason: st.peerSeenMsAgo === null ? `${st.peer} didn't answer` : `${st.peer} hung up` };
}
if (s.external) {
if (fresh && st && st.peerSeenMsAgo !== null && st.peerSeenMsAgo > PEER_LOST_MS) {
return { action: 'end', reason: `Lost the connection to ${st.peer}` };
}
return { action: 'none' };
}
if (s.remotes === 0 && fresh && st) {
if (st.peerSeenMsAgo === null && s.now - s.startedAt > NO_ANSWER_MS) {
return { action: 'end', reason: `${st.peer} didn't answer` };
}
if (st.peerSeenMsAgo !== null && st.peerSeenMsAgo > PEER_LOST_MS) {
return { action: 'end', reason: `Lost the connection to ${st.peer}` };
}
}
if (!s.joined && s.now - s.attemptStartedAt > JOIN_TIMEOUT_MS) {
return s.rejoins < MAX_REJOINS
? { action: 'rejoin', why: 'not joined' }
: { action: 'end', reason: "Couldn't connect the call" };
}
if (s.joined && s.remotes === 0 && s.aloneSince !== null) {
const alone = s.now - s.aloneSince;
if (alone > ALONE_END_MS) {
return { action: 'end', reason: st ? `Lost the connection to ${st.peer}` : 'Lost the connection' };
}
const peerHere = fresh && st && st.peerSeenMsAgo !== null && st.peerSeenMsAgo < 10_000 && s.peerSince !== null;
if (peerHere && s.now - Math.max(s.aloneSince, s.peerSince) > ALONE_REJOIN_MS && s.rejoins < MAX_REJOINS) {
return { action: 'rejoin', why: 'peer in the call but not in the room' };
}
}
return { action: 'none' };
}