Skip to content

Commit 98c1e38

Browse files
author
Stefania
committed
improved polling and socket reconnect, Fixes #5
1 parent 2ba385b commit 98c1e38

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/socket-daemon.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ export default class SocketDaemon extends Daemon {
9292
* First search in LOOPBACK_ADDRESS, after in LOOPBACK_HOST if in Chrome or Firefox, otherwise vice versa.
9393
*/
9494
findAgent() {
95+
if (this.pluginURL) {
96+
fetch(`${this.pluginURL}/info`)
97+
.then(response => response.json().then(data => {
98+
this.agentInfo = data;
99+
this.agentFound.next(true);
100+
}))
101+
.catch(() => timer(POLLING_INTERVAL).subscribe(() => this.findAgent()));
102+
return;
103+
}
104+
95105
this._tryPorts(orderedPluginAddresses[0])
96106
.catch(() => this._tryPorts(orderedPluginAddresses[1]))
97107
.then(() => this.agentFound.next(true))
@@ -196,9 +206,13 @@ export default class SocketDaemon extends Daemon {
196206
this.channelOpen.next(true);
197207
});
198208

199-
this.socket.on('error', error => this.error.next(error));
209+
this.socket.on('error', error => {
210+
this.socket.disconnect();
211+
this.error.next(error);
212+
});
200213

201214
this.socket.on('disconnect', () => {
215+
this.socket.disconnect();
202216
this.channelOpen.next(false);
203217
});
204218
}

0 commit comments

Comments
 (0)