Skip to content

V2 #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 5, 2019
Prev Previous commit
Next Next commit
Don't use v2 if it's not available
  • Loading branch information
matteosuppo committed Apr 3, 2019
commit 6f73ce9375847d8c3ca392f9aa42b1c803e38680
7 changes: 5 additions & 2 deletions src/socket-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ export default class SocketDaemon extends Daemon {
.subscribe(agentFound => {
if (agentFound) {
this._wsConnect();
this.v2 = new V2(this.pluginURL);
this.agentV2Found.next(this.v2);
const v2 = new V2(this.pluginURL);
v2.init().then(() => {
this.v2 = v2;
this.agentV2Found.next(this.v2);
});
}
else {
this.findAgent();
Expand Down
12 changes: 12 additions & 0 deletions src/socket-daemon.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ export default class SocketDaemonV2 {
this.daemonURL = `${daemonURL}/v2`;
}

// init tries an HEAD
init() {
return fetch(`${this.daemonURL}/pkgs/tools/installed`, {
method: 'HEAD',
}).then(res => {
if (res.status !== 200) {
throw Error('v2 not available');
}
return res;
});
}

// installedTools uses the new v2 apis to ask the daemon a list of the tools already present in the system
installedTools() {
return fetch(`${this.daemonURL}/pkgs/tools/installed`, {
Expand Down