@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,386 @@
|
|
|
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.ReactNativeTransport = 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 rxjs_1 = require("rxjs");
|
|
17
|
+
const rxjs_2 = require("rxjs");
|
|
18
|
+
const operators_1 = require("rxjs/operators");
|
|
19
|
+
const operators_2 = require("rxjs/operators");
|
|
20
|
+
const operators_3 = require("rxjs/operators");
|
|
21
|
+
const create6DigitPin_1 = require("../utils/create6DigitPin");
|
|
22
|
+
const stitch_1 = require("../utils/stitch");
|
|
23
|
+
const encoding_1 = require("../utils/encoding");
|
|
24
|
+
const types_1 = require("../types");
|
|
25
|
+
const constants_1 = require("../constants");
|
|
26
|
+
const constants_2 = require("../constants");
|
|
27
|
+
const constants_3 = require("../constants");
|
|
28
|
+
const constants_4 = require("../constants");
|
|
29
|
+
const osHasBluetoothSupport_1 = require("../utils/osHasBluetoothSupport");
|
|
30
|
+
class ReactNativeTransport {
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.type = types_1.TRANSPORT_TYPE.REACT_NATIVE;
|
|
33
|
+
this.characteristicsByName = {};
|
|
34
|
+
this.connection$ = new rxjs_1.BehaviorSubject(types_1.BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
35
|
+
this.pendingActions$ = new rxjs_1.BehaviorSubject([]);
|
|
36
|
+
this.logs$ = new rxjs_1.ReplaySubject(10);
|
|
37
|
+
this.connectionStream$ = this.connection$
|
|
38
|
+
.asObservable()
|
|
39
|
+
.pipe((0, operators_1.filter)((connection) => !!connection), (0, operators_2.distinctUntilChanged)(), (0, operators_2.shareReplay)(1));
|
|
40
|
+
const { BleManager, bleManagerEmitter, platform } = options;
|
|
41
|
+
if (!BleManager) {
|
|
42
|
+
const errorMessage = "React Native option: BleManager not provided.";
|
|
43
|
+
this.addLog(errorMessage);
|
|
44
|
+
throw new Error(errorMessage);
|
|
45
|
+
}
|
|
46
|
+
if (!bleManagerEmitter) {
|
|
47
|
+
const errorMessage = "React Native option: bleManagerEmitter not provided.";
|
|
48
|
+
this.addLog(errorMessage);
|
|
49
|
+
throw new Error(errorMessage);
|
|
50
|
+
}
|
|
51
|
+
if (!platform) {
|
|
52
|
+
const errorMessage = "React Native option: platform not provided.";
|
|
53
|
+
this.addLog(errorMessage);
|
|
54
|
+
throw new Error(errorMessage);
|
|
55
|
+
}
|
|
56
|
+
this.BleManager = BleManager;
|
|
57
|
+
this.bleManagerEmitter = bleManagerEmitter;
|
|
58
|
+
this.platform = platform;
|
|
59
|
+
// We create a single listener per event type to
|
|
60
|
+
// avoid missing events when multiple listeners are attached.
|
|
61
|
+
this.bleEvents = {
|
|
62
|
+
stopScan$: this._fromEvent("BleManagerStopScan"),
|
|
63
|
+
discoverPeripheral$: this._fromEvent("BleManagerDiscoverPeripheral"),
|
|
64
|
+
connectPeripheral$: this._fromEvent("BleManagerConnectPeripheral"),
|
|
65
|
+
disconnectPeripheral$: this._fromEvent("BleManagerDisconnectPeripheral"),
|
|
66
|
+
didUpdateValueForCharacteristic$: this._fromEvent("BleManagerDidUpdateValueForCharacteristic")
|
|
67
|
+
};
|
|
68
|
+
this.onDisconnected$ = this.bleEvents.disconnectPeripheral$.pipe((0, operators_3.share)());
|
|
69
|
+
// Initializes the module. This can only be called once.
|
|
70
|
+
this.BleManager.start({ showAlert: false })
|
|
71
|
+
.then(() => {
|
|
72
|
+
this.addLog(`BleManger started`);
|
|
73
|
+
})
|
|
74
|
+
.catch((error) => {
|
|
75
|
+
var _a;
|
|
76
|
+
this.addLog(`BleManger failed to start. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
77
|
+
});
|
|
78
|
+
this.connection$.asObservable().subscribe((connection) => {
|
|
79
|
+
this.addLog(`connection status is ${connection}`);
|
|
80
|
+
});
|
|
81
|
+
this.onDisconnected$.subscribe(() => {
|
|
82
|
+
this.connection$.next(types_1.BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
addLog(log) {
|
|
86
|
+
this.logs$.next(log);
|
|
87
|
+
}
|
|
88
|
+
isConnected() {
|
|
89
|
+
const connection = this.connection$.getValue();
|
|
90
|
+
return connection === types_1.BLUETOOTH_CONNECTION.CONNECTED;
|
|
91
|
+
}
|
|
92
|
+
_autoConnect(selectedDevice$) {
|
|
93
|
+
const selectedDeviceAfterDisconnect$ = this.onDisconnected$.pipe((0, operators_1.switchMap)(() => selectedDevice$));
|
|
94
|
+
return (0, rxjs_1.merge)(selectedDevice$, selectedDeviceAfterDisconnect$).pipe((0, operators_1.switchMap)((selectedDevice) => !(0, osHasBluetoothSupport_1.osHasBluetoothSupport)(selectedDevice)
|
|
95
|
+
? rxjs_2.NEVER
|
|
96
|
+
: this.scan().pipe((0, operators_1.switchMap)((peripherals) => {
|
|
97
|
+
const peripheralMatch = peripherals.find((peripheral) => peripheral.name === (selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceNickname));
|
|
98
|
+
return peripheralMatch ? (0, rxjs_1.of)(peripheralMatch) : rxjs_2.NEVER;
|
|
99
|
+
}), (0, operators_3.distinct)((peripheral) => peripheral.id), (0, operators_3.take)(1))), (0, operators_1.switchMap)((peripheral) => __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return yield this.connect(peripheral);
|
|
101
|
+
})));
|
|
102
|
+
}
|
|
103
|
+
connection() {
|
|
104
|
+
return this.connectionStream$;
|
|
105
|
+
}
|
|
106
|
+
_fromEvent(eventName) {
|
|
107
|
+
return (0, rxjs_2.fromEventPattern)((addHandler) => {
|
|
108
|
+
this.bleManagerEmitter.addListener(eventName, addHandler);
|
|
109
|
+
}, () => {
|
|
110
|
+
this.bleManagerEmitter.removeAllListeners(eventName);
|
|
111
|
+
}).pipe(
|
|
112
|
+
// @important: we need to share the subscription
|
|
113
|
+
// to avoid missing events
|
|
114
|
+
(0, operators_3.share)());
|
|
115
|
+
}
|
|
116
|
+
scan(options) {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
const RESCAN_INTERVAL = 10000; // 10 seconds
|
|
119
|
+
const seconds = (_a = options === null || options === void 0 ? void 0 : options.seconds) !== null && _a !== void 0 ? _a : RESCAN_INTERVAL / 1000;
|
|
120
|
+
const once = (_b = options === null || options === void 0 ? void 0 : options.once) !== null && _b !== void 0 ? _b : false;
|
|
121
|
+
const serviceUUIDs = [ipk_1.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING];
|
|
122
|
+
const allowDuplicates = true;
|
|
123
|
+
const scanOptions = {};
|
|
124
|
+
const scanOnce$ = new rxjs_2.Observable((subscriber) => {
|
|
125
|
+
var _a;
|
|
126
|
+
try {
|
|
127
|
+
this.BleManager.scan(serviceUUIDs, seconds, allowDuplicates, scanOptions).then(() => {
|
|
128
|
+
this.addLog(`BleManger scanning ${once ? "once" : "indefintely"}`);
|
|
129
|
+
subscriber.next();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
this.addLog(`BleManger scanning ${once ? "once" : "indefintely"} failed. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
134
|
+
subscriber.error(error);
|
|
135
|
+
}
|
|
136
|
+
return () => {
|
|
137
|
+
this.BleManager.stopScan();
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
const scan$ = once
|
|
141
|
+
? scanOnce$
|
|
142
|
+
: (0, rxjs_1.timer)(0, RESCAN_INTERVAL).pipe((0, operators_1.switchMap)(() => scanOnce$));
|
|
143
|
+
const peripherals$ = scan$.pipe((0, operators_1.tap)(() => {
|
|
144
|
+
this.connection$.next(types_1.BLUETOOTH_CONNECTION.SCANNING);
|
|
145
|
+
}), (0, operators_1.takeUntil)(this.onDisconnected$), (0, operators_1.switchMap)(() => this.bleEvents.discoverPeripheral$),
|
|
146
|
+
// Filter out devices that are not Neurosity devices
|
|
147
|
+
(0, operators_1.filter)((peripheral) => {
|
|
148
|
+
var _a, _b, _c;
|
|
149
|
+
const peripheralName = (_c = (_b = (_a = peripheral === null || peripheral === void 0 ? void 0 : peripheral.advertising) === null || _a === void 0 ? void 0 : _a.localName) !== null && _b !== void 0 ? _b : peripheral.name) !== null && _c !== void 0 ? _c : "";
|
|
150
|
+
if (!peripheralName) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
const startsWithPrefix = ipk_3.BLUETOOTH_DEVICE_NAME_PREFIXES.findIndex((prefix) => peripheralName.startsWith(prefix)) !== -1;
|
|
154
|
+
return startsWithPrefix;
|
|
155
|
+
}), (0, operators_3.scan)((acc, peripheral) => {
|
|
156
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
157
|
+
// normalized peripheral name for backwards compatibility
|
|
158
|
+
// Neurosity OS v15 doesn't have peripheral.name as deviceNickname
|
|
159
|
+
// it only has peripheral.advertising.localName as deviceNickname
|
|
160
|
+
// and OS v16 has both as deviceNickname
|
|
161
|
+
const peripheralName = (_c = (_b = (_a = peripheral === null || peripheral === void 0 ? void 0 : peripheral.advertising) === null || _a === void 0 ? void 0 : _a.localName) !== null && _b !== void 0 ? _b : peripheral.name) !== null && _c !== void 0 ? _c : "";
|
|
162
|
+
const manufactureDataString = (_h = (_g = (0, encoding_1.decode)(this.type, (_f = (_e = (_d = peripheral === null || peripheral === void 0 ? void 0 : peripheral.advertising) === null || _d === void 0 ? void 0 : _d.manufacturerData) === null || _e === void 0 ? void 0 : _e.bytes) !== null && _f !== void 0 ? _f : [])) === null || _g === void 0 ? void 0 : _g.slice) === null || _h === void 0 ? void 0 : _h.call(_g, 2); // First 2 bytes are reserved for the Neurosity company code
|
|
163
|
+
return Object.assign(Object.assign({}, acc), { [peripheral.id]: Object.assign(Object.assign({}, peripheral), { name: peripheralName, manufactureDataString }) });
|
|
164
|
+
}, {}), (0, operators_2.distinctUntilChanged)((a, b) => JSON.stringify(a) === JSON.stringify(b)), (0, operators_1.map)((peripheralMap) => Object.values(peripheralMap)), (0, operators_3.share)());
|
|
165
|
+
return peripherals$;
|
|
166
|
+
}
|
|
167
|
+
connect(peripheral) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
try {
|
|
171
|
+
if (!peripheral) {
|
|
172
|
+
this.addLog("Peripheral not found");
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.connection$.next(types_1.BLUETOOTH_CONNECTION.CONNECTING);
|
|
176
|
+
yield this.BleManager.connect(peripheral.id);
|
|
177
|
+
this.addLog(`Getting service...`);
|
|
178
|
+
const peripheralInfo = yield this.BleManager.retrieveServices(peripheral.id, [
|
|
179
|
+
ipk_1.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING
|
|
180
|
+
]);
|
|
181
|
+
if (!peripheralInfo) {
|
|
182
|
+
this.addLog("Could not retreive services");
|
|
183
|
+
reject(`Could not retreive services`);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
this.addLog(`Got service ${ipk_1.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING}, getting characteristics...`);
|
|
187
|
+
this.device = peripheral;
|
|
188
|
+
this.characteristicsByName = Object.fromEntries(peripheralInfo.characteristics.map((characteristic) => [
|
|
189
|
+
constants_2.CHARACTERISTIC_UUIDS_TO_NAMES[characteristic.characteristic.toLowerCase() // react native uses uppercase
|
|
190
|
+
],
|
|
191
|
+
{
|
|
192
|
+
characteristicUUID: characteristic.characteristic,
|
|
193
|
+
serviceUUID: characteristic.service,
|
|
194
|
+
peripheralId: peripheral.id
|
|
195
|
+
}
|
|
196
|
+
]));
|
|
197
|
+
this.addLog(`Got characteristics.`);
|
|
198
|
+
if (this.platform === "android") {
|
|
199
|
+
this.addLog(`Setting Android MTU to ${constants_3.ANDROID_MAX_MTU}`);
|
|
200
|
+
yield this.BleManager.requestMTU(peripheral.id, constants_3.ANDROID_MAX_MTU);
|
|
201
|
+
}
|
|
202
|
+
this.addLog(`Successfully connected to peripheral ${peripheral.id}`);
|
|
203
|
+
this.connection$.next(types_1.BLUETOOTH_CONNECTION.CONNECTED);
|
|
204
|
+
resolve();
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
reject(error);
|
|
208
|
+
}
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
disconnect() {
|
|
213
|
+
var _a;
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
try {
|
|
216
|
+
if (this.isConnected() && ((_a = this === null || this === void 0 ? void 0 : this.device) === null || _a === void 0 ? void 0 : _a.id)) {
|
|
217
|
+
yield this.BleManager.disconnect(this.device.id);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
return Promise.reject(error);
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
getCharacteristicByName(characteristicName) {
|
|
226
|
+
var _a;
|
|
227
|
+
if (!(characteristicName in this.characteristicsByName)) {
|
|
228
|
+
throw new Error(`Characteristic by name ${characteristicName} is not found`);
|
|
229
|
+
}
|
|
230
|
+
return (_a = this.characteristicsByName) === null || _a === void 0 ? void 0 : _a[characteristicName];
|
|
231
|
+
}
|
|
232
|
+
subscribeToCharacteristic({ characteristicName, manageNotifications = true }) {
|
|
233
|
+
const getData = ({ peripheralId, serviceUUID, characteristicUUID }) => (0, rxjs_1.defer)(() => __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
var _a;
|
|
235
|
+
if (manageNotifications) {
|
|
236
|
+
try {
|
|
237
|
+
yield this.BleManager.startNotification(peripheralId, serviceUUID, characteristicUUID);
|
|
238
|
+
this.addLog(`Started notifications for ${characteristicName} characteristic`);
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
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}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
})).pipe((0, operators_1.switchMap)(() => this.bleEvents.didUpdateValueForCharacteristic$), (0, operators_2.finalize)(() => __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
var _b;
|
|
246
|
+
if (manageNotifications) {
|
|
247
|
+
try {
|
|
248
|
+
yield this.BleManager.stopNotification(peripheralId, serviceUUID, characteristicUUID);
|
|
249
|
+
this.addLog(`Stopped notifications for ${characteristicName} characteristic`);
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
this.addLog(`Attemped to stop notifications for ${characteristicName} characteristic: ${(_b = error === null || error === void 0 ? void 0 : error.message) !== null && _b !== void 0 ? _b : error}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
})), (0, operators_1.filter)(({ characteristic }) => characteristic === characteristicUUID), (0, operators_1.map)(({ value }) => (0, encoding_1.decode)(this.type, value)), (0, stitch_1.stitchChunks)({ delimiter: ipk_2.BLUETOOTH_CHUNK_DELIMITER }), (0, operators_1.map)((payload) => {
|
|
256
|
+
var _a;
|
|
257
|
+
try {
|
|
258
|
+
return JSON.parse(payload);
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
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}`);
|
|
262
|
+
return payload;
|
|
263
|
+
}
|
|
264
|
+
}));
|
|
265
|
+
return this.connection$.pipe((0, operators_1.switchMap)((connection) => connection === types_1.BLUETOOTH_CONNECTION.CONNECTED
|
|
266
|
+
? getData(this.getCharacteristicByName(characteristicName))
|
|
267
|
+
: rxjs_2.NEVER));
|
|
268
|
+
}
|
|
269
|
+
readCharacteristic(characteristicName, parse = false) {
|
|
270
|
+
var _a;
|
|
271
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
272
|
+
this.addLog(`Reading characteristic: ${characteristicName}`);
|
|
273
|
+
const { peripheralId, serviceUUID, characteristicUUID } = this.getCharacteristicByName(characteristicName);
|
|
274
|
+
if (!characteristicUUID) {
|
|
275
|
+
return Promise.reject(`Did not find characteristic matching ${characteristicName}`);
|
|
276
|
+
}
|
|
277
|
+
try {
|
|
278
|
+
const value = yield this.BleManager.read(peripheralId, serviceUUID, characteristicUUID);
|
|
279
|
+
const decodedValue = (0, encoding_1.decode)(this.type, value);
|
|
280
|
+
const data = parse ? JSON.parse(decodedValue) : decodedValue;
|
|
281
|
+
this.addLog(`Received read data from ${characteristicName} characteristic: \n${data}`);
|
|
282
|
+
return data;
|
|
283
|
+
}
|
|
284
|
+
catch (error) {
|
|
285
|
+
return Promise.reject(`readCharacteristic ${characteristicName} error. ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
writeCharacteristic(characteristicName, data) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
this.addLog(`Writing characteristic: ${characteristicName}`);
|
|
292
|
+
const { peripheralId, serviceUUID, characteristicUUID } = this.getCharacteristicByName(characteristicName);
|
|
293
|
+
if (!characteristicUUID) {
|
|
294
|
+
return Promise.reject(`Did not find characteristic matching ${characteristicName}`);
|
|
295
|
+
}
|
|
296
|
+
const encoded = (0, encoding_1.encode)(this.type, data);
|
|
297
|
+
yield this.BleManager.write(peripheralId, serviceUUID, characteristicUUID, encoded, constants_4.REACT_NATIVE_MAX_BYTE_SIZE);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
_addPendingAction(actionId) {
|
|
301
|
+
const actions = this.pendingActions$.getValue();
|
|
302
|
+
this.pendingActions$.next([...actions, actionId]);
|
|
303
|
+
}
|
|
304
|
+
_removePendingAction(actionId) {
|
|
305
|
+
const actions = this.pendingActions$.getValue();
|
|
306
|
+
this.pendingActions$.next(actions.filter((id) => id !== actionId));
|
|
307
|
+
}
|
|
308
|
+
_autoToggleActionNotifications(selectedDevice$) {
|
|
309
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
+
let started = false;
|
|
311
|
+
const sideEffects$ = this.connection$.asObservable().pipe((0, operators_1.switchMap)((connection) => connection === types_1.BLUETOOTH_CONNECTION.CONNECTED
|
|
312
|
+
? this.pendingActions$
|
|
313
|
+
: rxjs_2.NEVER), (0, operators_1.tap)((pendingActions) => __awaiter(this, void 0, void 0, function* () {
|
|
314
|
+
var _a, _b;
|
|
315
|
+
const { peripheralId, serviceUUID, characteristicUUID } = this.getCharacteristicByName("actions");
|
|
316
|
+
const hasPendingActions = !!pendingActions.length;
|
|
317
|
+
if (hasPendingActions && !started) {
|
|
318
|
+
started = true;
|
|
319
|
+
try {
|
|
320
|
+
yield this.BleManager.startNotification(peripheralId, serviceUUID, characteristicUUID);
|
|
321
|
+
this.addLog(`Started notifications for [actions] characteristic`);
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
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}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (!hasPendingActions && started) {
|
|
328
|
+
started = false;
|
|
329
|
+
try {
|
|
330
|
+
yield this.BleManager.stopNotification(peripheralId, serviceUUID, characteristicUUID);
|
|
331
|
+
this.addLog(`Stopped notifications for actions characteristic`);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
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}`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
})));
|
|
338
|
+
selectedDevice$
|
|
339
|
+
.pipe((0, operators_1.switchMap)((selectedDevice) => !(0, osHasBluetoothSupport_1.osHasBluetoothSupport)(selectedDevice) ? rxjs_2.EMPTY : sideEffects$))
|
|
340
|
+
.subscribe();
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
dispatchAction({ characteristicName, action }) {
|
|
344
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
345
|
+
const { responseRequired = false, responseTimeout = constants_1.DEFAULT_ACTION_RESPONSE_TIMEOUT } = action;
|
|
346
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
347
|
+
const actionId = (0, create6DigitPin_1.create6DigitPin)(); // use to later identify and filter response
|
|
348
|
+
const payload = JSON.stringify(Object.assign({ actionId }, action)); // add the response id to the action
|
|
349
|
+
this.addLog(`Dispatched action with id ${actionId}`);
|
|
350
|
+
if (responseRequired && responseTimeout) {
|
|
351
|
+
this._addPendingAction(actionId);
|
|
352
|
+
const timeout = (0, rxjs_1.timer)(responseTimeout).subscribe(() => {
|
|
353
|
+
this._removePendingAction(actionId);
|
|
354
|
+
reject(`Action with id ${actionId} timed out after ${responseTimeout}ms`);
|
|
355
|
+
});
|
|
356
|
+
// listen for a response before writing
|
|
357
|
+
this.subscribeToCharacteristic({
|
|
358
|
+
characteristicName,
|
|
359
|
+
manageNotifications: false
|
|
360
|
+
})
|
|
361
|
+
.pipe((0, operators_1.filter)((response) => (response === null || response === void 0 ? void 0 : response.actionId) === actionId), (0, operators_3.take)(1))
|
|
362
|
+
.subscribe((response) => {
|
|
363
|
+
timeout.unsubscribe();
|
|
364
|
+
this._removePendingAction(actionId);
|
|
365
|
+
resolve(response);
|
|
366
|
+
});
|
|
367
|
+
// register action by writing
|
|
368
|
+
this.writeCharacteristic(characteristicName, payload).catch((error) => {
|
|
369
|
+
this._removePendingAction(actionId);
|
|
370
|
+
reject(error.message);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
this.writeCharacteristic(characteristicName, payload)
|
|
375
|
+
.then(() => {
|
|
376
|
+
resolve(null);
|
|
377
|
+
})
|
|
378
|
+
.catch((error) => {
|
|
379
|
+
reject(error.message);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}));
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
exports.ReactNativeTransport = ReactNativeTransport;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export declare class BleManager {
|
|
2
|
+
start(options?: StartOptions): Promise<void>;
|
|
3
|
+
scan(serviceUUIDs: string[], seconds: number, allowDuplicates?: boolean, options?: ScanOptions): Promise<void>;
|
|
4
|
+
stopScan(): Promise<void>;
|
|
5
|
+
connect(peripheralID: string): Promise<void>;
|
|
6
|
+
disconnect(peripheralID: string, force?: boolean): Promise<void>;
|
|
7
|
+
checkState(): void;
|
|
8
|
+
startNotification(peripheralID: string, serviceUUID: string, characteristicUUID: string): Promise<void>;
|
|
9
|
+
startNotificationUseBuffer(peripheralID: string, serviceUUID: string, characteristicUUID: string, buffer: number): Promise<void>;
|
|
10
|
+
stopNotification(peripheralID: string, serviceUUID: string, characteristicUUID: string): Promise<void>;
|
|
11
|
+
read(peripheralID: string, serviceUUID: string, characteristicUUID: string): Promise<any>;
|
|
12
|
+
write(peripheralID: string, serviceUUID: string, characteristicUUID: string, data: any, maxByteSize?: number): Promise<void>;
|
|
13
|
+
writeWithoutResponse(peripheralID: string, serviceUUID: string, characteristicUUID: string, data: any, maxByteSize?: number, queueSleepTime?: number): Promise<void>;
|
|
14
|
+
readRSSI(peripheralID: string): Promise<void>;
|
|
15
|
+
getConnectedPeripherals(serviceUUIDs: string[]): Promise<Peripheral[]>;
|
|
16
|
+
getDiscoveredPeripherals(): Promise<Peripheral[]>;
|
|
17
|
+
isPeripheralConnected(peripheralID: string, serviceUUIDs: string[]): Promise<boolean>;
|
|
18
|
+
requestConnectionPriority(peripheralID: string, connectionPriority: ConnectionPriority): Promise<void>;
|
|
19
|
+
enableBluetooth(): Promise<void>;
|
|
20
|
+
refreshCache(peripheralID: string): Promise<void>;
|
|
21
|
+
requestMTU(peripheralID: string, mtu: number): Promise<void>;
|
|
22
|
+
createBond(peripheralID: string, peripheralPin?: string): Promise<void>;
|
|
23
|
+
removeBond(peripheralID: string): Promise<void>;
|
|
24
|
+
getBondedPeripherals(): Promise<Peripheral[]>;
|
|
25
|
+
removePeripheral(peripheralID: string): Promise<void>;
|
|
26
|
+
retrieveServices(peripheralID: string, serviceUUIDs?: string[]): Promise<PeripheralInfo>;
|
|
27
|
+
}
|
|
28
|
+
export interface Peripheral {
|
|
29
|
+
id: string;
|
|
30
|
+
rssi: number;
|
|
31
|
+
name?: string;
|
|
32
|
+
advertising: AdvertisingData;
|
|
33
|
+
}
|
|
34
|
+
export interface AdvertisingData {
|
|
35
|
+
isConnectable?: boolean;
|
|
36
|
+
localName?: string;
|
|
37
|
+
manufacturerData?: any;
|
|
38
|
+
serviceUUIDs?: string[];
|
|
39
|
+
txPowerLevel?: number;
|
|
40
|
+
}
|
|
41
|
+
export interface StartOptions {
|
|
42
|
+
showAlert?: boolean;
|
|
43
|
+
restoreIdentifierKey?: string;
|
|
44
|
+
queueIdentifierKey?: string;
|
|
45
|
+
forceLegacy?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface ScanOptions {
|
|
48
|
+
numberOfMatches?: number;
|
|
49
|
+
matchMode?: number;
|
|
50
|
+
scanMode?: number;
|
|
51
|
+
reportDelay?: number;
|
|
52
|
+
}
|
|
53
|
+
export declare enum ConnectionPriority {
|
|
54
|
+
balanced = 0,
|
|
55
|
+
high = 1,
|
|
56
|
+
low = 2
|
|
57
|
+
}
|
|
58
|
+
export interface PeripheralInfo {
|
|
59
|
+
characteristics: Characteristic[];
|
|
60
|
+
}
|
|
61
|
+
export interface Characteristic {
|
|
62
|
+
characteristic: string;
|
|
63
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Taken from react-native-ble-manager project
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ConnectionPriority = void 0;
|
|
5
|
+
// [Android only API 21+]
|
|
6
|
+
var ConnectionPriority;
|
|
7
|
+
(function (ConnectionPriority) {
|
|
8
|
+
ConnectionPriority[ConnectionPriority["balanced"] = 0] = "balanced";
|
|
9
|
+
ConnectionPriority[ConnectionPriority["high"] = 1] = "high";
|
|
10
|
+
ConnectionPriority[ConnectionPriority["low"] = 2] = "low";
|
|
11
|
+
})(ConnectionPriority = exports.ConnectionPriority || (exports.ConnectionPriority = {}));
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EmitterSubscription represents a subscription with listener and context data.
|
|
3
|
+
*/
|
|
4
|
+
interface EmitterSubscription extends EventSubscription {
|
|
5
|
+
emitter: EventEmitter;
|
|
6
|
+
listener: () => any;
|
|
7
|
+
context: any;
|
|
8
|
+
/**
|
|
9
|
+
* @param emitter - The event emitter that registered this
|
|
10
|
+
* subscription
|
|
11
|
+
* @param subscriber - The subscriber that controls
|
|
12
|
+
* this subscription
|
|
13
|
+
* @param listener - Function to invoke when the specified event is
|
|
14
|
+
* emitted
|
|
15
|
+
* @param context - Optional context object to use when invoking the
|
|
16
|
+
* listener
|
|
17
|
+
*/
|
|
18
|
+
new (emitter: EventEmitter, subscriber: EventSubscriptionVendor, listener: () => any, context: any): EmitterSubscription;
|
|
19
|
+
/**
|
|
20
|
+
* Removes this subscription from the emitter that registered it.
|
|
21
|
+
* Note: we're overriding the `remove()` method of EventSubscription here
|
|
22
|
+
* but deliberately not calling `super.remove()` as the responsibility
|
|
23
|
+
* for removing the subscription lies with the EventEmitter.
|
|
24
|
+
*/
|
|
25
|
+
remove(): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* EventSubscription represents a subscription to a particular event. It can
|
|
29
|
+
* remove its own subscription.
|
|
30
|
+
*/
|
|
31
|
+
interface EventSubscription {
|
|
32
|
+
eventType: string;
|
|
33
|
+
key: number;
|
|
34
|
+
subscriber: EventSubscriptionVendor;
|
|
35
|
+
/**
|
|
36
|
+
* @param subscriber the subscriber that controls
|
|
37
|
+
* this subscription.
|
|
38
|
+
*/
|
|
39
|
+
new (subscriber: EventSubscriptionVendor): EventSubscription;
|
|
40
|
+
/**
|
|
41
|
+
* Removes this subscription from the subscriber that controls it.
|
|
42
|
+
*/
|
|
43
|
+
remove(): void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* EventSubscriptionVendor stores a set of EventSubscriptions that are
|
|
47
|
+
* subscribed to a particular event type.
|
|
48
|
+
*/
|
|
49
|
+
declare class EventSubscriptionVendor {
|
|
50
|
+
constructor();
|
|
51
|
+
/**
|
|
52
|
+
* Adds a subscription keyed by an event type.
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
addSubscription(eventType: string, subscription: EventSubscription): EventSubscription;
|
|
56
|
+
/**
|
|
57
|
+
* Removes a bulk set of the subscriptions.
|
|
58
|
+
*
|
|
59
|
+
* @param eventType - Optional name of the event type whose
|
|
60
|
+
* registered supscriptions to remove, if null remove all subscriptions.
|
|
61
|
+
*/
|
|
62
|
+
removeAllSubscriptions(eventType?: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Removes a specific subscription. Instead of calling this function, call
|
|
65
|
+
* `subscription.remove()` directly.
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
removeSubscription(subscription: any): void;
|
|
69
|
+
/**
|
|
70
|
+
* Returns the array of subscriptions that are currently registered for the
|
|
71
|
+
* given event type.
|
|
72
|
+
*
|
|
73
|
+
* Note: This array can be potentially sparse as subscriptions are deleted
|
|
74
|
+
* from it when they are removed.
|
|
75
|
+
*
|
|
76
|
+
*/
|
|
77
|
+
getSubscriptionsForType(eventType: string): EventSubscription[];
|
|
78
|
+
}
|
|
79
|
+
declare class EventEmitter {
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param subscriber - Optional subscriber instance
|
|
83
|
+
* to use. If omitted, a new subscriber will be created for the emitter.
|
|
84
|
+
*/
|
|
85
|
+
constructor(subscriber?: EventSubscriptionVendor | null);
|
|
86
|
+
/**
|
|
87
|
+
* Adds a listener to be invoked when events of the specified type are
|
|
88
|
+
* emitted. An optional calling context may be provided. The data arguments
|
|
89
|
+
* emitted will be passed to the listener function.
|
|
90
|
+
*
|
|
91
|
+
* @param eventType - Name of the event to listen to
|
|
92
|
+
* @param listener - Function to invoke when the specified event is
|
|
93
|
+
* emitted
|
|
94
|
+
* @param context - Optional context object to use when invoking the
|
|
95
|
+
* listener
|
|
96
|
+
*/
|
|
97
|
+
addListener(eventType: string, listener: (...args: any[]) => any, context?: any): EmitterSubscription;
|
|
98
|
+
/**
|
|
99
|
+
* Removes all of the registered listeners, including those registered as
|
|
100
|
+
* listener maps.
|
|
101
|
+
*
|
|
102
|
+
* @param eventType - Optional name of the event whose registered
|
|
103
|
+
* listeners to remove
|
|
104
|
+
*/
|
|
105
|
+
removeAllListeners(eventType?: string): void;
|
|
106
|
+
/**
|
|
107
|
+
* Returns the number of listeners that are currently registered for the given
|
|
108
|
+
* event.
|
|
109
|
+
*
|
|
110
|
+
* @param eventType - Name of the event to query
|
|
111
|
+
*/
|
|
112
|
+
listenerCount(eventType: string): number;
|
|
113
|
+
/**
|
|
114
|
+
* Emits an event of the given type with the given data. All handlers of that
|
|
115
|
+
* particular type will be notified.
|
|
116
|
+
*
|
|
117
|
+
* @param eventType - Name of the event to emit
|
|
118
|
+
* @param Arbitrary arguments to be passed to each registered listener
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* emitter.addListener('someEvent', function(message) {
|
|
122
|
+
* console.log(message);
|
|
123
|
+
* });
|
|
124
|
+
*
|
|
125
|
+
* emitter.emit('someEvent', 'abc'); // logs 'abc'
|
|
126
|
+
*/
|
|
127
|
+
emit(eventType: string, ...params: any[]): void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The React Native implementation of the IOS RCTEventEmitter which is required when creating
|
|
131
|
+
* a module that communicates with IOS
|
|
132
|
+
*/
|
|
133
|
+
declare type NativeModule = {
|
|
134
|
+
/**
|
|
135
|
+
* Add the provided eventType as an active listener
|
|
136
|
+
* @param eventType name of the event for which we are registering listener
|
|
137
|
+
*/
|
|
138
|
+
addListener: (eventType: string) => void;
|
|
139
|
+
/**
|
|
140
|
+
* Remove a specified number of events. There are no eventTypes in this case, as
|
|
141
|
+
* the native side doesn't remove the name, but only manages a counter of total
|
|
142
|
+
* listeners
|
|
143
|
+
* @param count number of listeners to remove (of any type)
|
|
144
|
+
*/
|
|
145
|
+
removeListeners: (count: number) => void;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Abstract base class for implementing event-emitting modules. This implements
|
|
149
|
+
* a subset of the standard EventEmitter node module API.
|
|
150
|
+
*/
|
|
151
|
+
export declare class NativeEventEmitter extends EventEmitter {
|
|
152
|
+
/**
|
|
153
|
+
* @param nativeModule the NativeModule implementation. This is required on IOS and will throw
|
|
154
|
+
* an invariant error if undefined.
|
|
155
|
+
*/
|
|
156
|
+
constructor(nativeModule?: NativeModule);
|
|
157
|
+
/**
|
|
158
|
+
* Add the specified listener, this call passes through to the NativeModule
|
|
159
|
+
* addListener
|
|
160
|
+
*
|
|
161
|
+
* @param eventType name of the event for which we are registering listener
|
|
162
|
+
* @param listener the listener function
|
|
163
|
+
* @param context context of the listener
|
|
164
|
+
*/
|
|
165
|
+
addListener(eventType: string, listener: (event: any) => void, context?: Object): EmitterSubscription;
|
|
166
|
+
/**
|
|
167
|
+
* @param eventType name of the event whose registered listeners to remove
|
|
168
|
+
*/
|
|
169
|
+
removeAllListeners(eventType: string): void;
|
|
170
|
+
/**
|
|
171
|
+
* Removes a subscription created by the addListener, the EventSubscription#remove()
|
|
172
|
+
* function actually calls through to this.
|
|
173
|
+
*/
|
|
174
|
+
removeSubscription(subscription: EmitterSubscription): void;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* @see https://reactnative.dev/docs/platform-specific-code#content
|
|
178
|
+
*/
|
|
179
|
+
export declare type PlatformOSType = "ios" | "android" | "macos" | "windows" | "web" | "native";
|
|
180
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// This is a subset of React Native's types
|
|
3
|
+
// EmitterSubscription
|
|
4
|
+
// EventSubscription
|
|
5
|
+
// EventSubscriptionVendor
|
|
6
|
+
// EventEmitter
|
|
7
|
+
// NativeModule
|
|
8
|
+
// NativeEventEmitter
|
|
9
|
+
// PlatformOSType
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|