Skip to content

Commit 499e792

Browse files
author
Stefania
committed
fetch min version from API
1 parent 4ac7432 commit 499e792

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/socket-daemon.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { filter, takeUntil, first } from 'rxjs/operators';
2828
import Daemon from './daemon';
2929

3030
// Required agent version
31-
const MIN_VERSION = '1.1.80';
3231
const browser = detect();
3332
const POLLING_INTERVAL = 3500;
3433
const UPLOAD_DONE_TIMER = 5000;
@@ -139,19 +138,25 @@ export default class SocketDaemon extends Daemon {
139138
});
140139

141140
if (found) {
142-
if (this.agentInfo.version && (semVerCompare(this.agentInfo.version, MIN_VERSION) >= 0 || this.agentInfo.version.indexOf('dev') !== -1)) {
143-
return this.agentInfo;
144-
}
145-
146-
updateAttempts += 1;
147-
if (updateAttempts === 0) {
148-
return this.update();
149-
}
150-
if (updateAttempts < 3) {
151-
return timer(10000).subscribe(() => this.update());
152-
}
153-
this.error.next('plugin version incompatible');
154-
return Promise.reject(new Error('plugin version incompatible'));
141+
return fetch('https://s3.amazonaws.com/arduino-create-static/agent-metadata/agent-version.json')
142+
.then(response => response.json().then(data => {
143+
if (this.agentInfo.version && (semVerCompare(this.agentInfo.version, data.Version) >= 0 || this.agentInfo.version.indexOf('dev') !== -1)) {
144+
return this.agentInfo;
145+
}
146+
147+
updateAttempts += 1;
148+
if (updateAttempts === 0) {
149+
return this.update();
150+
}
151+
if (updateAttempts < 3) {
152+
return timer(10000).subscribe(() => this.update());
153+
}
154+
this.error.next('plugin version incompatible');
155+
return Promise.reject(new Error('plugin version incompatible'));
156+
}))
157+
.catch(() =>
158+
// If version API broken, go ahead with current version
159+
this.agentInfo);
155160
}
156161

157162
// Set channelOpen false for the first time

0 commit comments

Comments
 (0)