Skip to content

Commit 150e4d5

Browse files
committed
Removed dependency from Uploader, it will be injected by the client.
1 parent 0cd2331 commit 150e4d5

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"lib": "lib"
1616
},
1717
"dependencies": {
18-
"@bcmi-labs/arduino-chromeos-uploader": "https://github.com/bcmi-labs/arduino-chromeos-uploader.git#csarnataro/iot-1597-main-refactoring",
1918
"detect-browser": "^4.8.0",
2019
"rxjs": "^6.5.3",
2120
"semver-compare": "^1.0.0",

src/chrome-os-daemon.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,37 @@
1717
* a commercial license, send an email to [email protected].
1818
*
1919
*/
20-
2120
import WebSerialDaemon from './web-serial-daemon';
2221
import ChromeAppDaemon from './chrome-app-daemon';
2322

2423
/**
2524
* ChromeOSDaemon is a new implementation for ChromeOS which allows
2625
+ to select the legacy Chrome app or the new BETA web serial API,
27-
* based on the the existance of a specific key in the browser CacheStorage,
28-
* which in turn means that the user has installed it from the Google Play Store
26+
* based on the the existance of a `useWebSerial` key available in the constructor.
27+
* Warning: support for WebSerialDaemon is still in alpha, so if you don't know
28+
* how to deal with Web Serial API, just stick with the Chrome App Deamon.
2929
*
3030
*/
3131
export default function ChromeOsDaemon(boardsUrl, options) {
3232

33-
let useWebSerial = null;
33+
let useWebSerial;
3434
let chromeExtensionId;
35+
let Uploader;
36+
let uploaderOptions;
3537

3638
// check chromeExtensionId OR web serial API
3739
if (typeof options === 'string') {
3840
chromeExtensionId = options;
3941
}
4042
else {
41-
useWebSerial = options.useWebSerial;
4243
chromeExtensionId = options.chromeExtensionId;
44+
useWebSerial = options.useWebSerial;
45+
Uploader = options.Uploader;
46+
uploaderOptions = options.uploaderOptions || {};
4347
}
44-
if (useWebSerial === 'true' && 'serial' in navigator) {
45-
this.flavour = new WebSerialDaemon(boardsUrl);
48+
49+
if ('serial' in navigator && useWebSerial === 'true' && !!Uploader) {
50+
this.flavour = new WebSerialDaemon(boardsUrl, Uploader, uploaderOptions);
4651
}
4752
else {
4853
this.flavour = new ChromeAppDaemon(boardsUrl, chromeExtensionId);

src/web-serial-daemon.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
1-
import { Uploader } from '@bcmi-labs/arduino-chromeos-uploader';
21
import {
32
filter, takeUntil
43
} from 'rxjs/operators';
54
import Daemon from './daemon';
65

6+
/**
7+
* WARNING: the WebSerialDaemon with support for the Web Serial API is still in an alpha version.
8+
* At the moment it doesn't implement all the features available in the
9+
* Use at your own risk.
10+
*
11+
* The `Uploader` parameter in the constructor is the component which is
12+
* used to interact with the Web Serial API.
13+
* It must provide a method `upload`.
14+
*/
715
export default class WebSerialDaemon extends Daemon {
8-
constructor(boardsUrl) {
16+
constructor(boardsUrl, Uploader, uploaderOptions) {
917
super(boardsUrl);
1018
this.port = null;
1119
this.agentFound.next(true); // subscribe(() => true);
1220
this.channelOpenStatus.next(true); // subscribe(() => true);
13-
this.uploader = new Uploader({
14-
logger: console,
15-
filters: [
16-
{ usbVendorId: 0x2341 }
17-
],
18-
disconnectCallback: () => {
19-
console.log('DISCONNECTED');
20-
// this.appMessages.next({ ports: [] });
21-
},
22-
connectCallback: () => {
23-
console.log('CONNECTED');
24-
},
25-
sendSupportedBoardsCallback: (supportedBoards) => {
26-
this.supportedBoards.next(supportedBoards);
27-
28-
}
29-
});
30-
21+
this.uploader = new Uploader(uploaderOptions);
3122
}
3223

3324
// // Specific for serial web API on chromebooks

0 commit comments

Comments
 (0)