Skip to content

Commit

Permalink
Regression: Change logic to check if connection is online on unstable…
Browse files Browse the repository at this point in the history
… networks (#25618)

* Change .race for .allsettled so rejections are handled better

* improve to unstable check logic

* CR suggestions
  • Loading branch information
KevLehman committed May 27, 2022
1 parent 195f90a commit 7dd89fc
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions apps/meteor/client/lib/voip/VoIPUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export class VoIPUser extends Emitter<VoipEvents> {

private optionsKeepAliveDebounceTimeInSec = 5;

private optionsKeepAliveDebounceCount = 3;

private attemptRegistration = false;

constructor(private readonly config: VoIPUserConfiguration, mediaRenderer?: IMediaStreamRenderer) {
Expand All @@ -97,6 +95,7 @@ export class VoIPUser extends Emitter<VoipEvents> {
this.networkEmitter = new Emitter<SignalingSocketEvents>();
this.connectionRetryCount = this.config.connectionRetryCount;
this.stop = false;

this.onlineNetworkHandler = this.onNetworkRestored.bind(this);
this.offlineNetworkHandler = this.onNetworkLost.bind(this);
}
Expand Down Expand Up @@ -912,24 +911,19 @@ export class VoIPUser extends Emitter<VoipEvents> {
return;
}
if (this._connectionState !== 'SERVER_RECONNECTING') {
const keepAliveResponse = await this.sendKeepAliveAndWaitForResponse();
if (!keepAliveResponse) {
const connectivityArray = new Array(this.optionsKeepAliveDebounceCount).fill(this.sendKeepAliveAndWaitForResponse(true));
await Promise.race(connectivityArray).then((response): void => {
if (!response) {
this.networkEmitter.emit('disconnected');
}
});
}
/**
* Either we got connected and managed to send keep-alive
* or while attempting keepAlive with debounce, we got connected at moment,
* |keepAliveResponse| will be turned on.
*/
if (keepAliveResponse) {
this.networkEmitter.emit('connected');
let isConnected = false;
try {
await this.sendKeepAliveAndWaitForResponse();
isConnected = true;
} catch (e) {
console.error(`[${e}] Failed to do options ping.`);
} finally {
// Send event only if it's a "change" on the status (avoid unnecessary event flooding)
!isConnected && this.networkEmitter.emit('disconnected');
isConnected && this.networkEmitter.emit('connected');
}
}
// Each seconds check if the network can reach asterisk. If not, try to reconnect
this.startOptionsPingForUnstableNetworks();
}, this.optionsKeepaliveInterval * 1000);
}
Expand Down

0 comments on commit 7dd89fc

Please sign in to comment.