From 657df45a08dd36e88241536764414256659c0805 Mon Sep 17 00:00:00 2001 From: Stefania Date: Thu, 2 Aug 2018 18:06:27 +0200 Subject: [PATCH] implemented re-connect for chrome os, Fixes https://github.com/bcmi-labs/webide/issues/2194 --- src/chrome-app-daemon.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/chrome-app-daemon.js b/src/chrome-app-daemon.js index 918c80e5..b6ed4f7f 100644 --- a/src/chrome-app-daemon.js +++ b/src/chrome-app-daemon.js @@ -18,10 +18,13 @@ * */ -import { takeUntil, filter } from 'rxjs/operators'; +import { interval } from 'rxjs'; +import { filter, startWith, takeUntil } from 'rxjs/operators'; import Daemon from './daemon'; +const POLLING_INTERVAL = 2000; + export default class ChromeOsDaemon extends Daemon { constructor(chromeExtensionId) { super(); @@ -31,15 +34,31 @@ export default class ChromeOsDaemon extends Daemon { command: 'listPorts' })); - this._appConnect(chromeExtensionId); + this.chromeExtensionId = chromeExtensionId; + + this.agentFound + .subscribe(agentFound => { + if (!agentFound) { + this.findApp(); + } + }); + } + + findApp() { + interval(POLLING_INTERVAL) + .pipe(startWith(0)) + .pipe(takeUntil(this.channelOpen.pipe(filter(status => status)))) + .subscribe(() => { + this._appConnect(); + }); } /** * Instantiate connection and events listeners for chrome app */ - _appConnect(chromeExtensionId) { + _appConnect() { if (chrome.runtime) { - this.channel = chrome.runtime.connect(chromeExtensionId); + this.channel = chrome.runtime.connect(this.chromeExtensionId); this.channel.onMessage.addListener(message => { if (message.version) { this.agentInfo = message;