RTC-13903 Fix unable to start IV call after WIFI connection lost behind a VPN

This commit is contained in:
Baptiste Clarey Sjostrand
2023-03-02 17:27:42 +01:00
committed by Salah Benmoussati
parent 12e8fabded
commit 0f0cd96b23

View File

@@ -19,9 +19,11 @@ type StatusCallback = (status: IShellStatus) => void;
class C9ShellHandler { class C9ShellHandler {
private _c9shell: ChildProcess | undefined; private _c9shell: ChildProcess | undefined;
private _curStatus: IShellStatus | undefined; private _curStatus: IShellStatus | undefined;
private _isDisconnected = false;
private _isStarting = false; private _isStarting = false;
private _isTerminating = false; private _isTerminating = false;
private _sender: WebContents; private _sender: WebContents;
private _shouldRestart = false;
private _statusCallback: StatusCallback | undefined; private _statusCallback: StatusCallback | undefined;
constructor(sender: WebContents) { constructor(sender: WebContents) {
@@ -77,7 +79,7 @@ class C9ShellHandler {
/** /**
* Terminates the c9shell process if it was started by this handler. * Terminates the c9shell process if it was started by this handler.
*/ */
public terminateShell() { public terminateShell(shouldRestart = false) {
if (this._isTerminating) { if (this._isTerminating) {
logger.info('c9-shell-handler: _isTerminating, skip terminate'); logger.info('c9-shell-handler: _isTerminating, skip terminate');
return; return;
@@ -90,6 +92,7 @@ class C9ShellHandler {
logger.info('c9-shell-handler: terminate'); logger.info('c9-shell-handler: terminate');
this._isTerminating = true; this._isTerminating = true;
this._shouldRestart = shouldRestart;
this._c9shell.kill(); this._c9shell.kill();
} }
@@ -199,6 +202,10 @@ class C9ShellHandler {
this._c9shell = undefined; this._c9shell = undefined;
this._isTerminating = false; this._isTerminating = false;
this._updateStatus({ status: 'inactive' }); this._updateStatus({ status: 'inactive' });
if (this._shouldRestart) {
this._shouldRestart = false;
this.startShell();
}
}); });
c9Shell.on('spawn', () => { c9Shell.on('spawn', () => {
@@ -210,7 +217,9 @@ class C9ShellHandler {
}); });
c9Shell.stdout.on('data', (data) => { c9Shell.stdout.on('data', (data) => {
logger.info(`c9-shell: ${data.toString().trim()}`); const message: string = data.toString().trim();
logger.info(`c9-shell: ${message}`);
this._updateNetworkStatus(message);
}); });
c9Shell.stderr.on('data', (data) => { c9Shell.stderr.on('data', (data) => {
@@ -219,6 +228,34 @@ class C9ShellHandler {
return c9Shell; return c9Shell;
} }
/**
* Update network status
* @param c9ShellMessage Any message provided by c9-shell
*/
private _updateNetworkStatus(c9ShellMessage: string) {
if (this._isDisconnected) {
if (
c9ShellMessage.includes('NetworkConnectivityService|Internet Available')
) {
this._isDisconnected = false;
this._onNetworkReconnection();
}
} else if (
c9ShellMessage.includes(
'NetworkConnectivityService|No Internet Available',
)
) {
this._isDisconnected = true;
}
}
/**
* Executed after the network connection is restored
*/
private _onNetworkReconnection() {
this.terminateShell(true);
}
} }
let c9ShellHandler: C9ShellHandler | undefined; let c9ShellHandler: C9ShellHandler | undefined;