@neurosity/sdk 6.2.0 → 6.2.1-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +19 -23
- package/CHANGELOG.md +0 -25
- package/dist/browser/neurosity.iife.js +0 -48712
- package/dist/browser/neurosity.js +0 -666
- package/dist/browser/neurosity.js.map +0 -1
- package/dist/cjs/Neurosity.d.ts +0 -619
- package/dist/cjs/Neurosity.js +0 -1244
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +0 -72
- package/dist/cjs/api/bluetooth/BluetoothClient.js +0 -310
- package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +0 -33
- package/dist/cjs/api/bluetooth/BluetoothTransport.js +0 -2
- package/dist/cjs/api/bluetooth/constants.d.ts +0 -4
- package/dist/cjs/api/bluetooth/constants.js +0 -9
- package/dist/cjs/api/bluetooth/index.d.ts +0 -4
- package/dist/cjs/api/bluetooth/index.js +0 -20
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +0 -70
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +0 -406
- package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.d.ts +0 -63
- package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.js +0 -11
- package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +0 -180
- package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.js +0 -10
- package/dist/cjs/api/bluetooth/types/index.d.ts +0 -31
- package/dist/cjs/api/bluetooth/types/index.js +0 -22
- package/dist/cjs/api/bluetooth/utils/create6DigitPin.d.ts +0 -1
- package/dist/cjs/api/bluetooth/utils/create6DigitPin.js +0 -8
- package/dist/cjs/api/bluetooth/utils/csvBufferToEpoch.d.ts +0 -11
- package/dist/cjs/api/bluetooth/utils/csvBufferToEpoch.js +0 -36
- package/dist/cjs/api/bluetooth/utils/encoding.d.ts +0 -3
- package/dist/cjs/api/bluetooth/utils/encoding.js +0 -22
- package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.d.ts +0 -2
- package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.js +0 -23
- package/dist/cjs/api/bluetooth/utils/stitch.d.ts +0 -5
- package/dist/cjs/api/bluetooth/utils/stitch.js +0 -22
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +0 -54
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +0 -430
- package/dist/cjs/api/bluetooth/web/isMaybeWebWorkerContext.d.ts +0 -1
- package/dist/cjs/api/bluetooth/web/isMaybeWebWorkerContext.js +0 -8
- package/dist/cjs/api/bluetooth/web/isWebBluetoothSupported.d.ts +0 -1
- package/dist/cjs/api/bluetooth/web/isWebBluetoothSupported.js +0 -11
- package/dist/cjs/api/firebase/FirebaseApp.d.ts +0 -20
- package/dist/cjs/api/firebase/FirebaseApp.js +0 -70
- package/dist/cjs/api/firebase/FirebaseDevice.d.ts +0 -68
- package/dist/cjs/api/firebase/FirebaseDevice.js +0 -146
- package/dist/cjs/api/firebase/FirebaseUser.d.ts +0 -53
- package/dist/cjs/api/firebase/FirebaseUser.js +0 -434
- package/dist/cjs/api/firebase/config.d.ts +0 -8
- package/dist/cjs/api/firebase/config.js +0 -11
- package/dist/cjs/api/firebase/deviceStore.d.ts +0 -26
- package/dist/cjs/api/firebase/deviceStore.js +0 -191
- package/dist/cjs/api/firebase/index.d.ts +0 -3
- package/dist/cjs/api/firebase/index.js +0 -19
- package/dist/cjs/api/https/config.d.ts +0 -1
- package/dist/cjs/api/https/config.js +0 -4
- package/dist/cjs/api/https/createOAuthURL.d.ts +0 -3
- package/dist/cjs/api/https/createOAuthURL.js +0 -18
- package/dist/cjs/api/https/getOAuthToken.d.ts +0 -3
- package/dist/cjs/api/https/getOAuthToken.js +0 -34
- package/dist/cjs/api/https/utils.d.ts +0 -2
- package/dist/cjs/api/https/utils.js +0 -13
- package/dist/cjs/api/index.d.ts +0 -109
- package/dist/cjs/api/index.js +0 -307
- package/dist/cjs/index.d.ts +0 -2
- package/dist/cjs/index.js +0 -18
- package/dist/cjs/subscriptions/SubscriptionManager.d.ts +0 -11
- package/dist/cjs/subscriptions/SubscriptionManager.js +0 -27
- package/dist/cjs/timesync/Timesync.d.ts +0 -20
- package/dist/cjs/timesync/Timesync.js +0 -78
- package/dist/cjs/timesync/index.d.ts +0 -1
- package/dist/cjs/timesync/index.js +0 -17
- package/dist/cjs/types/accelerometer.d.ts +0 -10
- package/dist/cjs/types/accelerometer.js +0 -2
- package/dist/cjs/types/actions.d.ts +0 -16
- package/dist/cjs/types/actions.js +0 -2
- package/dist/cjs/types/awareness.d.ts +0 -1
- package/dist/cjs/types/awareness.js +0 -2
- package/dist/cjs/types/brainwaves.d.ts +0 -26
- package/dist/cjs/types/brainwaves.js +0 -2
- package/dist/cjs/types/calm.d.ts +0 -6
- package/dist/cjs/types/calm.js +0 -2
- package/dist/cjs/types/client.d.ts +0 -22
- package/dist/cjs/types/client.js +0 -2
- package/dist/cjs/types/credentials.d.ts +0 -12
- package/dist/cjs/types/credentials.js +0 -2
- package/dist/cjs/types/deviceInfo.d.ts +0 -18
- package/dist/cjs/types/deviceInfo.js +0 -2
- package/dist/cjs/types/epoch.d.ts +0 -12
- package/dist/cjs/types/epoch.js +0 -2
- package/dist/cjs/types/experiment.d.ts +0 -9
- package/dist/cjs/types/experiment.js +0 -2
- package/dist/cjs/types/focus.d.ts +0 -6
- package/dist/cjs/types/focus.js +0 -2
- package/dist/cjs/types/hapticEffects.d.ts +0 -125
- package/dist/cjs/types/hapticEffects.js +0 -2
- package/dist/cjs/types/kinesis.d.ts +0 -6
- package/dist/cjs/types/kinesis.js +0 -2
- package/dist/cjs/types/marker.d.ts +0 -7
- package/dist/cjs/types/marker.js +0 -2
- package/dist/cjs/types/metrics.d.ts +0 -21
- package/dist/cjs/types/metrics.js +0 -2
- package/dist/cjs/types/oauth.d.ts +0 -20
- package/dist/cjs/types/oauth.js +0 -2
- package/dist/cjs/types/options.d.ts +0 -51
- package/dist/cjs/types/options.js +0 -2
- package/dist/cjs/types/sample.d.ts +0 -15
- package/dist/cjs/types/sample.js +0 -2
- package/dist/cjs/types/settings.d.ts +0 -13
- package/dist/cjs/types/settings.js +0 -2
- package/dist/cjs/types/signalQuality.d.ts +0 -13
- package/dist/cjs/types/signalQuality.js +0 -2
- package/dist/cjs/types/skill.d.ts +0 -68
- package/dist/cjs/types/skill.js +0 -2
- package/dist/cjs/types/status.d.ts +0 -26
- package/dist/cjs/types/status.js +0 -22
- package/dist/cjs/types/streaming.d.ts +0 -15
- package/dist/cjs/types/streaming.js +0 -20
- package/dist/cjs/types/subscriptions.d.ts +0 -23
- package/dist/cjs/types/subscriptions.js +0 -2
- package/dist/cjs/types/training.d.ts +0 -19
- package/dist/cjs/types/training.js +0 -2
- package/dist/cjs/types/user.d.ts +0 -12
- package/dist/cjs/types/user.js +0 -2
- package/dist/cjs/utils/errors.d.ts +0 -5
- package/dist/cjs/utils/errors.js +0 -17
- package/dist/cjs/utils/filterInternalKeys.d.ts +0 -3
- package/dist/cjs/utils/filterInternalKeys.js +0 -21
- package/dist/cjs/utils/hapticEffects.d.ts +0 -123
- package/dist/cjs/utils/hapticEffects.js +0 -130
- package/dist/cjs/utils/heartbeat.d.ts +0 -4
- package/dist/cjs/utils/heartbeat.js +0 -41
- package/dist/cjs/utils/is-node.d.ts +0 -1
- package/dist/cjs/utils/is-node.js +0 -9
- package/dist/cjs/utils/metrics.d.ts +0 -1
- package/dist/cjs/utils/metrics.js +0 -56
- package/dist/cjs/utils/oauth.d.ts +0 -9
- package/dist/cjs/utils/oauth.js +0 -92
- package/dist/cjs/utils/pick.d.ts +0 -1
- package/dist/cjs/utils/pick.js +0 -5
- package/dist/cjs/utils/pipes.d.ts +0 -46
- package/dist/cjs/utils/pipes.js +0 -71
- package/dist/cjs/utils/platform.d.ts +0 -30
- package/dist/cjs/utils/platform.js +0 -47
- package/dist/cjs/utils/subscription.d.ts +0 -6
- package/dist/cjs/utils/subscription.js +0 -55
- package/dist/cjs/utils/transferDevice.d.ts +0 -9
- package/dist/cjs/utils/transferDevice.js +0 -2
- package/dist/cjs/utils/whileOnline.d.ts +0 -8
- package/dist/cjs/utils/whileOnline.js +0 -15
- package/dist/electron/index.js +0 -86
- package/dist/electron/index.js.map +0 -1
- package/dist/esm/Neurosity.d.ts +0 -619
- package/dist/esm/Neurosity.js +0 -1213
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +0 -72
- package/dist/esm/api/bluetooth/BluetoothClient.js +0 -306
- package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +0 -33
- package/dist/esm/api/bluetooth/BluetoothTransport.js +0 -1
- package/dist/esm/api/bluetooth/constants.d.ts +0 -4
- package/dist/esm/api/bluetooth/constants.js +0 -6
- package/dist/esm/api/bluetooth/index.d.ts +0 -4
- package/dist/esm/api/bluetooth/index.js +0 -4
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +0 -70
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +0 -402
- package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.d.ts +0 -63
- package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.js +0 -8
- package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +0 -180
- package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.js +0 -9
- package/dist/esm/api/bluetooth/types/index.d.ts +0 -31
- package/dist/esm/api/bluetooth/types/index.js +0 -19
- package/dist/esm/api/bluetooth/utils/create6DigitPin.d.ts +0 -1
- package/dist/esm/api/bluetooth/utils/create6DigitPin.js +0 -4
- package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.d.ts +0 -11
- package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.js +0 -31
- package/dist/esm/api/bluetooth/utils/encoding.d.ts +0 -3
- package/dist/esm/api/bluetooth/utils/encoding.js +0 -17
- package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.d.ts +0 -2
- package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.js +0 -16
- package/dist/esm/api/bluetooth/utils/stitch.d.ts +0 -5
- package/dist/esm/api/bluetooth/utils/stitch.js +0 -18
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +0 -54
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +0 -426
- package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.d.ts +0 -1
- package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.js +0 -4
- package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.d.ts +0 -1
- package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.js +0 -7
- package/dist/esm/api/firebase/FirebaseApp.d.ts +0 -20
- package/dist/esm/api/firebase/FirebaseApp.js +0 -63
- package/dist/esm/api/firebase/FirebaseDevice.d.ts +0 -68
- package/dist/esm/api/firebase/FirebaseDevice.js +0 -139
- package/dist/esm/api/firebase/FirebaseUser.d.ts +0 -53
- package/dist/esm/api/firebase/FirebaseUser.js +0 -426
- package/dist/esm/api/firebase/config.d.ts +0 -8
- package/dist/esm/api/firebase/config.js +0 -8
- package/dist/esm/api/firebase/deviceStore.d.ts +0 -26
- package/dist/esm/api/firebase/deviceStore.js +0 -184
- package/dist/esm/api/firebase/index.d.ts +0 -3
- package/dist/esm/api/firebase/index.js +0 -3
- package/dist/esm/api/https/config.d.ts +0 -1
- package/dist/esm/api/https/config.js +0 -1
- package/dist/esm/api/https/createOAuthURL.d.ts +0 -3
- package/dist/esm/api/https/createOAuthURL.js +0 -11
- package/dist/esm/api/https/getOAuthToken.d.ts +0 -3
- package/dist/esm/api/https/getOAuthToken.js +0 -27
- package/dist/esm/api/https/utils.d.ts +0 -2
- package/dist/esm/api/https/utils.js +0 -9
- package/dist/esm/api/index.d.ts +0 -109
- package/dist/esm/api/index.js +0 -300
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.js +0 -2
- package/dist/esm/neurosity.mjs +0 -48700
- package/dist/esm/subscriptions/SubscriptionManager.d.ts +0 -11
- package/dist/esm/subscriptions/SubscriptionManager.js +0 -23
- package/dist/esm/timesync/Timesync.d.ts +0 -20
- package/dist/esm/timesync/Timesync.js +0 -71
- package/dist/esm/timesync/index.d.ts +0 -1
- package/dist/esm/timesync/index.js +0 -1
- package/dist/esm/types/accelerometer.d.ts +0 -10
- package/dist/esm/types/accelerometer.js +0 -1
- package/dist/esm/types/actions.d.ts +0 -16
- package/dist/esm/types/actions.js +0 -1
- package/dist/esm/types/awareness.d.ts +0 -1
- package/dist/esm/types/awareness.js +0 -1
- package/dist/esm/types/brainwaves.d.ts +0 -26
- package/dist/esm/types/brainwaves.js +0 -1
- package/dist/esm/types/calm.d.ts +0 -6
- package/dist/esm/types/calm.js +0 -1
- package/dist/esm/types/client.d.ts +0 -22
- package/dist/esm/types/client.js +0 -1
- package/dist/esm/types/credentials.d.ts +0 -12
- package/dist/esm/types/credentials.js +0 -1
- package/dist/esm/types/deviceInfo.d.ts +0 -18
- package/dist/esm/types/deviceInfo.js +0 -1
- package/dist/esm/types/epoch.d.ts +0 -12
- package/dist/esm/types/epoch.js +0 -1
- package/dist/esm/types/experiment.d.ts +0 -9
- package/dist/esm/types/experiment.js +0 -1
- package/dist/esm/types/focus.d.ts +0 -6
- package/dist/esm/types/focus.js +0 -1
- package/dist/esm/types/hapticEffects.d.ts +0 -125
- package/dist/esm/types/hapticEffects.js +0 -1
- package/dist/esm/types/kinesis.d.ts +0 -6
- package/dist/esm/types/kinesis.js +0 -1
- package/dist/esm/types/marker.d.ts +0 -7
- package/dist/esm/types/marker.js +0 -1
- package/dist/esm/types/metrics.d.ts +0 -21
- package/dist/esm/types/metrics.js +0 -1
- package/dist/esm/types/oauth.d.ts +0 -20
- package/dist/esm/types/oauth.js +0 -1
- package/dist/esm/types/options.d.ts +0 -51
- package/dist/esm/types/options.js +0 -1
- package/dist/esm/types/sample.d.ts +0 -15
- package/dist/esm/types/sample.js +0 -1
- package/dist/esm/types/settings.d.ts +0 -13
- package/dist/esm/types/settings.js +0 -1
- package/dist/esm/types/signalQuality.d.ts +0 -13
- package/dist/esm/types/signalQuality.js +0 -1
- package/dist/esm/types/skill.d.ts +0 -68
- package/dist/esm/types/skill.js +0 -1
- package/dist/esm/types/status.d.ts +0 -26
- package/dist/esm/types/status.js +0 -19
- package/dist/esm/types/streaming.d.ts +0 -15
- package/dist/esm/types/streaming.js +0 -17
- package/dist/esm/types/subscriptions.d.ts +0 -23
- package/dist/esm/types/subscriptions.js +0 -1
- package/dist/esm/types/training.d.ts +0 -19
- package/dist/esm/types/training.js +0 -1
- package/dist/esm/types/user.d.ts +0 -12
- package/dist/esm/types/user.js +0 -1
- package/dist/esm/utils/errors.d.ts +0 -5
- package/dist/esm/utils/errors.js +0 -11
- package/dist/esm/utils/filterInternalKeys.d.ts +0 -3
- package/dist/esm/utils/filterInternalKeys.js +0 -17
- package/dist/esm/utils/hapticEffects.d.ts +0 -123
- package/dist/esm/utils/hapticEffects.js +0 -125
- package/dist/esm/utils/heartbeat.d.ts +0 -4
- package/dist/esm/utils/heartbeat.js +0 -33
- package/dist/esm/utils/is-node.d.ts +0 -1
- package/dist/esm/utils/is-node.js +0 -5
- package/dist/esm/utils/metrics.d.ts +0 -1
- package/dist/esm/utils/metrics.js +0 -52
- package/dist/esm/utils/oauth.d.ts +0 -9
- package/dist/esm/utils/oauth.js +0 -64
- package/dist/esm/utils/pick.d.ts +0 -1
- package/dist/esm/utils/pick.js +0 -1
- package/dist/esm/utils/pipes.d.ts +0 -46
- package/dist/esm/utils/pipes.js +0 -65
- package/dist/esm/utils/platform.d.ts +0 -30
- package/dist/esm/utils/platform.js +0 -41
- package/dist/esm/utils/subscription.d.ts +0 -6
- package/dist/esm/utils/subscription.js +0 -24
- package/dist/esm/utils/transferDevice.d.ts +0 -9
- package/dist/esm/utils/transferDevice.js +0 -1
- package/dist/esm/utils/whileOnline.d.ts +0 -8
- package/dist/esm/utils/whileOnline.js +0 -11
- package/dist/examples/auth.html +0 -32
- package/dist/examples/cloud.html +0 -17
- package/dist/examples/index.html +0 -1
- package/dist/examples/neurosity.iife.js +0 -48712
- package/dist/examples/neurosity.js +0 -666
- package/dist/examples/neurosity.mjs +0 -48700
- package/dist/examples/training.html +0 -49
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.WebBluetoothTransport = void 0;
|
|
13
|
-
const ipk_1 = require("@neurosity/ipk");
|
|
14
|
-
const ipk_2 = require("@neurosity/ipk");
|
|
15
|
-
const ipk_3 = require("@neurosity/ipk");
|
|
16
|
-
const ipk_4 = require("@neurosity/ipk");
|
|
17
|
-
const rxjs_1 = require("rxjs");
|
|
18
|
-
const rxjs_2 = require("rxjs");
|
|
19
|
-
const operators_1 = require("rxjs/operators");
|
|
20
|
-
const operators_2 = require("rxjs/operators");
|
|
21
|
-
const operators_3 = require("rxjs/operators");
|
|
22
|
-
const isWebBluetoothSupported_1 = require("./isWebBluetoothSupported");
|
|
23
|
-
const create6DigitPin_1 = require("../utils/create6DigitPin");
|
|
24
|
-
const stitch_1 = require("../utils/stitch");
|
|
25
|
-
const encoding_1 = require("../utils/encoding");
|
|
26
|
-
const types_1 = require("../types");
|
|
27
|
-
const constants_1 = require("../constants");
|
|
28
|
-
const constants_2 = require("../constants");
|
|
29
|
-
const osHasBluetoothSupport_1 = require("../utils/osHasBluetoothSupport");
|
|
30
|
-
const defaultOptions = {
|
|
31
|
-
autoConnect: true
|
|
32
|
-
};
|
|
33
|
-
class WebBluetoothTransport {
|
|
34
|
-
constructor(options = {}) {
|
|
35
|
-
this.type = types_1.TRANSPORT_TYPE.WEB;
|
|
36
|
-
this.characteristicsByName = {};
|
|
37
|
-
this.connection$ = new rxjs_1.BehaviorSubject(types_1.BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
38
|
-
this.pendingActions$ = new rxjs_1.BehaviorSubject([]);
|
|
39
|
-
this.logs$ = new rxjs_1.ReplaySubject(10);
|
|
40
|
-
this.onDisconnected$ = this._onDisconnected().pipe((0, operators_3.share)());
|
|
41
|
-
this.connectionStream$ = this.connection$
|
|
42
|
-
.asObservable()
|
|
43
|
-
.pipe((0, operators_1.filter)((connection) => !!connection), (0, operators_2.distinctUntilChanged)(), (0, operators_2.shareReplay)(1));
|
|
44
|
-
this._isAutoConnectEnabled$ = new rxjs_1.ReplaySubject(1);
|
|
45
|
-
this.options = Object.assign(Object.assign({}, defaultOptions), options);
|
|
46
|
-
if (!(0, isWebBluetoothSupported_1.isWebBluetoothSupported)()) {
|
|
47
|
-
const errorMessage = "Web Bluetooth is not supported";
|
|
48
|
-
this.addLog(errorMessage);
|
|
49
|
-
throw new Error(errorMessage);
|
|
50
|
-
}
|
|
51
|
-
this._isAutoConnectEnabled$.subscribe((autoConnect) => {
|
|
52
|
-
this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
|
|
53
|
-
});
|
|
54
|
-
this._isAutoConnectEnabled$.next(this.options.autoConnect);
|
|
55
|
-
this.connection$.asObservable().subscribe((connection) => {
|
|
56
|
-
this.addLog(`connection status is ${connection}`);
|
|
57
|
-
});
|
|
58
|
-
this.onDisconnected$.subscribe(() => {
|
|
59
|
-
this.connection$.next(types_1.BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
_getPairedDevices() {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
return yield navigator.bluetooth.getDevices();
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
_autoConnect(selectedDevice$) {
|
|
68
|
-
return this._isAutoConnectEnabled$.pipe((0, operators_1.switchMap)((isAutoConnectEnabled) => isAutoConnectEnabled
|
|
69
|
-
? (0, rxjs_1.merge)(selectedDevice$, this.onDisconnected$.pipe((0, operators_1.switchMap)(() => selectedDevice$)))
|
|
70
|
-
: rxjs_2.NEVER), (0, operators_1.switchMap)((selectedDevice) => (0, osHasBluetoothSupport_1.osHasBluetoothSupport)(selectedDevice) ? (0, rxjs_1.of)(selectedDevice) : rxjs_2.EMPTY), (0, operators_1.switchMap)((selectedDevice) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
var _a;
|
|
72
|
-
const { deviceNickname } = selectedDevice;
|
|
73
|
-
if (this.isConnected()) {
|
|
74
|
-
this.addLog(`Auto connect: ${deviceNickname} is already connected. Skipping auto connect.`);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const [devicesError, devices] = yield this._getPairedDevices()
|
|
78
|
-
.then((devices) => [null, devices])
|
|
79
|
-
.catch((error) => [error, null]);
|
|
80
|
-
if (devicesError) {
|
|
81
|
-
throw new Error(`failed to get devices: ${(_a = devicesError === null || devicesError === void 0 ? void 0 : devicesError.message) !== null && _a !== void 0 ? _a : devicesError}`);
|
|
82
|
-
}
|
|
83
|
-
this.addLog(`Auto connect: found ${devices.length} devices ${devices
|
|
84
|
-
.map(({ name }) => name)
|
|
85
|
-
.join(", ")}`);
|
|
86
|
-
// @important - Using `findLast` instead of `find` because somehow the browser
|
|
87
|
-
// is finding multiple peripherals with the same name
|
|
88
|
-
const device = devices.findLast((device) => device.name === deviceNickname);
|
|
89
|
-
if (!device) {
|
|
90
|
-
throw new Error(`couldn't find selected device in the list of paired devices.`);
|
|
91
|
-
}
|
|
92
|
-
this.addLog(`Auto connect: ${deviceNickname} was detected and previously paired`);
|
|
93
|
-
return device;
|
|
94
|
-
})), (0, operators_1.tap)(() => {
|
|
95
|
-
this.connection$.next(types_1.BLUETOOTH_CONNECTION.SCANNING);
|
|
96
|
-
}), (0, operators_1.switchMap)((device) => onAdvertisementReceived(device)), (0, operators_1.switchMap)((advertisement) => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
this.addLog(`Advertisement received for ${advertisement.device.name}`);
|
|
98
|
-
return yield this.getServerServiceAndCharacteristics(advertisement.device);
|
|
99
|
-
})));
|
|
100
|
-
}
|
|
101
|
-
enableAutoConnect(autoConnect) {
|
|
102
|
-
this._isAutoConnectEnabled$.next(autoConnect);
|
|
103
|
-
}
|
|
104
|
-
addLog(log) {
|
|
105
|
-
this.logs$.next(log);
|
|
106
|
-
}
|
|
107
|
-
isConnected() {
|
|
108
|
-
const connection = this.connection$.getValue();
|
|
109
|
-
return connection === types_1.BLUETOOTH_CONNECTION.CONNECTED;
|
|
110
|
-
}
|
|
111
|
-
connection() {
|
|
112
|
-
return this.connectionStream$;
|
|
113
|
-
}
|
|
114
|
-
connect(deviceNickname) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
try {
|
|
117
|
-
// requires user gesture
|
|
118
|
-
const device = yield this.requestDevice(deviceNickname);
|
|
119
|
-
yield this.getServerServiceAndCharacteristics(device);
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
return Promise.reject(error);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
requestDevice(deviceNickname) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
try {
|
|
129
|
-
this.addLog("Requesting Bluetooth Device...");
|
|
130
|
-
const prefixes = ipk_3.BLUETOOTH_DEVICE_NAME_PREFIXES.map((namePrefix) => ({
|
|
131
|
-
namePrefix
|
|
132
|
-
}));
|
|
133
|
-
// Ability to only show selectedDevice if provided
|
|
134
|
-
const filters = deviceNickname
|
|
135
|
-
? [
|
|
136
|
-
{
|
|
137
|
-
name: deviceNickname
|
|
138
|
-
}
|
|
139
|
-
]
|
|
140
|
-
: prefixes;
|
|
141
|
-
const device = yield window.navigator.bluetooth.requestDevice({
|
|
142
|
-
filters: [
|
|
143
|
-
...filters,
|
|
144
|
-
{
|
|
145
|
-
manufacturerData: [
|
|
146
|
-
{
|
|
147
|
-
companyIdentifier: ipk_4.BLUETOOTH_COMPANY_IDENTIFIER_HEX
|
|
148
|
-
}
|
|
149
|
-
]
|
|
150
|
-
}
|
|
151
|
-
],
|
|
152
|
-
optionalServices: [ipk_1.BLUETOOTH_PRIMARY_SERVICE_UUID_HEX]
|
|
153
|
-
});
|
|
154
|
-
return device;
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
return Promise.reject(error);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
getServerServiceAndCharacteristics(device) {
|
|
162
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
try {
|
|
164
|
-
this.device = device;
|
|
165
|
-
const isConnecting = this.connection$.getValue() === types_1.BLUETOOTH_CONNECTION.CONNECTING;
|
|
166
|
-
if (!isConnecting) {
|
|
167
|
-
this.connection$.next(types_1.BLUETOOTH_CONNECTION.CONNECTING);
|
|
168
|
-
}
|
|
169
|
-
this.server = yield device.gatt.connect();
|
|
170
|
-
this.addLog(`Getting service...`);
|
|
171
|
-
this.service = yield this.server.getPrimaryService(ipk_1.BLUETOOTH_PRIMARY_SERVICE_UUID_HEX);
|
|
172
|
-
this.addLog(`Got service ${this.service.uuid}, getting characteristics...`);
|
|
173
|
-
const characteristicsList = yield this.service.getCharacteristics();
|
|
174
|
-
this.addLog(`Got characteristics`);
|
|
175
|
-
this.characteristicsByName = Object.fromEntries(characteristicsList.map((characteristic) => [
|
|
176
|
-
constants_2.CHARACTERISTIC_UUIDS_TO_NAMES[characteristic.uuid],
|
|
177
|
-
characteristic
|
|
178
|
-
]));
|
|
179
|
-
this.connection$.next(types_1.BLUETOOTH_CONNECTION.CONNECTED);
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
return Promise.reject(error);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
_onDisconnected() {
|
|
187
|
-
return this.connection$
|
|
188
|
-
.asObservable()
|
|
189
|
-
.pipe((0, operators_1.switchMap)((connection) => connection === types_1.BLUETOOTH_CONNECTION.CONNECTED
|
|
190
|
-
? fromDOMEvent(this.device, "gattserverdisconnected")
|
|
191
|
-
: rxjs_2.NEVER));
|
|
192
|
-
}
|
|
193
|
-
disconnect() {
|
|
194
|
-
var _a, _b;
|
|
195
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
-
const isDeviceConnected = (_b = (_a = this === null || this === void 0 ? void 0 : this.device) === null || _a === void 0 ? void 0 : _a.gatt) === null || _b === void 0 ? void 0 : _b.connected;
|
|
197
|
-
if (isDeviceConnected) {
|
|
198
|
-
this.device.gatt.disconnect();
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
*
|
|
204
|
-
* Bluetooth GATT attributes, services, characteristics, etc. are invalidated
|
|
205
|
-
* when a device disconnects. This means your code should always retrieve
|
|
206
|
-
* (through getPrimaryService(s), getCharacteristic(s), etc.) these attributes
|
|
207
|
-
* after reconnecting.
|
|
208
|
-
*/
|
|
209
|
-
getCharacteristicByName(characteristicName) {
|
|
210
|
-
var _a;
|
|
211
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
212
|
-
return (_a = this.characteristicsByName) === null || _a === void 0 ? void 0 : _a[characteristicName];
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
subscribeToCharacteristic({ characteristicName, manageNotifications = true }) {
|
|
216
|
-
const data$ = (0, rxjs_1.defer)(() => this.getCharacteristicByName(characteristicName)).pipe((0, operators_1.switchMap)((characteristic) => __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
var _a;
|
|
218
|
-
if (this.isConnected() && manageNotifications) {
|
|
219
|
-
try {
|
|
220
|
-
yield characteristic.startNotifications();
|
|
221
|
-
this.addLog(`Started notifications for ${characteristicName} characteristic`);
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
this.addLog(`Attemped to stop notifications for ${characteristicName} characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return characteristic;
|
|
228
|
-
})), (0, operators_1.switchMap)((characteristic) => {
|
|
229
|
-
return fromDOMEvent(characteristic, "characteristicvaluechanged", () => __awaiter(this, void 0, void 0, function* () {
|
|
230
|
-
var _a;
|
|
231
|
-
if (this.isConnected() && manageNotifications) {
|
|
232
|
-
try {
|
|
233
|
-
yield characteristic.stopNotifications();
|
|
234
|
-
this.addLog(`Stopped notifications for ${characteristicName} characteristic`);
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
this.addLog(`Attemped to stop notifications for ${characteristicName} characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}));
|
|
241
|
-
}), (0, operators_1.map)((event) => {
|
|
242
|
-
const buffer = event.target.value;
|
|
243
|
-
const decoded = (0, encoding_1.decode)(this.type, buffer);
|
|
244
|
-
this.addLog(`Received chunk with buffer size of ${buffer.byteLength} and decoded size ${decoded.length} for ${characteristicName} characteristic: \n${decoded}`);
|
|
245
|
-
return decoded;
|
|
246
|
-
}), (0, stitch_1.stitchChunks)({ delimiter: ipk_2.BLUETOOTH_CHUNK_DELIMITER }), (0, operators_1.map)((payload) => {
|
|
247
|
-
var _a;
|
|
248
|
-
try {
|
|
249
|
-
return JSON.parse(payload);
|
|
250
|
-
}
|
|
251
|
-
catch (error) {
|
|
252
|
-
this.addLog(`Failed to parse JSON for ${characteristicName} characteristic. Falling back to unparsed string. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
253
|
-
return payload;
|
|
254
|
-
}
|
|
255
|
-
})
|
|
256
|
-
// when streaming at ultra-low latency, the logs will slow down rendering
|
|
257
|
-
// tap((data) => {
|
|
258
|
-
// this.addLog(
|
|
259
|
-
// `Received data for ${characteristicName} characteristic: \n${JSON.stringify(
|
|
260
|
-
// data,
|
|
261
|
-
// null,
|
|
262
|
-
// 2
|
|
263
|
-
// )}`
|
|
264
|
-
// );
|
|
265
|
-
// })
|
|
266
|
-
);
|
|
267
|
-
return this.connection$.pipe((0, operators_1.switchMap)((connection) => connection === types_1.BLUETOOTH_CONNECTION.CONNECTED ? data$ : rxjs_2.NEVER));
|
|
268
|
-
}
|
|
269
|
-
readCharacteristic(characteristicName, parse = false) {
|
|
270
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
-
try {
|
|
272
|
-
this.addLog(`Reading characteristic: ${characteristicName}`);
|
|
273
|
-
const characteristic = yield this.getCharacteristicByName(characteristicName);
|
|
274
|
-
if (!characteristic) {
|
|
275
|
-
this.addLog(`Did not fund ${characteristicName} characteristic`);
|
|
276
|
-
return Promise.reject(`Did not find characteristic by the name: ${characteristicName}`);
|
|
277
|
-
}
|
|
278
|
-
const value = yield characteristic.readValue();
|
|
279
|
-
const uint8Array = value;
|
|
280
|
-
const decodedValue = (0, encoding_1.decode)(this.type, uint8Array);
|
|
281
|
-
const data = parse ? JSON.parse(decodedValue) : decodedValue;
|
|
282
|
-
this.addLog(`Received read data from ${characteristicName} characteristic: \n${data}`);
|
|
283
|
-
return data;
|
|
284
|
-
}
|
|
285
|
-
catch (error) {
|
|
286
|
-
return Promise.reject(`Error reading characteristic: ${error.message}`);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
writeCharacteristic(characteristicName, data) {
|
|
291
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
292
|
-
this.addLog(`Writing characteristic: ${characteristicName}`);
|
|
293
|
-
const characteristic = yield this.getCharacteristicByName(characteristicName);
|
|
294
|
-
if (!characteristic) {
|
|
295
|
-
this.addLog(`Did not fund ${characteristicName} characteristic`);
|
|
296
|
-
return Promise.reject(`Did not find characteristic by the name: ${characteristicName}`);
|
|
297
|
-
}
|
|
298
|
-
const encoded = (0, encoding_1.encode)(this.type, data);
|
|
299
|
-
yield characteristic.writeValueWithResponse(encoded);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
_addPendingAction(actionId) {
|
|
303
|
-
const actions = this.pendingActions$.getValue();
|
|
304
|
-
this.pendingActions$.next([...actions, actionId]);
|
|
305
|
-
}
|
|
306
|
-
_removePendingAction(actionId) {
|
|
307
|
-
const actions = this.pendingActions$.getValue();
|
|
308
|
-
this.pendingActions$.next(actions.filter((id) => id !== actionId));
|
|
309
|
-
}
|
|
310
|
-
_autoToggleActionNotifications(selectedDevice$) {
|
|
311
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
-
let actionsCharacteristic;
|
|
313
|
-
let started = false;
|
|
314
|
-
const sideEffects$ = this.connection$.asObservable().pipe((0, operators_1.switchMap)((connection) => connection === types_1.BLUETOOTH_CONNECTION.CONNECTED
|
|
315
|
-
? (0, rxjs_1.defer)(() => this.getCharacteristicByName("actions")).pipe((0, operators_1.switchMap)((characteristic) => {
|
|
316
|
-
actionsCharacteristic = characteristic;
|
|
317
|
-
return this.pendingActions$;
|
|
318
|
-
}))
|
|
319
|
-
: rxjs_2.NEVER), (0, operators_1.tap)((pendingActions) => __awaiter(this, void 0, void 0, function* () {
|
|
320
|
-
var _a, _b;
|
|
321
|
-
const hasPendingActions = !!pendingActions.length;
|
|
322
|
-
if (hasPendingActions && !started) {
|
|
323
|
-
started = true;
|
|
324
|
-
try {
|
|
325
|
-
yield actionsCharacteristic.startNotifications();
|
|
326
|
-
this.addLog(`Started notifications for [actions] characteristic`);
|
|
327
|
-
}
|
|
328
|
-
catch (error) {
|
|
329
|
-
this.addLog(`Attemped to start notifications for [actions] characteristic: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (!hasPendingActions && started) {
|
|
333
|
-
started = false;
|
|
334
|
-
try {
|
|
335
|
-
yield actionsCharacteristic.stopNotifications();
|
|
336
|
-
this.addLog(`Stopped notifications for actions characteristic`);
|
|
337
|
-
}
|
|
338
|
-
catch (error) {
|
|
339
|
-
this.addLog(`Attemped to stop notifications for [actions] characteristic: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
})));
|
|
343
|
-
selectedDevice$
|
|
344
|
-
.pipe((0, operators_1.switchMap)((selectedDevice) => !(0, osHasBluetoothSupport_1.osHasBluetoothSupport)(selectedDevice) ? rxjs_2.EMPTY : sideEffects$))
|
|
345
|
-
.subscribe();
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
dispatchAction({ characteristicName, action }) {
|
|
349
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
350
|
-
const { responseRequired = false, responseTimeout = constants_1.DEFAULT_ACTION_RESPONSE_TIMEOUT } = action;
|
|
351
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
352
|
-
const characteristic = yield this.getCharacteristicByName(characteristicName).catch(() => {
|
|
353
|
-
reject(`Did not find characteristic by the name: ${characteristicName}`);
|
|
354
|
-
});
|
|
355
|
-
if (!characteristic) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
const actionId = (0, create6DigitPin_1.create6DigitPin)(); // use to later identify and filter response
|
|
359
|
-
const payload = JSON.stringify(Object.assign({ actionId }, action)); // add the response id to the action
|
|
360
|
-
this.addLog(`Dispatched action with id ${actionId}`);
|
|
361
|
-
if (responseRequired && responseTimeout) {
|
|
362
|
-
this._addPendingAction(actionId);
|
|
363
|
-
const timeout = (0, rxjs_1.timer)(responseTimeout).subscribe(() => {
|
|
364
|
-
this._removePendingAction(actionId);
|
|
365
|
-
reject(`Action with id ${actionId} timed out after ${responseTimeout}ms`);
|
|
366
|
-
});
|
|
367
|
-
// listen for a response before writing
|
|
368
|
-
this.subscribeToCharacteristic({
|
|
369
|
-
characteristicName,
|
|
370
|
-
manageNotifications: false
|
|
371
|
-
})
|
|
372
|
-
.pipe((0, operators_1.filter)((response) => (response === null || response === void 0 ? void 0 : response.actionId) === actionId), (0, operators_3.take)(1))
|
|
373
|
-
.subscribe((response) => {
|
|
374
|
-
timeout.unsubscribe();
|
|
375
|
-
this._removePendingAction(actionId);
|
|
376
|
-
resolve(response);
|
|
377
|
-
});
|
|
378
|
-
// register action by writing
|
|
379
|
-
this.writeCharacteristic(characteristicName, payload).catch((error) => {
|
|
380
|
-
this._removePendingAction(actionId);
|
|
381
|
-
reject(error.message);
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
this.writeCharacteristic(characteristicName, payload)
|
|
386
|
-
.then(() => {
|
|
387
|
-
resolve(null);
|
|
388
|
-
})
|
|
389
|
-
.catch((error) => {
|
|
390
|
-
reject(error.message);
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
}));
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
exports.WebBluetoothTransport = WebBluetoothTransport;
|
|
398
|
-
function fromDOMEvent(target, eventName, beforeRemove) {
|
|
399
|
-
return (0, rxjs_2.fromEventPattern)((addHandler) => {
|
|
400
|
-
target.addEventListener(eventName, addHandler);
|
|
401
|
-
}, (removeHandler) => __awaiter(this, void 0, void 0, function* () {
|
|
402
|
-
if (beforeRemove) {
|
|
403
|
-
yield beforeRemove();
|
|
404
|
-
}
|
|
405
|
-
target.removeEventListener(eventName, removeHandler);
|
|
406
|
-
}));
|
|
407
|
-
}
|
|
408
|
-
function onAdvertisementReceived(device) {
|
|
409
|
-
return new rxjs_2.Observable((subscriber) => {
|
|
410
|
-
const abortController = new AbortController();
|
|
411
|
-
const { signal } = abortController;
|
|
412
|
-
const listener = device.addEventListener("advertisementreceived", (advertisement) => {
|
|
413
|
-
abortController.abort();
|
|
414
|
-
subscriber.next(advertisement);
|
|
415
|
-
subscriber.complete();
|
|
416
|
-
}, {
|
|
417
|
-
once: true
|
|
418
|
-
});
|
|
419
|
-
try {
|
|
420
|
-
device.watchAdvertisements({ signal });
|
|
421
|
-
}
|
|
422
|
-
catch (error) {
|
|
423
|
-
subscriber.error(error);
|
|
424
|
-
}
|
|
425
|
-
return () => {
|
|
426
|
-
abortController.abort();
|
|
427
|
-
device.removeEventListener("advertisementreceived", listener);
|
|
428
|
-
};
|
|
429
|
-
});
|
|
430
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isMaybeWebWorkerContext: () => boolean;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMaybeWebWorkerContext = void 0;
|
|
4
|
-
const self = this;
|
|
5
|
-
const isMaybeWebWorkerContext = () => {
|
|
6
|
-
return self && (self === null || self === void 0 ? void 0 : self.document) === undefined;
|
|
7
|
-
};
|
|
8
|
-
exports.isMaybeWebWorkerContext = isMaybeWebWorkerContext;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isWebBluetoothSupported(): boolean;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWebBluetoothSupported = void 0;
|
|
4
|
-
const isMaybeWebWorkerContext_1 = require("./isMaybeWebWorkerContext");
|
|
5
|
-
function isWebBluetoothSupported() {
|
|
6
|
-
var _a;
|
|
7
|
-
return (typeof window !== "undefined" &&
|
|
8
|
-
((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.bluetooth) &&
|
|
9
|
-
!(0, isMaybeWebWorkerContext_1.isMaybeWebWorkerContext)());
|
|
10
|
-
}
|
|
11
|
-
exports.isWebBluetoothSupported = isWebBluetoothSupported;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import firebase from "firebase/app";
|
|
2
|
-
import "firebase/database";
|
|
3
|
-
import "firebase/auth";
|
|
4
|
-
import "firebase/functions";
|
|
5
|
-
import "firebase/firestore";
|
|
6
|
-
import { SDKOptions } from "../../types/options";
|
|
7
|
-
export declare const SERVER_TIMESTAMP: Object;
|
|
8
|
-
/**
|
|
9
|
-
* @hidden
|
|
10
|
-
*/
|
|
11
|
-
export declare class FirebaseApp {
|
|
12
|
-
protected standalone: boolean;
|
|
13
|
-
app: firebase.app.App;
|
|
14
|
-
constructor(options: SDKOptions);
|
|
15
|
-
private getApp;
|
|
16
|
-
connectEmulators(options: SDKOptions): void;
|
|
17
|
-
goOnline(): void;
|
|
18
|
-
goOffline(): void;
|
|
19
|
-
disconnect(): Promise<any>;
|
|
20
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FirebaseApp = exports.SERVER_TIMESTAMP = void 0;
|
|
7
|
-
const app_1 = __importDefault(require("firebase/app"));
|
|
8
|
-
require("firebase/database");
|
|
9
|
-
require("firebase/auth");
|
|
10
|
-
require("firebase/functions");
|
|
11
|
-
require("firebase/firestore");
|
|
12
|
-
const config_1 = require("./config");
|
|
13
|
-
exports.SERVER_TIMESTAMP = app_1.default.database.ServerValue.TIMESTAMP;
|
|
14
|
-
/**
|
|
15
|
-
* @hidden
|
|
16
|
-
*/
|
|
17
|
-
class FirebaseApp {
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this.app = this.getApp(options.deviceId);
|
|
20
|
-
this.standalone = this.app.name === options.deviceId;
|
|
21
|
-
if (options.emulator) {
|
|
22
|
-
this.connectEmulators(options);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
getApp(deviceId) {
|
|
26
|
-
const moduleApps = app_1.default.apps;
|
|
27
|
-
const browserApps = typeof window !== "undefined" &&
|
|
28
|
-
"firebase" in window &&
|
|
29
|
-
"apps" in window.firebase
|
|
30
|
-
? window["firebase"]["apps"]
|
|
31
|
-
: [];
|
|
32
|
-
const neurosityApp = [...moduleApps, ...browserApps].find((app) => app.name === "[DEFAULT]" &&
|
|
33
|
-
app.options.databaseURL === config_1.config.databaseURL);
|
|
34
|
-
if (neurosityApp) {
|
|
35
|
-
return neurosityApp;
|
|
36
|
-
}
|
|
37
|
-
if (deviceId) {
|
|
38
|
-
const neurosityAppName = deviceId;
|
|
39
|
-
const neurosityApp = moduleApps.find((app) => app.name === neurosityAppName);
|
|
40
|
-
return neurosityApp
|
|
41
|
-
? neurosityApp
|
|
42
|
-
: app_1.default.initializeApp(config_1.config, neurosityAppName);
|
|
43
|
-
}
|
|
44
|
-
return app_1.default.initializeApp(config_1.config);
|
|
45
|
-
}
|
|
46
|
-
connectEmulators(options) {
|
|
47
|
-
const { emulatorHost, emulatorAuthPort, emulatorDatabasePort, emulatorFunctionsPort, emulatorFirestorePort, emulatorOptions } = options;
|
|
48
|
-
this.app.auth().useEmulator(`http://${emulatorHost}:${emulatorAuthPort}`);
|
|
49
|
-
this.app
|
|
50
|
-
.database()
|
|
51
|
-
.useEmulator(emulatorHost, emulatorDatabasePort, emulatorOptions);
|
|
52
|
-
this.app.functions().useEmulator(emulatorHost, emulatorFunctionsPort);
|
|
53
|
-
this.app
|
|
54
|
-
.firestore()
|
|
55
|
-
.useEmulator(emulatorHost, emulatorFirestorePort, emulatorOptions);
|
|
56
|
-
}
|
|
57
|
-
goOnline() {
|
|
58
|
-
this.app.database().goOnline();
|
|
59
|
-
}
|
|
60
|
-
goOffline() {
|
|
61
|
-
this.app.database().goOffline();
|
|
62
|
-
}
|
|
63
|
-
disconnect() {
|
|
64
|
-
if (this.standalone) {
|
|
65
|
-
return this.app.delete();
|
|
66
|
-
}
|
|
67
|
-
return Promise.resolve();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.FirebaseApp = FirebaseApp;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import firebase from "firebase/app";
|
|
2
|
-
import { FirebaseApp } from "./FirebaseApp";
|
|
3
|
-
import { SDKDependencies } from "../../types/options";
|
|
4
|
-
declare type FirebaseDeviceOptions = {
|
|
5
|
-
deviceId: string;
|
|
6
|
-
firebaseApp: FirebaseApp;
|
|
7
|
-
dependencies: SDKDependencies;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* @hidden
|
|
11
|
-
*/
|
|
12
|
-
export declare class FirebaseDevice {
|
|
13
|
-
static serverType: string;
|
|
14
|
-
protected app: firebase.app.App;
|
|
15
|
-
protected deviceStore: any;
|
|
16
|
-
deviceId: string;
|
|
17
|
-
constructor({ deviceId, firebaseApp, dependencies }: FirebaseDeviceOptions);
|
|
18
|
-
get timestamp(): any;
|
|
19
|
-
dispatchAction(action: any): Promise<any>;
|
|
20
|
-
getInfo(): Promise<any>;
|
|
21
|
-
onNamespace(namespace: string, callback: Function): Function;
|
|
22
|
-
onceNamespace(namespace: string): Promise<any>;
|
|
23
|
-
offNamespace(namespace: string, listener: Function): void;
|
|
24
|
-
getTimesync(): Promise<number>;
|
|
25
|
-
/**
|
|
26
|
-
* Pushes metric for each subscriptions in path:
|
|
27
|
-
* /devices/:deviceId/metrics/:metricName
|
|
28
|
-
*/
|
|
29
|
-
nextMetric(metricName: string, metricValue: {
|
|
30
|
-
[label: string]: any;
|
|
31
|
-
}): void;
|
|
32
|
-
/**
|
|
33
|
-
* Listens for metrics in path:
|
|
34
|
-
* /devices/:deviceId/metrics/:metricName
|
|
35
|
-
*/
|
|
36
|
-
onMetric(subscription: any, callback: any): Function;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a new and unique subscription in path:
|
|
39
|
-
* /devices/:deviceId/subscriptions/:subscriptionId
|
|
40
|
-
* E.g. /devices/device1/subscriptions/subscription3
|
|
41
|
-
*
|
|
42
|
-
* @param subscription
|
|
43
|
-
* @returns subscriptionId
|
|
44
|
-
*/
|
|
45
|
-
subscribeToMetric(subscription: any): any;
|
|
46
|
-
/**
|
|
47
|
-
* Removes subscription in path:
|
|
48
|
-
* /devices/:deviceId/subscriptions/:subscriptionId
|
|
49
|
-
*
|
|
50
|
-
* @param subscription
|
|
51
|
-
*/
|
|
52
|
-
unsubscribeFromMetric(subscription: any): void;
|
|
53
|
-
/**
|
|
54
|
-
* Removes metric listener
|
|
55
|
-
* /devices/:deviceId/metric
|
|
56
|
-
* or
|
|
57
|
-
* /devices/:deviceId/metric/label
|
|
58
|
-
*
|
|
59
|
-
* @param subscription
|
|
60
|
-
* @param listener
|
|
61
|
-
*/
|
|
62
|
-
removeMetricListener(subscription: any, listener: Function): void;
|
|
63
|
-
changeSettings(settings: any): Promise<void>;
|
|
64
|
-
getSkill(bundleId: any): Promise<any>;
|
|
65
|
-
createBluetoothToken(): Promise<string>;
|
|
66
|
-
disconnect(): void;
|
|
67
|
-
}
|
|
68
|
-
export {};
|