Skip to content

Commit

Permalink
implemented re-connect for chrome os, Fixes https://github.com/bcmi-l…
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefania committed Aug 2, 2018
1 parent a1e58c6 commit 657df45
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/chrome-app-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit 657df45

Please sign in to comment.