Properly stops userAgent / peer when audio connection/reconnection fails

Changed the maximum attempts of the UserAgent reconnection (this should be changed when binding audio's websocket to meteor's connection state).
Added a log to monitor WS reconnect attempts.
This commit is contained in:
Mario Jr 2020-10-28 14:38:33 -03:00
parent 8966fbf89a
commit 3e3b648040

View File

@ -27,7 +27,7 @@ const IPV4_FALLBACK_DOMAIN = Meteor.settings.public.app.ipv4FallbackDomain;
const CALL_CONNECT_TIMEOUT = 20000;
const ICE_NEGOTIATION_TIMEOUT = 20000;
const AUDIO_SESSION_NUM_KEY = 'AudioSessionNumber';
const USER_AGENT_RECONNECTION_ATTEMPTS = 3;
const USER_AGENT_RECONNECTION_ATTEMPTS = 7;
const USER_AGENT_RECONNECTION_DELAY_MS = 5000;
const USER_AGENT_CONNECTION_TIMEOUT_MS = 5000;
const ICE_GATHERING_TIMEOUT = MEDIA.iceGatheringTimeout || 5000;
@ -310,15 +310,18 @@ class SIPSession {
});
}
onBeforeUnload() {
this.userRequestedHangup = true;
if (this.userAgent) {
stopUserAgent() {
if (this.userAgent && (typeof this.userAgent.stop === 'function')) {
return this.userAgent.stop();
}
return Promise.resolve();
}
onBeforeUnload() {
this.userRequestedHangup = true;
return this.stopUserAgent();
}
createUserAgent(iceServers) {
return new Promise((resolve, reject) => {
if (this.userRequestedHangup === true) reject();
@ -426,6 +429,9 @@ class SIPSession {
error = 1002;
bridgeError = 'Websocket failed to connect';
}
this.stopUserAgent();
this.callback({
status: this.baseCallStates.failed,
error,
@ -463,6 +469,8 @@ class SIPSession {
if (code === 1006) {
this.stopUserAgent();
this.callback({
status: this.baseCallStates.failed,
error: 1006,
@ -483,6 +491,8 @@ class SIPSession {
resolve();
}).catch(() => {
this.stopUserAgent();
logger.info({
logCode: 'sip_js_session_ua_disconnected',
extraInfo: {
@ -521,6 +531,13 @@ class SIPSession {
this._reconnecting = true;
logger.info({
logCode: 'sip_js_session_ua_reconnection_attempt',
extraInfo: {
callerIdName: this.user.callerIdName,
},
}, `User agent reconnection attempt ${attempts}`);
setTimeout(() => {
this.userAgent.reconnect().then(() => {
this._reconnecting = false;