1 |
|
2 | export default function PandaUSB (options) {
|
3 | if (require('is-browser')) {
|
4 | if (options.wifi) {
|
5 | throw new Error('You cannot use wifi mode in the browser.');
|
6 | }
|
7 | let PandaWebUSB = require('./impl/browser').default;
|
8 | return new PandaWebUSB(options, navigator.usb);
|
9 | }
|
10 | if (options.wifi) {
|
11 | let PandaWifi = require('./impl/wifi').default;
|
12 | return new PandaWifi(options);
|
13 | }
|
14 |
|
15 | if (isTestEnv()) {
|
16 | let PandaMock = require('./impl/mock').default;
|
17 | return new PandaMock(options);
|
18 | }
|
19 | if (require('is-node')) {
|
20 | let PandaNodeUSB = require('./impl/node').default;
|
21 | return new PandaNodeUSB(options);
|
22 | }
|
23 | console.log(process.env);
|
24 | throw new Error('pandajs.PandaUSB: Unable to connect to any usb devices, unsupported environment.');
|
25 | }
|
26 |
|
27 | function isTestEnv () {
|
28 | if (process.env.NODE_ENV === 'test') {
|
29 | return true;
|
30 | }
|
31 | if (process.env.npm_lifecycle_event === 'test') {
|
32 | return true;
|
33 | }
|
34 | return false;
|
35 | }
|