@neurosity/sdk 6.0.0-next.11
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/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/browser/neurosity.iife.js +48736 -0
- package/dist/browser/neurosity.js +672 -0
- package/dist/browser/neurosity.js.map +1 -0
- package/dist/cjs/Notion.d.ts +619 -0
- package/dist/cjs/Notion.js +1291 -0
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +59 -0
- package/dist/cjs/api/bluetooth/BluetoothClient.js +287 -0
- package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +32 -0
- package/dist/cjs/api/bluetooth/BluetoothTransport.js +2 -0
- package/dist/cjs/api/bluetooth/constants.d.ts +4 -0
- package/dist/cjs/api/bluetooth/constants.js +9 -0
- package/dist/cjs/api/bluetooth/index.d.ts +4 -0
- package/dist/cjs/api/bluetooth/index.js +20 -0
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +65 -0
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +386 -0
- package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.d.ts +63 -0
- package/dist/cjs/api/bluetooth/react-native/types/BleManagerTypes.js +11 -0
- package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +180 -0
- package/dist/cjs/api/bluetooth/react-native/types/ReactNativeTypes.js +10 -0
- package/dist/cjs/api/bluetooth/types/index.d.ts +31 -0
- package/dist/cjs/api/bluetooth/types/index.js +22 -0
- package/dist/cjs/api/bluetooth/utils/create6DigitPin.d.ts +1 -0
- package/dist/cjs/api/bluetooth/utils/create6DigitPin.js +8 -0
- package/dist/cjs/api/bluetooth/utils/csvBufferToEpoch.d.ts +11 -0
- package/dist/cjs/api/bluetooth/utils/csvBufferToEpoch.js +36 -0
- package/dist/cjs/api/bluetooth/utils/encoding.d.ts +3 -0
- package/dist/cjs/api/bluetooth/utils/encoding.js +22 -0
- package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -0
- package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.js +23 -0
- package/dist/cjs/api/bluetooth/utils/stitch.d.ts +5 -0
- package/dist/cjs/api/bluetooth/utils/stitch.js +22 -0
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +47 -0
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +412 -0
- package/dist/cjs/api/bluetooth/web/isMaybeWebWorkerContext.d.ts +1 -0
- package/dist/cjs/api/bluetooth/web/isMaybeWebWorkerContext.js +8 -0
- package/dist/cjs/api/bluetooth/web/isWebBluetoothSupported.d.ts +1 -0
- package/dist/cjs/api/bluetooth/web/isWebBluetoothSupported.js +11 -0
- package/dist/cjs/api/firebase/FirebaseApp.d.ts +20 -0
- package/dist/cjs/api/firebase/FirebaseApp.js +70 -0
- package/dist/cjs/api/firebase/FirebaseDevice.d.ts +68 -0
- package/dist/cjs/api/firebase/FirebaseDevice.js +146 -0
- package/dist/cjs/api/firebase/FirebaseUser.d.ts +53 -0
- package/dist/cjs/api/firebase/FirebaseUser.js +434 -0
- package/dist/cjs/api/firebase/config.d.ts +8 -0
- package/dist/cjs/api/firebase/config.js +11 -0
- package/dist/cjs/api/firebase/deviceStore.d.ts +26 -0
- package/dist/cjs/api/firebase/deviceStore.js +191 -0
- package/dist/cjs/api/firebase/index.d.ts +3 -0
- package/dist/cjs/api/firebase/index.js +19 -0
- package/dist/cjs/api/https/config.d.ts +1 -0
- package/dist/cjs/api/https/config.js +4 -0
- package/dist/cjs/api/https/createOAuthURL.d.ts +3 -0
- package/dist/cjs/api/https/createOAuthURL.js +18 -0
- package/dist/cjs/api/https/getOAuthToken.d.ts +3 -0
- package/dist/cjs/api/https/getOAuthToken.js +34 -0
- package/dist/cjs/api/https/utils.d.ts +2 -0
- package/dist/cjs/api/https/utils.js +13 -0
- package/dist/cjs/api/index.d.ts +108 -0
- package/dist/cjs/api/index.js +306 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +19 -0
- package/dist/cjs/skills/NotionOnDevice.d.ts +7 -0
- package/dist/cjs/skills/NotionOnDevice.js +25 -0
- package/dist/cjs/skills/createSkill.d.ts +7 -0
- package/dist/cjs/skills/createSkill.js +40 -0
- package/dist/cjs/skills/index.d.ts +2 -0
- package/dist/cjs/skills/index.js +18 -0
- package/dist/cjs/subscriptions/SubscriptionManager.d.ts +11 -0
- package/dist/cjs/subscriptions/SubscriptionManager.js +27 -0
- package/dist/cjs/timesync/Timesync.d.ts +20 -0
- package/dist/cjs/timesync/Timesync.js +78 -0
- package/dist/cjs/timesync/index.d.ts +1 -0
- package/dist/cjs/timesync/index.js +17 -0
- package/dist/cjs/types/accelerometer.d.ts +10 -0
- package/dist/cjs/types/accelerometer.js +2 -0
- package/dist/cjs/types/actions.d.ts +16 -0
- package/dist/cjs/types/actions.js +2 -0
- package/dist/cjs/types/awareness.d.ts +1 -0
- package/dist/cjs/types/awareness.js +2 -0
- package/dist/cjs/types/brainwaves.d.ts +26 -0
- package/dist/cjs/types/brainwaves.js +2 -0
- package/dist/cjs/types/calm.d.ts +6 -0
- package/dist/cjs/types/calm.js +2 -0
- package/dist/cjs/types/client.d.ts +22 -0
- package/dist/cjs/types/client.js +2 -0
- package/dist/cjs/types/credentials.d.ts +12 -0
- package/dist/cjs/types/credentials.js +2 -0
- package/dist/cjs/types/deviceInfo.d.ts +18 -0
- package/dist/cjs/types/deviceInfo.js +2 -0
- package/dist/cjs/types/epoch.d.ts +12 -0
- package/dist/cjs/types/epoch.js +2 -0
- package/dist/cjs/types/experiment.d.ts +9 -0
- package/dist/cjs/types/experiment.js +2 -0
- package/dist/cjs/types/focus.d.ts +6 -0
- package/dist/cjs/types/focus.js +2 -0
- package/dist/cjs/types/hapticEffects.d.ts +125 -0
- package/dist/cjs/types/hapticEffects.js +2 -0
- package/dist/cjs/types/kinesis.d.ts +6 -0
- package/dist/cjs/types/kinesis.js +2 -0
- package/dist/cjs/types/marker.d.ts +7 -0
- package/dist/cjs/types/marker.js +2 -0
- package/dist/cjs/types/metrics.d.ts +21 -0
- package/dist/cjs/types/metrics.js +2 -0
- package/dist/cjs/types/oauth.d.ts +20 -0
- package/dist/cjs/types/oauth.js +2 -0
- package/dist/cjs/types/options.d.ts +51 -0
- package/dist/cjs/types/options.js +2 -0
- package/dist/cjs/types/sample.d.ts +15 -0
- package/dist/cjs/types/sample.js +2 -0
- package/dist/cjs/types/settings.d.ts +13 -0
- package/dist/cjs/types/settings.js +2 -0
- package/dist/cjs/types/signalQuality.d.ts +13 -0
- package/dist/cjs/types/signalQuality.js +2 -0
- package/dist/cjs/types/skill.d.ts +68 -0
- package/dist/cjs/types/skill.js +2 -0
- package/dist/cjs/types/status.d.ts +26 -0
- package/dist/cjs/types/status.js +22 -0
- package/dist/cjs/types/streaming.d.ts +15 -0
- package/dist/cjs/types/streaming.js +20 -0
- package/dist/cjs/types/subscriptions.d.ts +23 -0
- package/dist/cjs/types/subscriptions.js +2 -0
- package/dist/cjs/types/training.d.ts +19 -0
- package/dist/cjs/types/training.js +2 -0
- package/dist/cjs/types/user.d.ts +12 -0
- package/dist/cjs/types/user.js +2 -0
- package/dist/cjs/utils/errors.d.ts +5 -0
- package/dist/cjs/utils/errors.js +17 -0
- package/dist/cjs/utils/filterInternalKeys.d.ts +3 -0
- package/dist/cjs/utils/filterInternalKeys.js +21 -0
- package/dist/cjs/utils/hapticEffects.d.ts +123 -0
- package/dist/cjs/utils/hapticEffects.js +130 -0
- package/dist/cjs/utils/heartbeat.d.ts +4 -0
- package/dist/cjs/utils/heartbeat.js +34 -0
- package/dist/cjs/utils/is-node.d.ts +1 -0
- package/dist/cjs/utils/is-node.js +9 -0
- package/dist/cjs/utils/metrics.d.ts +1 -0
- package/dist/cjs/utils/metrics.js +56 -0
- package/dist/cjs/utils/oauth.d.ts +9 -0
- package/dist/cjs/utils/oauth.js +92 -0
- package/dist/cjs/utils/pick.d.ts +1 -0
- package/dist/cjs/utils/pick.js +5 -0
- package/dist/cjs/utils/pipes.d.ts +46 -0
- package/dist/cjs/utils/pipes.js +71 -0
- package/dist/cjs/utils/platform.d.ts +30 -0
- package/dist/cjs/utils/platform.js +47 -0
- package/dist/cjs/utils/subscription.d.ts +6 -0
- package/dist/cjs/utils/subscription.js +55 -0
- package/dist/cjs/utils/transferDevice.d.ts +9 -0
- package/dist/cjs/utils/transferDevice.js +2 -0
- package/dist/cjs/utils/whileOnline.d.ts +8 -0
- package/dist/cjs/utils/whileOnline.js +15 -0
- package/dist/electron/index.js +92 -0
- package/dist/electron/index.js.map +1 -0
- package/dist/esm/Notion.d.ts +619 -0
- package/dist/esm/Notion.js +1260 -0
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +59 -0
- package/dist/esm/api/bluetooth/BluetoothClient.js +283 -0
- package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +32 -0
- package/dist/esm/api/bluetooth/BluetoothTransport.js +1 -0
- package/dist/esm/api/bluetooth/constants.d.ts +4 -0
- package/dist/esm/api/bluetooth/constants.js +6 -0
- package/dist/esm/api/bluetooth/index.d.ts +4 -0
- package/dist/esm/api/bluetooth/index.js +4 -0
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +65 -0
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +382 -0
- package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.d.ts +63 -0
- package/dist/esm/api/bluetooth/react-native/types/BleManagerTypes.js +8 -0
- package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.d.ts +180 -0
- package/dist/esm/api/bluetooth/react-native/types/ReactNativeTypes.js +9 -0
- package/dist/esm/api/bluetooth/types/index.d.ts +31 -0
- package/dist/esm/api/bluetooth/types/index.js +19 -0
- package/dist/esm/api/bluetooth/utils/create6DigitPin.d.ts +1 -0
- package/dist/esm/api/bluetooth/utils/create6DigitPin.js +4 -0
- package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.d.ts +11 -0
- package/dist/esm/api/bluetooth/utils/csvBufferToEpoch.js +31 -0
- package/dist/esm/api/bluetooth/utils/encoding.d.ts +3 -0
- package/dist/esm/api/bluetooth/utils/encoding.js +17 -0
- package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -0
- package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.js +16 -0
- package/dist/esm/api/bluetooth/utils/stitch.d.ts +5 -0
- package/dist/esm/api/bluetooth/utils/stitch.js +18 -0
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +47 -0
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +408 -0
- package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.d.ts +1 -0
- package/dist/esm/api/bluetooth/web/isMaybeWebWorkerContext.js +4 -0
- package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.d.ts +1 -0
- package/dist/esm/api/bluetooth/web/isWebBluetoothSupported.js +7 -0
- package/dist/esm/api/firebase/FirebaseApp.d.ts +20 -0
- package/dist/esm/api/firebase/FirebaseApp.js +63 -0
- package/dist/esm/api/firebase/FirebaseDevice.d.ts +68 -0
- package/dist/esm/api/firebase/FirebaseDevice.js +139 -0
- package/dist/esm/api/firebase/FirebaseUser.d.ts +53 -0
- package/dist/esm/api/firebase/FirebaseUser.js +426 -0
- package/dist/esm/api/firebase/config.d.ts +8 -0
- package/dist/esm/api/firebase/config.js +8 -0
- package/dist/esm/api/firebase/deviceStore.d.ts +26 -0
- package/dist/esm/api/firebase/deviceStore.js +184 -0
- package/dist/esm/api/firebase/index.d.ts +3 -0
- package/dist/esm/api/firebase/index.js +3 -0
- package/dist/esm/api/https/config.d.ts +1 -0
- package/dist/esm/api/https/config.js +1 -0
- package/dist/esm/api/https/createOAuthURL.d.ts +3 -0
- package/dist/esm/api/https/createOAuthURL.js +11 -0
- package/dist/esm/api/https/getOAuthToken.d.ts +3 -0
- package/dist/esm/api/https/getOAuthToken.js +27 -0
- package/dist/esm/api/https/utils.d.ts +2 -0
- package/dist/esm/api/https/utils.js +9 -0
- package/dist/esm/api/index.d.ts +108 -0
- package/dist/esm/api/index.js +299 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/neurosity.mjs +48722 -0
- package/dist/esm/skills/NotionOnDevice.d.ts +7 -0
- package/dist/esm/skills/NotionOnDevice.js +21 -0
- package/dist/esm/skills/createSkill.d.ts +7 -0
- package/dist/esm/skills/createSkill.js +36 -0
- package/dist/esm/skills/index.d.ts +2 -0
- package/dist/esm/skills/index.js +2 -0
- package/dist/esm/subscriptions/SubscriptionManager.d.ts +11 -0
- package/dist/esm/subscriptions/SubscriptionManager.js +23 -0
- package/dist/esm/timesync/Timesync.d.ts +20 -0
- package/dist/esm/timesync/Timesync.js +71 -0
- package/dist/esm/timesync/index.d.ts +1 -0
- package/dist/esm/timesync/index.js +1 -0
- package/dist/esm/types/accelerometer.d.ts +10 -0
- package/dist/esm/types/accelerometer.js +1 -0
- package/dist/esm/types/actions.d.ts +16 -0
- package/dist/esm/types/actions.js +1 -0
- package/dist/esm/types/awareness.d.ts +1 -0
- package/dist/esm/types/awareness.js +1 -0
- package/dist/esm/types/brainwaves.d.ts +26 -0
- package/dist/esm/types/brainwaves.js +1 -0
- package/dist/esm/types/calm.d.ts +6 -0
- package/dist/esm/types/calm.js +1 -0
- package/dist/esm/types/client.d.ts +22 -0
- package/dist/esm/types/client.js +1 -0
- package/dist/esm/types/credentials.d.ts +12 -0
- package/dist/esm/types/credentials.js +1 -0
- package/dist/esm/types/deviceInfo.d.ts +18 -0
- package/dist/esm/types/deviceInfo.js +1 -0
- package/dist/esm/types/epoch.d.ts +12 -0
- package/dist/esm/types/epoch.js +1 -0
- package/dist/esm/types/experiment.d.ts +9 -0
- package/dist/esm/types/experiment.js +1 -0
- package/dist/esm/types/focus.d.ts +6 -0
- package/dist/esm/types/focus.js +1 -0
- package/dist/esm/types/hapticEffects.d.ts +125 -0
- package/dist/esm/types/hapticEffects.js +1 -0
- package/dist/esm/types/kinesis.d.ts +6 -0
- package/dist/esm/types/kinesis.js +1 -0
- package/dist/esm/types/marker.d.ts +7 -0
- package/dist/esm/types/marker.js +1 -0
- package/dist/esm/types/metrics.d.ts +21 -0
- package/dist/esm/types/metrics.js +1 -0
- package/dist/esm/types/oauth.d.ts +20 -0
- package/dist/esm/types/oauth.js +1 -0
- package/dist/esm/types/options.d.ts +51 -0
- package/dist/esm/types/options.js +1 -0
- package/dist/esm/types/sample.d.ts +15 -0
- package/dist/esm/types/sample.js +1 -0
- package/dist/esm/types/settings.d.ts +13 -0
- package/dist/esm/types/settings.js +1 -0
- package/dist/esm/types/signalQuality.d.ts +13 -0
- package/dist/esm/types/signalQuality.js +1 -0
- package/dist/esm/types/skill.d.ts +68 -0
- package/dist/esm/types/skill.js +1 -0
- package/dist/esm/types/status.d.ts +26 -0
- package/dist/esm/types/status.js +19 -0
- package/dist/esm/types/streaming.d.ts +15 -0
- package/dist/esm/types/streaming.js +17 -0
- package/dist/esm/types/subscriptions.d.ts +23 -0
- package/dist/esm/types/subscriptions.js +1 -0
- package/dist/esm/types/training.d.ts +19 -0
- package/dist/esm/types/training.js +1 -0
- package/dist/esm/types/user.d.ts +12 -0
- package/dist/esm/types/user.js +1 -0
- package/dist/esm/utils/errors.d.ts +5 -0
- package/dist/esm/utils/errors.js +11 -0
- package/dist/esm/utils/filterInternalKeys.d.ts +3 -0
- package/dist/esm/utils/filterInternalKeys.js +17 -0
- package/dist/esm/utils/hapticEffects.d.ts +123 -0
- package/dist/esm/utils/hapticEffects.js +125 -0
- package/dist/esm/utils/heartbeat.d.ts +4 -0
- package/dist/esm/utils/heartbeat.js +29 -0
- package/dist/esm/utils/is-node.d.ts +1 -0
- package/dist/esm/utils/is-node.js +5 -0
- package/dist/esm/utils/metrics.d.ts +1 -0
- package/dist/esm/utils/metrics.js +52 -0
- package/dist/esm/utils/oauth.d.ts +9 -0
- package/dist/esm/utils/oauth.js +64 -0
- package/dist/esm/utils/pick.d.ts +1 -0
- package/dist/esm/utils/pick.js +1 -0
- package/dist/esm/utils/pipes.d.ts +46 -0
- package/dist/esm/utils/pipes.js +65 -0
- package/dist/esm/utils/platform.d.ts +30 -0
- package/dist/esm/utils/platform.js +41 -0
- package/dist/esm/utils/subscription.d.ts +6 -0
- package/dist/esm/utils/subscription.js +24 -0
- package/dist/esm/utils/transferDevice.d.ts +9 -0
- package/dist/esm/utils/transferDevice.js +1 -0
- package/dist/esm/utils/whileOnline.d.ts +8 -0
- package/dist/esm/utils/whileOnline.js +11 -0
- package/dist/examples/auth.html +32 -0
- package/dist/examples/cloud.html +17 -0
- package/dist/examples/index.html +1 -0
- package/dist/examples/neurosity.iife.js +48736 -0
- package/dist/examples/neurosity.js +672 -0
- package/dist/examples/neurosity.mjs +48722 -0
- package/dist/examples/training.html +49 -0
- package/package.json +78 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hidden
|
|
3
|
+
*/
|
|
4
|
+
export var BLUETOOTH_CONNECTION;
|
|
5
|
+
(function (BLUETOOTH_CONNECTION) {
|
|
6
|
+
BLUETOOTH_CONNECTION["SCANNING"] = "scanning";
|
|
7
|
+
BLUETOOTH_CONNECTION["CONNECTED"] = "connected";
|
|
8
|
+
BLUETOOTH_CONNECTION["CONNECTING"] = "connecting";
|
|
9
|
+
BLUETOOTH_CONNECTION["DISCONNECTING"] = "disconnecting";
|
|
10
|
+
BLUETOOTH_CONNECTION["DISCONNECTED"] = "disconnected";
|
|
11
|
+
})(BLUETOOTH_CONNECTION || (BLUETOOTH_CONNECTION = {}));
|
|
12
|
+
/**
|
|
13
|
+
* @hidden
|
|
14
|
+
*/
|
|
15
|
+
export var TRANSPORT_TYPE;
|
|
16
|
+
(function (TRANSPORT_TYPE) {
|
|
17
|
+
TRANSPORT_TYPE["WEB"] = "web";
|
|
18
|
+
TRANSPORT_TYPE["REACT_NATIVE"] = "reactNative";
|
|
19
|
+
})(TRANSPORT_TYPE || (TRANSPORT_TYPE = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function create6DigitPin(): number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Observable, UnaryFunction } from "rxjs";
|
|
2
|
+
import { Epoch } from "../../../types/epoch";
|
|
3
|
+
import { DeviceInfo } from "../../../types/deviceInfo";
|
|
4
|
+
/**
|
|
5
|
+
* @hidden
|
|
6
|
+
*/
|
|
7
|
+
export declare function csvBufferToEpoch(deviceInfo: DeviceInfo): UnaryFunction<Observable<Epoch>, any>;
|
|
8
|
+
/**
|
|
9
|
+
* @hidden
|
|
10
|
+
*/
|
|
11
|
+
export declare function csvBufferToSamples(): UnaryFunction<any, any>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { pipe, from } from "rxjs";
|
|
2
|
+
import { mergeMap, map } from "rxjs/operators";
|
|
3
|
+
import { epoch, addInfo } from "../../../utils/pipes";
|
|
4
|
+
const EPOCH_BUFFER_SIZE = 16;
|
|
5
|
+
const SAMPLING_RATE_FALLBACK = 256; // Crown's sampling rate
|
|
6
|
+
/**
|
|
7
|
+
* @hidden
|
|
8
|
+
*/
|
|
9
|
+
export function csvBufferToEpoch(deviceInfo) {
|
|
10
|
+
var _a;
|
|
11
|
+
if (!(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.samplingRate)) {
|
|
12
|
+
console.warn(`Didn't receive a sampling rate, defaulting to ${SAMPLING_RATE_FALLBACK}`);
|
|
13
|
+
}
|
|
14
|
+
return pipe(csvBufferToSamples(), epoch({
|
|
15
|
+
duration: EPOCH_BUFFER_SIZE,
|
|
16
|
+
interval: EPOCH_BUFFER_SIZE,
|
|
17
|
+
samplingRate: (_a = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.samplingRate) !== null && _a !== void 0 ? _a : SAMPLING_RATE_FALLBACK
|
|
18
|
+
}), addInfo({
|
|
19
|
+
channelNames: deviceInfo.channelNames,
|
|
20
|
+
samplingRate: deviceInfo.samplingRate
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @hidden
|
|
25
|
+
*/
|
|
26
|
+
export function csvBufferToSamples() {
|
|
27
|
+
return pipe(mergeMap((samples) => from(samples)), map(([timestamp, marker, ...data]) => ({
|
|
28
|
+
timestamp,
|
|
29
|
+
data
|
|
30
|
+
})));
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TRANSPORT_TYPE } from "../types";
|
|
2
|
+
const encoder = new TextEncoder();
|
|
3
|
+
const decoder = new TextDecoder("utf-8");
|
|
4
|
+
export function encode(transportType, data) {
|
|
5
|
+
if (transportType === TRANSPORT_TYPE.REACT_NATIVE) {
|
|
6
|
+
// React Native expects a plain array of numbers and not a Uint8Array
|
|
7
|
+
return [...encoder.encode(data)];
|
|
8
|
+
}
|
|
9
|
+
return encoder.encode(data);
|
|
10
|
+
}
|
|
11
|
+
export function decode(transportType, data) {
|
|
12
|
+
if (transportType === TRANSPORT_TYPE.REACT_NATIVE) {
|
|
13
|
+
// React Native outpouts a plain array of numbers and not a Uint8Array
|
|
14
|
+
return decoder.decode(new Uint8Array(data));
|
|
15
|
+
}
|
|
16
|
+
return decoder.decode(data);
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import semverGte from "semver/functions/gte";
|
|
2
|
+
export function osHasBluetoothSupport(selectedDevice) {
|
|
3
|
+
if (!selectedDevice) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
// Only the Crown supports Bluetooth
|
|
7
|
+
const isCrown = Number(selectedDevice.modelVersion) >= 3;
|
|
8
|
+
if (!isCrown) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const isEmulator = !!(selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.emulator);
|
|
12
|
+
if (isEmulator) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return semverGte(selectedDevice.osVersion, "16.0.0");
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { pipe } from "rxjs";
|
|
2
|
+
import { map, scan, filter } from "rxjs/operators";
|
|
3
|
+
export function stitchChunks({ delimiter }) {
|
|
4
|
+
return pipe(scan(([remainder], currentBuffer) => {
|
|
5
|
+
const nextBuffer = remainder + currentBuffer;
|
|
6
|
+
if (!nextBuffer.includes(delimiter)) {
|
|
7
|
+
return [nextBuffer, ""];
|
|
8
|
+
}
|
|
9
|
+
if (nextBuffer.endsWith(delimiter)) {
|
|
10
|
+
return ["", nextBuffer];
|
|
11
|
+
}
|
|
12
|
+
const remainderStart = nextBuffer.lastIndexOf(delimiter);
|
|
13
|
+
const remainderIndex = remainderStart + delimiter.length;
|
|
14
|
+
const nextPacket = nextBuffer.slice(0, remainderIndex);
|
|
15
|
+
const nextRemainder = nextBuffer.slice(remainderIndex);
|
|
16
|
+
return [nextRemainder, nextPacket];
|
|
17
|
+
}, ["", ""]), map(([, nextPacket]) => nextPacket.slice(0, -delimiter.length)), filter((nextPacket) => !!nextPacket.length));
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="web-bluetooth" />
|
|
2
|
+
import { BehaviorSubject, ReplaySubject } from "rxjs";
|
|
3
|
+
import { Observable } from "rxjs";
|
|
4
|
+
import { BluetoothTransport } from "../BluetoothTransport";
|
|
5
|
+
import { ActionOptions, SubscribeOptions } from "../types";
|
|
6
|
+
import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
|
|
7
|
+
import { DeviceInfo } from "../../../types/deviceInfo";
|
|
8
|
+
export declare class WebBluetoothTransport implements BluetoothTransport {
|
|
9
|
+
type: TRANSPORT_TYPE;
|
|
10
|
+
device: BluetoothDevice;
|
|
11
|
+
server: BluetoothRemoteGATTServer;
|
|
12
|
+
service: BluetoothRemoteGATTService;
|
|
13
|
+
characteristicsByName: {
|
|
14
|
+
[name: string]: BluetoothRemoteGATTCharacteristic;
|
|
15
|
+
};
|
|
16
|
+
connection$: BehaviorSubject<BLUETOOTH_CONNECTION>;
|
|
17
|
+
pendingActions$: BehaviorSubject<any[]>;
|
|
18
|
+
logs$: ReplaySubject<string>;
|
|
19
|
+
onDisconnected$: Observable<void>;
|
|
20
|
+
connectionStream$: Observable<BLUETOOTH_CONNECTION>;
|
|
21
|
+
constructor();
|
|
22
|
+
_getPairedDevices(): Promise<BluetoothDevice[]>;
|
|
23
|
+
_autoConnect(selectedDevice$: Observable<DeviceInfo>): Observable<void>;
|
|
24
|
+
addLog(log: string): void;
|
|
25
|
+
isConnected(): boolean;
|
|
26
|
+
connection(): Observable<BLUETOOTH_CONNECTION>;
|
|
27
|
+
connect(deviceNickname?: string): Promise<void>;
|
|
28
|
+
requestDevice(deviceNickname?: string): Promise<BluetoothDevice>;
|
|
29
|
+
getServerServiceAndCharacteristics(device: BluetoothDevice): Promise<never>;
|
|
30
|
+
_onDisconnected(): Observable<any>;
|
|
31
|
+
disconnect(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* Bluetooth GATT attributes, services, characteristics, etc. are invalidated
|
|
35
|
+
* when a device disconnects. This means your code should always retrieve
|
|
36
|
+
* (through getPrimaryService(s), getCharacteristic(s), etc.) these attributes
|
|
37
|
+
* after reconnecting.
|
|
38
|
+
*/
|
|
39
|
+
getCharacteristicByName(characteristicName: string): Promise<BluetoothRemoteGATTCharacteristic>;
|
|
40
|
+
subscribeToCharacteristic({ characteristicName, manageNotifications }: SubscribeOptions): Observable<any>;
|
|
41
|
+
readCharacteristic(characteristicName: string, parse?: boolean): Promise<any>;
|
|
42
|
+
writeCharacteristic(characteristicName: string, data: string): Promise<void>;
|
|
43
|
+
_addPendingAction(actionId: number): void;
|
|
44
|
+
_removePendingAction(actionId: number): void;
|
|
45
|
+
_autoToggleActionNotifications(selectedDevice$: Observable<DeviceInfo>): Promise<void>;
|
|
46
|
+
dispatchAction({ characteristicName, action }: ActionOptions): Promise<any>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { BLUETOOTH_PRIMARY_SERVICE_UUID_HEX } from "@neurosity/ipk";
|
|
11
|
+
import { BLUETOOTH_CHUNK_DELIMITER } from "@neurosity/ipk";
|
|
12
|
+
import { BLUETOOTH_DEVICE_NAME_PREFIXES } from "@neurosity/ipk";
|
|
13
|
+
import { BLUETOOTH_COMPANY_IDENTIFIER_HEX } from "@neurosity/ipk";
|
|
14
|
+
import { BehaviorSubject, defer, merge, of, ReplaySubject, timer } from "rxjs";
|
|
15
|
+
import { fromEventPattern, Observable, EMPTY, NEVER } from "rxjs";
|
|
16
|
+
import { switchMap, map, filter, tap } from "rxjs/operators";
|
|
17
|
+
import { shareReplay, distinctUntilChanged } from "rxjs/operators";
|
|
18
|
+
import { take, share } from "rxjs/operators";
|
|
19
|
+
import { isWebBluetoothSupported } from "./isWebBluetoothSupported";
|
|
20
|
+
import { create6DigitPin } from "../utils/create6DigitPin";
|
|
21
|
+
import { stitchChunks } from "../utils/stitch";
|
|
22
|
+
import { encode, decode } from "../utils/encoding";
|
|
23
|
+
import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
|
|
24
|
+
import { DEFAULT_ACTION_RESPONSE_TIMEOUT } from "../constants";
|
|
25
|
+
import { CHARACTERISTIC_UUIDS_TO_NAMES } from "../constants";
|
|
26
|
+
import { osHasBluetoothSupport } from "../utils/osHasBluetoothSupport";
|
|
27
|
+
export class WebBluetoothTransport {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.type = TRANSPORT_TYPE.WEB;
|
|
30
|
+
this.characteristicsByName = {};
|
|
31
|
+
this.connection$ = new BehaviorSubject(BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
32
|
+
this.pendingActions$ = new BehaviorSubject([]);
|
|
33
|
+
this.logs$ = new ReplaySubject(10);
|
|
34
|
+
this.onDisconnected$ = this._onDisconnected().pipe(share());
|
|
35
|
+
this.connectionStream$ = this.connection$
|
|
36
|
+
.asObservable()
|
|
37
|
+
.pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
|
|
38
|
+
if (!isWebBluetoothSupported()) {
|
|
39
|
+
const errorMessage = "Web Bluetooth is not supported";
|
|
40
|
+
this.addLog(errorMessage);
|
|
41
|
+
throw new Error(errorMessage);
|
|
42
|
+
}
|
|
43
|
+
this.connection$.asObservable().subscribe((connection) => {
|
|
44
|
+
this.addLog(`connection status is ${connection}`);
|
|
45
|
+
});
|
|
46
|
+
this.onDisconnected$.subscribe(() => {
|
|
47
|
+
this.connection$.next(BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
_getPairedDevices() {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
return yield navigator.bluetooth.getDevices();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
_autoConnect(selectedDevice$) {
|
|
56
|
+
return merge(selectedDevice$, this.onDisconnected$.pipe(switchMap(() => selectedDevice$))).pipe(switchMap((selectedDevice) => osHasBluetoothSupport(selectedDevice) ? of(selectedDevice) : EMPTY), switchMap((selectedDevice) => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
var _a;
|
|
58
|
+
const { deviceNickname } = selectedDevice;
|
|
59
|
+
const [devicesError, devices] = yield this._getPairedDevices()
|
|
60
|
+
.then((devices) => [null, devices])
|
|
61
|
+
.catch((error) => [error, null]);
|
|
62
|
+
if (devicesError) {
|
|
63
|
+
throw new Error(`failed to get devices: ${(_a = devicesError === null || devicesError === void 0 ? void 0 : devicesError.message) !== null && _a !== void 0 ? _a : devicesError}`);
|
|
64
|
+
}
|
|
65
|
+
this.addLog(`Auto connect: found ${devices.length} devices ${devices
|
|
66
|
+
.map(({ name }) => name)
|
|
67
|
+
.join(", ")}`);
|
|
68
|
+
// @important - Using `findLast` instead of `find` because somehow the browser
|
|
69
|
+
// is finding multiple peripherals with the same name
|
|
70
|
+
const device = devices.findLast((device) => device.name === deviceNickname);
|
|
71
|
+
if (!device) {
|
|
72
|
+
throw new Error(`couldn't find selected device in the list of paired devices.`);
|
|
73
|
+
}
|
|
74
|
+
this.addLog(`Auto connect: ${deviceNickname} was detected and previously paired`);
|
|
75
|
+
return device;
|
|
76
|
+
})), tap(() => {
|
|
77
|
+
this.connection$.next(BLUETOOTH_CONNECTION.SCANNING);
|
|
78
|
+
}), switchMap((device) => onAdvertisementReceived(device)), switchMap((advertisement) => __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
this.addLog(`Advertisement received for ${advertisement.device.name}`);
|
|
80
|
+
return yield this.getServerServiceAndCharacteristics(advertisement.device);
|
|
81
|
+
})));
|
|
82
|
+
}
|
|
83
|
+
addLog(log) {
|
|
84
|
+
this.logs$.next(log);
|
|
85
|
+
}
|
|
86
|
+
isConnected() {
|
|
87
|
+
const connection = this.connection$.getValue();
|
|
88
|
+
return connection === BLUETOOTH_CONNECTION.CONNECTED;
|
|
89
|
+
}
|
|
90
|
+
connection() {
|
|
91
|
+
return this.connectionStream$;
|
|
92
|
+
}
|
|
93
|
+
connect(deviceNickname) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
try {
|
|
96
|
+
// requires user gesture
|
|
97
|
+
const device = yield this.requestDevice(deviceNickname);
|
|
98
|
+
yield this.getServerServiceAndCharacteristics(device);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return Promise.reject(error);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
requestDevice(deviceNickname) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
try {
|
|
108
|
+
this.addLog("Requesting Bluetooth Device...");
|
|
109
|
+
const prefixes = BLUETOOTH_DEVICE_NAME_PREFIXES.map((namePrefix) => ({
|
|
110
|
+
namePrefix
|
|
111
|
+
}));
|
|
112
|
+
// Ability to only show selectedDevice if provided
|
|
113
|
+
const filters = deviceNickname
|
|
114
|
+
? [
|
|
115
|
+
{
|
|
116
|
+
name: deviceNickname
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
: prefixes;
|
|
120
|
+
const device = yield window.navigator.bluetooth.requestDevice({
|
|
121
|
+
filters: [
|
|
122
|
+
...filters,
|
|
123
|
+
{
|
|
124
|
+
manufacturerData: [
|
|
125
|
+
{
|
|
126
|
+
companyIdentifier: BLUETOOTH_COMPANY_IDENTIFIER_HEX
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
optionalServices: [BLUETOOTH_PRIMARY_SERVICE_UUID_HEX]
|
|
132
|
+
});
|
|
133
|
+
return device;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return Promise.reject(error);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
getServerServiceAndCharacteristics(device) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
try {
|
|
143
|
+
this.device = device;
|
|
144
|
+
const isConnecting = this.connection$.getValue() === BLUETOOTH_CONNECTION.CONNECTING;
|
|
145
|
+
if (!isConnecting) {
|
|
146
|
+
this.connection$.next(BLUETOOTH_CONNECTION.CONNECTING);
|
|
147
|
+
}
|
|
148
|
+
this.server = yield device.gatt.connect();
|
|
149
|
+
this.addLog(`Getting service...`);
|
|
150
|
+
this.service = yield this.server.getPrimaryService(BLUETOOTH_PRIMARY_SERVICE_UUID_HEX);
|
|
151
|
+
this.addLog(`Got service ${this.service.uuid}, getting characteristics...`);
|
|
152
|
+
const characteristicsList = yield this.service.getCharacteristics();
|
|
153
|
+
this.addLog(`Got characteristics`);
|
|
154
|
+
this.characteristicsByName = Object.fromEntries(characteristicsList.map((characteristic) => [
|
|
155
|
+
CHARACTERISTIC_UUIDS_TO_NAMES[characteristic.uuid],
|
|
156
|
+
characteristic
|
|
157
|
+
]));
|
|
158
|
+
this.connection$.next(BLUETOOTH_CONNECTION.CONNECTED);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
return Promise.reject(error);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
_onDisconnected() {
|
|
166
|
+
return this.connection$
|
|
167
|
+
.asObservable()
|
|
168
|
+
.pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED
|
|
169
|
+
? fromDOMEvent(this.device, "gattserverdisconnected")
|
|
170
|
+
: NEVER));
|
|
171
|
+
}
|
|
172
|
+
disconnect() {
|
|
173
|
+
var _a, _b;
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
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;
|
|
176
|
+
if (isDeviceConnected) {
|
|
177
|
+
this.device.gatt.disconnect();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
*
|
|
183
|
+
* Bluetooth GATT attributes, services, characteristics, etc. are invalidated
|
|
184
|
+
* when a device disconnects. This means your code should always retrieve
|
|
185
|
+
* (through getPrimaryService(s), getCharacteristic(s), etc.) these attributes
|
|
186
|
+
* after reconnecting.
|
|
187
|
+
*/
|
|
188
|
+
getCharacteristicByName(characteristicName) {
|
|
189
|
+
var _a;
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
return (_a = this.characteristicsByName) === null || _a === void 0 ? void 0 : _a[characteristicName];
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
subscribeToCharacteristic({ characteristicName, manageNotifications = true }) {
|
|
195
|
+
const data$ = defer(() => this.getCharacteristicByName(characteristicName)).pipe(switchMap((characteristic) => __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
var _a;
|
|
197
|
+
if (this.isConnected() && manageNotifications) {
|
|
198
|
+
try {
|
|
199
|
+
yield characteristic.startNotifications();
|
|
200
|
+
this.addLog(`Started notifications for ${characteristicName} characteristic`);
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
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}`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return characteristic;
|
|
207
|
+
})), switchMap((characteristic) => {
|
|
208
|
+
return fromDOMEvent(characteristic, "characteristicvaluechanged", () => __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
var _a;
|
|
210
|
+
if (this.isConnected() && manageNotifications) {
|
|
211
|
+
try {
|
|
212
|
+
yield characteristic.stopNotifications();
|
|
213
|
+
this.addLog(`Stopped notifications for ${characteristicName} characteristic`);
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
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}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}));
|
|
220
|
+
}), map((event) => {
|
|
221
|
+
const buffer = event.target.value;
|
|
222
|
+
const decoded = decode(this.type, buffer);
|
|
223
|
+
this.addLog(`Received chunk with buffer size of ${buffer.byteLength} and decoded size ${decoded.length} for ${characteristicName} characteristic: \n${decoded}`);
|
|
224
|
+
return decoded;
|
|
225
|
+
}), stitchChunks({ delimiter: BLUETOOTH_CHUNK_DELIMITER }), map((payload) => {
|
|
226
|
+
var _a;
|
|
227
|
+
try {
|
|
228
|
+
return JSON.parse(payload);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
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}`);
|
|
232
|
+
return payload;
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
// when streaming at ultra-low latency, the logs will slow down rendering
|
|
236
|
+
// tap((data) => {
|
|
237
|
+
// this.addLog(
|
|
238
|
+
// `Received data for ${characteristicName} characteristic: \n${JSON.stringify(
|
|
239
|
+
// data,
|
|
240
|
+
// null,
|
|
241
|
+
// 2
|
|
242
|
+
// )}`
|
|
243
|
+
// );
|
|
244
|
+
// })
|
|
245
|
+
);
|
|
246
|
+
return this.connection$.pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED ? data$ : NEVER));
|
|
247
|
+
}
|
|
248
|
+
readCharacteristic(characteristicName, parse = false) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
try {
|
|
251
|
+
this.addLog(`Reading characteristic: ${characteristicName}`);
|
|
252
|
+
const characteristic = yield this.getCharacteristicByName(characteristicName);
|
|
253
|
+
if (!characteristic) {
|
|
254
|
+
this.addLog(`Did not fund ${characteristicName} characteristic`);
|
|
255
|
+
return Promise.reject(`Did not find characteristic by the name: ${characteristicName}`);
|
|
256
|
+
}
|
|
257
|
+
const value = yield characteristic.readValue();
|
|
258
|
+
const uint8Array = value;
|
|
259
|
+
const decodedValue = decode(this.type, uint8Array);
|
|
260
|
+
const data = parse ? JSON.parse(decodedValue) : decodedValue;
|
|
261
|
+
this.addLog(`Received read data from ${characteristicName} characteristic: \n${data}`);
|
|
262
|
+
return data;
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
return Promise.reject(`Error reading characteristic: ${error.message}`);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
writeCharacteristic(characteristicName, data) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
this.addLog(`Writing characteristic: ${characteristicName}`);
|
|
272
|
+
const characteristic = yield this.getCharacteristicByName(characteristicName);
|
|
273
|
+
if (!characteristic) {
|
|
274
|
+
this.addLog(`Did not fund ${characteristicName} characteristic`);
|
|
275
|
+
return Promise.reject(`Did not find characteristic by the name: ${characteristicName}`);
|
|
276
|
+
}
|
|
277
|
+
const encoded = encode(this.type, data);
|
|
278
|
+
yield characteristic.writeValueWithResponse(encoded);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
_addPendingAction(actionId) {
|
|
282
|
+
const actions = this.pendingActions$.getValue();
|
|
283
|
+
this.pendingActions$.next([...actions, actionId]);
|
|
284
|
+
}
|
|
285
|
+
_removePendingAction(actionId) {
|
|
286
|
+
const actions = this.pendingActions$.getValue();
|
|
287
|
+
this.pendingActions$.next(actions.filter((id) => id !== actionId));
|
|
288
|
+
}
|
|
289
|
+
_autoToggleActionNotifications(selectedDevice$) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
let actionsCharacteristic;
|
|
292
|
+
let started = false;
|
|
293
|
+
const sideEffects$ = this.connection$.asObservable().pipe(switchMap((connection) => connection === BLUETOOTH_CONNECTION.CONNECTED
|
|
294
|
+
? defer(() => this.getCharacteristicByName("actions")).pipe(switchMap((characteristic) => {
|
|
295
|
+
actionsCharacteristic = characteristic;
|
|
296
|
+
return this.pendingActions$;
|
|
297
|
+
}))
|
|
298
|
+
: NEVER), tap((pendingActions) => __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
var _a, _b;
|
|
300
|
+
const hasPendingActions = !!pendingActions.length;
|
|
301
|
+
if (hasPendingActions && !started) {
|
|
302
|
+
started = true;
|
|
303
|
+
try {
|
|
304
|
+
yield actionsCharacteristic.startNotifications();
|
|
305
|
+
this.addLog(`Started notifications for [actions] characteristic`);
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
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}`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (!hasPendingActions && started) {
|
|
312
|
+
started = false;
|
|
313
|
+
try {
|
|
314
|
+
yield actionsCharacteristic.stopNotifications();
|
|
315
|
+
this.addLog(`Stopped notifications for actions characteristic`);
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
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}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
})));
|
|
322
|
+
selectedDevice$
|
|
323
|
+
.pipe(switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice) ? EMPTY : sideEffects$))
|
|
324
|
+
.subscribe();
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
dispatchAction({ characteristicName, action }) {
|
|
328
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
+
const { responseRequired = false, responseTimeout = DEFAULT_ACTION_RESPONSE_TIMEOUT } = action;
|
|
330
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
const characteristic = yield this.getCharacteristicByName(characteristicName).catch(() => {
|
|
332
|
+
reject(`Did not find characteristic by the name: ${characteristicName}`);
|
|
333
|
+
});
|
|
334
|
+
if (!characteristic) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const actionId = create6DigitPin(); // use to later identify and filter response
|
|
338
|
+
const payload = JSON.stringify(Object.assign({ actionId }, action)); // add the response id to the action
|
|
339
|
+
this.addLog(`Dispatched action with id ${actionId}`);
|
|
340
|
+
if (responseRequired && responseTimeout) {
|
|
341
|
+
this._addPendingAction(actionId);
|
|
342
|
+
const timeout = timer(responseTimeout).subscribe(() => {
|
|
343
|
+
this._removePendingAction(actionId);
|
|
344
|
+
reject(`Action with id ${actionId} timed out after ${responseTimeout}ms`);
|
|
345
|
+
});
|
|
346
|
+
// listen for a response before writing
|
|
347
|
+
this.subscribeToCharacteristic({
|
|
348
|
+
characteristicName,
|
|
349
|
+
manageNotifications: false
|
|
350
|
+
})
|
|
351
|
+
.pipe(filter((response) => (response === null || response === void 0 ? void 0 : response.actionId) === actionId), take(1))
|
|
352
|
+
.subscribe((response) => {
|
|
353
|
+
timeout.unsubscribe();
|
|
354
|
+
this._removePendingAction(actionId);
|
|
355
|
+
resolve(response);
|
|
356
|
+
});
|
|
357
|
+
// register action by writing
|
|
358
|
+
this.writeCharacteristic(characteristicName, payload).catch((error) => {
|
|
359
|
+
this._removePendingAction(actionId);
|
|
360
|
+
reject(error.message);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
else {
|
|
364
|
+
this.writeCharacteristic(characteristicName, payload)
|
|
365
|
+
.then(() => {
|
|
366
|
+
resolve(null);
|
|
367
|
+
})
|
|
368
|
+
.catch((error) => {
|
|
369
|
+
reject(error.message);
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
}));
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function fromDOMEvent(target, eventName, beforeRemove) {
|
|
377
|
+
return fromEventPattern((addHandler) => {
|
|
378
|
+
target.addEventListener(eventName, addHandler);
|
|
379
|
+
}, (removeHandler) => __awaiter(this, void 0, void 0, function* () {
|
|
380
|
+
if (beforeRemove) {
|
|
381
|
+
yield beforeRemove();
|
|
382
|
+
}
|
|
383
|
+
target.removeEventListener(eventName, removeHandler);
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
function onAdvertisementReceived(device) {
|
|
387
|
+
return new Observable((subscriber) => {
|
|
388
|
+
const abortController = new AbortController();
|
|
389
|
+
const { signal } = abortController;
|
|
390
|
+
const listener = device.addEventListener("advertisementreceived", (advertisement) => {
|
|
391
|
+
abortController.abort();
|
|
392
|
+
subscriber.next(advertisement);
|
|
393
|
+
subscriber.complete();
|
|
394
|
+
}, {
|
|
395
|
+
once: true
|
|
396
|
+
});
|
|
397
|
+
try {
|
|
398
|
+
device.watchAdvertisements({ signal });
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
subscriber.error(error);
|
|
402
|
+
}
|
|
403
|
+
return () => {
|
|
404
|
+
abortController.abort();
|
|
405
|
+
device.removeEventListener("advertisementreceived", listener);
|
|
406
|
+
};
|
|
407
|
+
});
|
|
408
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isMaybeWebWorkerContext: () => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isWebBluetoothSupported(): boolean;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { isMaybeWebWorkerContext } from "./isMaybeWebWorkerContext";
|
|
2
|
+
export function isWebBluetoothSupported() {
|
|
3
|
+
var _a;
|
|
4
|
+
return (typeof window !== "undefined" &&
|
|
5
|
+
((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.bluetooth) &&
|
|
6
|
+
!isMaybeWebWorkerContext());
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
}
|