Skip to content

Commit 657df45

Browse files
author
Stefania
committed
implemented re-connect for chrome os, Fixes https://github.com/bcmi-labs/webide/issues/2194
1 parent a1e58c6 commit 657df45

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/chrome-app-daemon.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
*
1919
*/
2020

21-
import { takeUntil, filter } from 'rxjs/operators';
21+
import { interval } from 'rxjs';
22+
import { filter, startWith, takeUntil } from 'rxjs/operators';
2223

2324
import Daemon from './daemon';
2425

26+
const POLLING_INTERVAL = 2000;
27+
2528
export default class ChromeOsDaemon extends Daemon {
2629
constructor(chromeExtensionId) {
2730
super();
@@ -31,15 +34,31 @@ export default class ChromeOsDaemon extends Daemon {
3134
command: 'listPorts'
3235
}));
3336

34-
this._appConnect(chromeExtensionId);
37+
this.chromeExtensionId = chromeExtensionId;
38+
39+
this.agentFound
40+
.subscribe(agentFound => {
41+
if (!agentFound) {
42+
this.findApp();
43+
}
44+
});
45+
}
46+
47+
findApp() {
48+
interval(POLLING_INTERVAL)
49+
.pipe(startWith(0))
50+
.pipe(takeUntil(this.channelOpen.pipe(filter(status => status))))
51+
.subscribe(() => {
52+
this._appConnect();
53+
});
3554
}
3655

3756
/**
3857
* Instantiate connection and events listeners for chrome app
3958
*/
40-
_appConnect(chromeExtensionId) {
59+
_appConnect() {
4160
if (chrome.runtime) {
42-
this.channel = chrome.runtime.connect(chromeExtensionId);
61+
this.channel = chrome.runtime.connect(this.chromeExtensionId);
4362
this.channel.onMessage.addListener(message => {
4463
if (message.version) {
4564
this.agentInfo = message;

0 commit comments

Comments
 (0)