@neurosity/sdk 6.0.0 → 6.2.0
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/CHANGELOG.md +25 -0
- package/dist/browser/neurosity.iife.js +44 -113
- package/dist/browser/neurosity.js +8 -14
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/{Notion.d.ts → Neurosity.d.ts} +0 -0
- package/dist/cjs/{Notion.js → Neurosity.js} +0 -47
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +1 -0
- package/dist/cjs/api/bluetooth/BluetoothClient.js +3 -0
- package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +1 -0
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +5 -0
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +23 -3
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +8 -1
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +16 -2
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +1 -2
- package/dist/electron/index.js +8 -14
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/{Notion.d.ts → Neurosity.d.ts} +0 -0
- package/dist/esm/{Notion.js → Neurosity.js} +1 -48
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +1 -0
- package/dist/esm/api/bluetooth/BluetoothClient.js +3 -0
- package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +1 -0
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +5 -0
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +23 -3
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +8 -1
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +16 -2
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/neurosity.mjs +45 -112
- package/dist/examples/neurosity.iife.js +44 -113
- package/dist/examples/neurosity.js +8 -14
- package/dist/examples/neurosity.mjs +45 -112
- package/package.json +1 -1
- package/dist/cjs/skills/NotionOnDevice.d.ts +0 -7
- package/dist/cjs/skills/NotionOnDevice.js +0 -25
- package/dist/cjs/skills/createSkill.d.ts +0 -7
- package/dist/cjs/skills/createSkill.js +0 -40
- package/dist/cjs/skills/index.d.ts +0 -2
- package/dist/cjs/skills/index.js +0 -18
- package/dist/esm/skills/NotionOnDevice.d.ts +0 -7
- package/dist/esm/skills/NotionOnDevice.js +0 -21
- package/dist/esm/skills/createSkill.d.ts +0 -7
- package/dist/esm/skills/createSkill.js +0 -36
- package/dist/esm/skills/index.d.ts +0 -2
- package/dist/esm/skills/index.js +0 -2
|
File without changes
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { combineLatest,
|
|
10
|
+
import { combineLatest, of, throwError } from "rxjs";
|
|
11
11
|
import { ReplaySubject, firstValueFrom, EMPTY } from "rxjs";
|
|
12
12
|
import { distinctUntilChanged, map, switchMap } from "rxjs/operators";
|
|
13
13
|
import isEqual from "fast-deep-equal";
|
|
@@ -1142,53 +1142,6 @@ export class Neurosity {
|
|
|
1142
1142
|
removeOAuthAccess() {
|
|
1143
1143
|
return this.cloudClient.removeOAuthAccess();
|
|
1144
1144
|
}
|
|
1145
|
-
/**
|
|
1146
|
-
* @internal
|
|
1147
|
-
* Proof of Concept for Skills - Not user facing yet
|
|
1148
|
-
*
|
|
1149
|
-
* Accesses a skill by Bundle ID. Additionally, allows to observe
|
|
1150
|
-
* and push skill metrics
|
|
1151
|
-
*
|
|
1152
|
-
* @param bundleId Bundle ID of skill
|
|
1153
|
-
* @returns Skill instance
|
|
1154
|
-
*/
|
|
1155
|
-
skill(bundleId) {
|
|
1156
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
1157
|
-
if (!(yield this.cloudClient.didSelectDevice())) {
|
|
1158
|
-
return Promise.reject(errors.mustSelectDevice);
|
|
1159
|
-
}
|
|
1160
|
-
const skillData = yield this.cloudClient.skills.get(bundleId);
|
|
1161
|
-
if (skillData === null) {
|
|
1162
|
-
return Promise.reject(new Error(`${errors.prefix}Access denied for: ${bundleId}. Make sure the skill is installed.`));
|
|
1163
|
-
}
|
|
1164
|
-
return {
|
|
1165
|
-
metric: (label) => {
|
|
1166
|
-
const metricName = `skill~${skillData.id}~${label}`;
|
|
1167
|
-
const subscription = new Observable((observer) => {
|
|
1168
|
-
const subscription = this.cloudClient.metrics.subscribe({
|
|
1169
|
-
metric: metricName,
|
|
1170
|
-
labels: [label],
|
|
1171
|
-
atomic: true
|
|
1172
|
-
});
|
|
1173
|
-
const listener = this.cloudClient.metrics.on(subscription, (...data) => {
|
|
1174
|
-
observer.next(...data);
|
|
1175
|
-
});
|
|
1176
|
-
return () => {
|
|
1177
|
-
this.cloudClient.metrics.unsubscribe(subscription, listener);
|
|
1178
|
-
};
|
|
1179
|
-
}).pipe(map((metric) => metric[label]));
|
|
1180
|
-
Object.defineProperty(subscription, "next", {
|
|
1181
|
-
value: (metricValue) => {
|
|
1182
|
-
this.cloudClient.metrics.next(metricName, {
|
|
1183
|
-
[label]: metricValue
|
|
1184
|
-
});
|
|
1185
|
-
}
|
|
1186
|
-
});
|
|
1187
|
-
return subscription;
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
});
|
|
1191
|
-
}
|
|
1192
1145
|
/**
|
|
1193
1146
|
* <StreamingModes wifi={true} />
|
|
1194
1147
|
*
|
|
@@ -37,6 +37,7 @@ export declare class BluetoothClient {
|
|
|
37
37
|
_wifiConnections$: Observable<any>;
|
|
38
38
|
constructor(options: Options);
|
|
39
39
|
_autoAuthenticate(createBluetoothToken: CreateBluetoothToken): Observable<IsAuthenticatedResponse>;
|
|
40
|
+
enableAutoConnect(autoConnect: boolean): void;
|
|
40
41
|
_hasBluetoothSupport(): Promise<boolean>;
|
|
41
42
|
authenticate(token: string): Promise<IsAuthenticatedResponse>;
|
|
42
43
|
isAuthenticated(): Promise<IsAuthenticatedResponse>;
|
|
@@ -83,6 +83,9 @@ export class BluetoothClient {
|
|
|
83
83
|
}
|
|
84
84
|
})))));
|
|
85
85
|
}
|
|
86
|
+
enableAutoConnect(autoConnect) {
|
|
87
|
+
this.transport.enableAutoConnect(autoConnect);
|
|
88
|
+
}
|
|
86
89
|
_hasBluetoothSupport() {
|
|
87
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
91
|
const selectedDevice = yield firstValueFrom(this.selectedDevice$);
|
|
@@ -20,6 +20,7 @@ declare type Options = {
|
|
|
20
20
|
BleManager: BleManager;
|
|
21
21
|
bleManagerEmitter: NativeEventEmitter;
|
|
22
22
|
platform: PlatformOSType;
|
|
23
|
+
autoConnect?: boolean;
|
|
23
24
|
};
|
|
24
25
|
declare type BleManagerEvents = {
|
|
25
26
|
stopScan$: Observable<void>;
|
|
@@ -27,9 +28,11 @@ declare type BleManagerEvents = {
|
|
|
27
28
|
connectPeripheral$: Observable<void>;
|
|
28
29
|
disconnectPeripheral$: Observable<void>;
|
|
29
30
|
didUpdateValueForCharacteristic$: Observable<any>;
|
|
31
|
+
didUpdateState$: Observable<any>;
|
|
30
32
|
};
|
|
31
33
|
export declare class ReactNativeTransport implements BluetoothTransport {
|
|
32
34
|
type: TRANSPORT_TYPE;
|
|
35
|
+
options: Options;
|
|
33
36
|
BleManager: BleManager;
|
|
34
37
|
bleManagerEmitter: NativeEventEmitter;
|
|
35
38
|
platform: PlatformOSType;
|
|
@@ -41,10 +44,12 @@ export declare class ReactNativeTransport implements BluetoothTransport {
|
|
|
41
44
|
logs$: ReplaySubject<string>;
|
|
42
45
|
onDisconnected$: Observable<void>;
|
|
43
46
|
connectionStream$: Observable<BLUETOOTH_CONNECTION>;
|
|
47
|
+
_isAutoConnectEnabled$: ReplaySubject<boolean>;
|
|
44
48
|
constructor(options: Options);
|
|
45
49
|
addLog(log: string): void;
|
|
46
50
|
isConnected(): boolean;
|
|
47
51
|
_autoConnect(selectedDevice$: Observable<DeviceInfo>): Observable<void>;
|
|
52
|
+
enableAutoConnect(autoConnect: boolean): void;
|
|
48
53
|
connection(): Observable<BLUETOOTH_CONNECTION>;
|
|
49
54
|
_fromEvent(eventName: string): Observable<any>;
|
|
50
55
|
scan(options?: {
|
|
@@ -24,6 +24,9 @@ import { CHARACTERISTIC_UUIDS_TO_NAMES } from "../constants";
|
|
|
24
24
|
import { ANDROID_MAX_MTU } from "../constants";
|
|
25
25
|
import { REACT_NATIVE_MAX_BYTE_SIZE } from "../constants";
|
|
26
26
|
import { osHasBluetoothSupport } from "../utils/osHasBluetoothSupport";
|
|
27
|
+
const defaultOptions = {
|
|
28
|
+
autoConnect: true
|
|
29
|
+
};
|
|
27
30
|
export class ReactNativeTransport {
|
|
28
31
|
constructor(options) {
|
|
29
32
|
this.type = TRANSPORT_TYPE.REACT_NATIVE;
|
|
@@ -34,7 +37,14 @@ export class ReactNativeTransport {
|
|
|
34
37
|
this.connectionStream$ = this.connection$
|
|
35
38
|
.asObservable()
|
|
36
39
|
.pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
|
|
37
|
-
|
|
40
|
+
this._isAutoConnectEnabled$ = new ReplaySubject(1);
|
|
41
|
+
if (!options) {
|
|
42
|
+
const errorMessage = "React Native transport: missing options.";
|
|
43
|
+
this.addLog(errorMessage);
|
|
44
|
+
throw new Error(errorMessage);
|
|
45
|
+
}
|
|
46
|
+
this.options = Object.assign(Object.assign({}, defaultOptions), options);
|
|
47
|
+
const { BleManager, bleManagerEmitter, platform, autoConnect } = this.options;
|
|
38
48
|
if (!BleManager) {
|
|
39
49
|
const errorMessage = "React Native option: BleManager not provided.";
|
|
40
50
|
this.addLog(errorMessage);
|
|
@@ -53,6 +63,10 @@ export class ReactNativeTransport {
|
|
|
53
63
|
this.BleManager = BleManager;
|
|
54
64
|
this.bleManagerEmitter = bleManagerEmitter;
|
|
55
65
|
this.platform = platform;
|
|
66
|
+
this._isAutoConnectEnabled$.next(autoConnect);
|
|
67
|
+
this._isAutoConnectEnabled$.subscribe((autoConnect) => {
|
|
68
|
+
this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
|
|
69
|
+
});
|
|
56
70
|
// We create a single listener per event type to
|
|
57
71
|
// avoid missing events when multiple listeners are attached.
|
|
58
72
|
this.bleEvents = {
|
|
@@ -60,7 +74,8 @@ export class ReactNativeTransport {
|
|
|
60
74
|
discoverPeripheral$: this._fromEvent("BleManagerDiscoverPeripheral"),
|
|
61
75
|
connectPeripheral$: this._fromEvent("BleManagerConnectPeripheral"),
|
|
62
76
|
disconnectPeripheral$: this._fromEvent("BleManagerDisconnectPeripheral"),
|
|
63
|
-
didUpdateValueForCharacteristic$: this._fromEvent("BleManagerDidUpdateValueForCharacteristic")
|
|
77
|
+
didUpdateValueForCharacteristic$: this._fromEvent("BleManagerDidUpdateValueForCharacteristic"),
|
|
78
|
+
didUpdateState$: this._fromEvent("BleManagerDidUpdateState")
|
|
64
79
|
};
|
|
65
80
|
this.onDisconnected$ = this.bleEvents.disconnectPeripheral$.pipe(share());
|
|
66
81
|
// Initializes the module. This can only be called once.
|
|
@@ -88,7 +103,9 @@ export class ReactNativeTransport {
|
|
|
88
103
|
}
|
|
89
104
|
_autoConnect(selectedDevice$) {
|
|
90
105
|
const selectedDeviceAfterDisconnect$ = this.onDisconnected$.pipe(switchMap(() => selectedDevice$));
|
|
91
|
-
return
|
|
106
|
+
return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
|
|
107
|
+
? merge(selectedDevice$, selectedDeviceAfterDisconnect$)
|
|
108
|
+
: NEVER), switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice)
|
|
92
109
|
? NEVER
|
|
93
110
|
: this.scan().pipe(switchMap((peripherals) => {
|
|
94
111
|
const peripheralMatch = peripherals.find((peripheral) => peripheral.name === (selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceNickname));
|
|
@@ -97,6 +114,9 @@ export class ReactNativeTransport {
|
|
|
97
114
|
return yield this.connect(peripheral);
|
|
98
115
|
})));
|
|
99
116
|
}
|
|
117
|
+
enableAutoConnect(autoConnect) {
|
|
118
|
+
this._isAutoConnectEnabled$.next(autoConnect);
|
|
119
|
+
}
|
|
100
120
|
connection() {
|
|
101
121
|
return this.connectionStream$;
|
|
102
122
|
}
|
|
@@ -5,8 +5,12 @@ import { BluetoothTransport } from "../BluetoothTransport";
|
|
|
5
5
|
import { ActionOptions, SubscribeOptions } from "../types";
|
|
6
6
|
import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
|
|
7
7
|
import { DeviceInfo } from "../../../types/deviceInfo";
|
|
8
|
+
declare type Options = {
|
|
9
|
+
autoConnect?: boolean;
|
|
10
|
+
};
|
|
8
11
|
export declare class WebBluetoothTransport implements BluetoothTransport {
|
|
9
12
|
type: TRANSPORT_TYPE;
|
|
13
|
+
options: Options;
|
|
10
14
|
device: BluetoothDevice;
|
|
11
15
|
server: BluetoothRemoteGATTServer;
|
|
12
16
|
service: BluetoothRemoteGATTService;
|
|
@@ -18,9 +22,11 @@ export declare class WebBluetoothTransport implements BluetoothTransport {
|
|
|
18
22
|
logs$: ReplaySubject<string>;
|
|
19
23
|
onDisconnected$: Observable<void>;
|
|
20
24
|
connectionStream$: Observable<BLUETOOTH_CONNECTION>;
|
|
21
|
-
|
|
25
|
+
_isAutoConnectEnabled$: ReplaySubject<boolean>;
|
|
26
|
+
constructor(options?: Options);
|
|
22
27
|
_getPairedDevices(): Promise<BluetoothDevice[]>;
|
|
23
28
|
_autoConnect(selectedDevice$: Observable<DeviceInfo>): Observable<void>;
|
|
29
|
+
enableAutoConnect(autoConnect: boolean): void;
|
|
24
30
|
addLog(log: string): void;
|
|
25
31
|
isConnected(): boolean;
|
|
26
32
|
connection(): Observable<BLUETOOTH_CONNECTION>;
|
|
@@ -45,3 +51,4 @@ export declare class WebBluetoothTransport implements BluetoothTransport {
|
|
|
45
51
|
_autoToggleActionNotifications(selectedDevice$: Observable<DeviceInfo>): Promise<void>;
|
|
46
52
|
dispatchAction({ characteristicName, action }: ActionOptions): Promise<any>;
|
|
47
53
|
}
|
|
54
|
+
export {};
|
|
@@ -24,8 +24,11 @@ import { TRANSPORT_TYPE, BLUETOOTH_CONNECTION } from "../types";
|
|
|
24
24
|
import { DEFAULT_ACTION_RESPONSE_TIMEOUT } from "../constants";
|
|
25
25
|
import { CHARACTERISTIC_UUIDS_TO_NAMES } from "../constants";
|
|
26
26
|
import { osHasBluetoothSupport } from "../utils/osHasBluetoothSupport";
|
|
27
|
+
const defaultOptions = {
|
|
28
|
+
autoConnect: true
|
|
29
|
+
};
|
|
27
30
|
export class WebBluetoothTransport {
|
|
28
|
-
constructor() {
|
|
31
|
+
constructor(options = {}) {
|
|
29
32
|
this.type = TRANSPORT_TYPE.WEB;
|
|
30
33
|
this.characteristicsByName = {};
|
|
31
34
|
this.connection$ = new BehaviorSubject(BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
@@ -35,11 +38,17 @@ export class WebBluetoothTransport {
|
|
|
35
38
|
this.connectionStream$ = this.connection$
|
|
36
39
|
.asObservable()
|
|
37
40
|
.pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
|
|
41
|
+
this._isAutoConnectEnabled$ = new ReplaySubject(1);
|
|
42
|
+
this.options = Object.assign(Object.assign({}, defaultOptions), options);
|
|
38
43
|
if (!isWebBluetoothSupported()) {
|
|
39
44
|
const errorMessage = "Web Bluetooth is not supported";
|
|
40
45
|
this.addLog(errorMessage);
|
|
41
46
|
throw new Error(errorMessage);
|
|
42
47
|
}
|
|
48
|
+
this._isAutoConnectEnabled$.subscribe((autoConnect) => {
|
|
49
|
+
this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
|
|
50
|
+
});
|
|
51
|
+
this._isAutoConnectEnabled$.next(this.options.autoConnect);
|
|
43
52
|
this.connection$.asObservable().subscribe((connection) => {
|
|
44
53
|
this.addLog(`connection status is ${connection}`);
|
|
45
54
|
});
|
|
@@ -53,7 +62,9 @@ export class WebBluetoothTransport {
|
|
|
53
62
|
});
|
|
54
63
|
}
|
|
55
64
|
_autoConnect(selectedDevice$) {
|
|
56
|
-
return
|
|
65
|
+
return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
|
|
66
|
+
? merge(selectedDevice$, this.onDisconnected$.pipe(switchMap(() => selectedDevice$)))
|
|
67
|
+
: NEVER), switchMap((selectedDevice) => osHasBluetoothSupport(selectedDevice) ? of(selectedDevice) : EMPTY), switchMap((selectedDevice) => __awaiter(this, void 0, void 0, function* () {
|
|
57
68
|
var _a;
|
|
58
69
|
const { deviceNickname } = selectedDevice;
|
|
59
70
|
if (this.isConnected()) {
|
|
@@ -84,6 +95,9 @@ export class WebBluetoothTransport {
|
|
|
84
95
|
return yield this.getServerServiceAndCharacteristics(advertisement.device);
|
|
85
96
|
})));
|
|
86
97
|
}
|
|
98
|
+
enableAutoConnect(autoConnect) {
|
|
99
|
+
this._isAutoConnectEnabled$.next(autoConnect);
|
|
100
|
+
}
|
|
87
101
|
addLog(log) {
|
|
88
102
|
this.logs$.next(log);
|
|
89
103
|
}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/neurosity.mjs
CHANGED
|
@@ -46325,8 +46325,11 @@ var __awaiter$d = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
46325
46325
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46326
46326
|
});
|
|
46327
46327
|
};
|
|
46328
|
+
const defaultOptions$1 = {
|
|
46329
|
+
autoConnect: true
|
|
46330
|
+
};
|
|
46328
46331
|
class WebBluetoothTransport {
|
|
46329
|
-
constructor() {
|
|
46332
|
+
constructor(options = {}) {
|
|
46330
46333
|
this.type = TRANSPORT_TYPE.WEB;
|
|
46331
46334
|
this.characteristicsByName = {};
|
|
46332
46335
|
this.connection$ = new BehaviorSubject(BLUETOOTH_CONNECTION.DISCONNECTED);
|
|
@@ -46336,11 +46339,17 @@ class WebBluetoothTransport {
|
|
|
46336
46339
|
this.connectionStream$ = this.connection$
|
|
46337
46340
|
.asObservable()
|
|
46338
46341
|
.pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
|
|
46342
|
+
this._isAutoConnectEnabled$ = new ReplaySubject(1);
|
|
46343
|
+
this.options = Object.assign(Object.assign({}, defaultOptions$1), options);
|
|
46339
46344
|
if (!isWebBluetoothSupported()) {
|
|
46340
46345
|
const errorMessage = "Web Bluetooth is not supported";
|
|
46341
46346
|
this.addLog(errorMessage);
|
|
46342
46347
|
throw new Error(errorMessage);
|
|
46343
46348
|
}
|
|
46349
|
+
this._isAutoConnectEnabled$.subscribe((autoConnect) => {
|
|
46350
|
+
this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
|
|
46351
|
+
});
|
|
46352
|
+
this._isAutoConnectEnabled$.next(this.options.autoConnect);
|
|
46344
46353
|
this.connection$.asObservable().subscribe((connection) => {
|
|
46345
46354
|
this.addLog(`connection status is ${connection}`);
|
|
46346
46355
|
});
|
|
@@ -46354,7 +46363,9 @@ class WebBluetoothTransport {
|
|
|
46354
46363
|
});
|
|
46355
46364
|
}
|
|
46356
46365
|
_autoConnect(selectedDevice$) {
|
|
46357
|
-
return
|
|
46366
|
+
return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
|
|
46367
|
+
? merge(selectedDevice$, this.onDisconnected$.pipe(switchMap(() => selectedDevice$)))
|
|
46368
|
+
: NEVER), switchMap((selectedDevice) => osHasBluetoothSupport(selectedDevice) ? of(selectedDevice) : EMPTY), switchMap((selectedDevice) => __awaiter$d(this, void 0, void 0, function* () {
|
|
46358
46369
|
var _a;
|
|
46359
46370
|
const { deviceNickname } = selectedDevice;
|
|
46360
46371
|
if (this.isConnected()) {
|
|
@@ -46385,6 +46396,9 @@ class WebBluetoothTransport {
|
|
|
46385
46396
|
return yield this.getServerServiceAndCharacteristics(advertisement.device);
|
|
46386
46397
|
})));
|
|
46387
46398
|
}
|
|
46399
|
+
enableAutoConnect(autoConnect) {
|
|
46400
|
+
this._isAutoConnectEnabled$.next(autoConnect);
|
|
46401
|
+
}
|
|
46388
46402
|
addLog(log) {
|
|
46389
46403
|
this.logs$.next(log);
|
|
46390
46404
|
}
|
|
@@ -46721,6 +46735,9 @@ var __awaiter$e = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
46721
46735
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
46722
46736
|
});
|
|
46723
46737
|
};
|
|
46738
|
+
const defaultOptions$2 = {
|
|
46739
|
+
autoConnect: true
|
|
46740
|
+
};
|
|
46724
46741
|
class ReactNativeTransport {
|
|
46725
46742
|
constructor(options) {
|
|
46726
46743
|
this.type = TRANSPORT_TYPE.REACT_NATIVE;
|
|
@@ -46731,7 +46748,14 @@ class ReactNativeTransport {
|
|
|
46731
46748
|
this.connectionStream$ = this.connection$
|
|
46732
46749
|
.asObservable()
|
|
46733
46750
|
.pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
|
|
46734
|
-
|
|
46751
|
+
this._isAutoConnectEnabled$ = new ReplaySubject(1);
|
|
46752
|
+
if (!options) {
|
|
46753
|
+
const errorMessage = "React Native transport: missing options.";
|
|
46754
|
+
this.addLog(errorMessage);
|
|
46755
|
+
throw new Error(errorMessage);
|
|
46756
|
+
}
|
|
46757
|
+
this.options = Object.assign(Object.assign({}, defaultOptions$2), options);
|
|
46758
|
+
const { BleManager, bleManagerEmitter, platform, autoConnect } = this.options;
|
|
46735
46759
|
if (!BleManager) {
|
|
46736
46760
|
const errorMessage = "React Native option: BleManager not provided.";
|
|
46737
46761
|
this.addLog(errorMessage);
|
|
@@ -46750,6 +46774,10 @@ class ReactNativeTransport {
|
|
|
46750
46774
|
this.BleManager = BleManager;
|
|
46751
46775
|
this.bleManagerEmitter = bleManagerEmitter;
|
|
46752
46776
|
this.platform = platform;
|
|
46777
|
+
this._isAutoConnectEnabled$.next(autoConnect);
|
|
46778
|
+
this._isAutoConnectEnabled$.subscribe((autoConnect) => {
|
|
46779
|
+
this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
|
|
46780
|
+
});
|
|
46753
46781
|
// We create a single listener per event type to
|
|
46754
46782
|
// avoid missing events when multiple listeners are attached.
|
|
46755
46783
|
this.bleEvents = {
|
|
@@ -46757,7 +46785,8 @@ class ReactNativeTransport {
|
|
|
46757
46785
|
discoverPeripheral$: this._fromEvent("BleManagerDiscoverPeripheral"),
|
|
46758
46786
|
connectPeripheral$: this._fromEvent("BleManagerConnectPeripheral"),
|
|
46759
46787
|
disconnectPeripheral$: this._fromEvent("BleManagerDisconnectPeripheral"),
|
|
46760
|
-
didUpdateValueForCharacteristic$: this._fromEvent("BleManagerDidUpdateValueForCharacteristic")
|
|
46788
|
+
didUpdateValueForCharacteristic$: this._fromEvent("BleManagerDidUpdateValueForCharacteristic"),
|
|
46789
|
+
didUpdateState$: this._fromEvent("BleManagerDidUpdateState")
|
|
46761
46790
|
};
|
|
46762
46791
|
this.onDisconnected$ = this.bleEvents.disconnectPeripheral$.pipe(share());
|
|
46763
46792
|
// Initializes the module. This can only be called once.
|
|
@@ -46785,7 +46814,9 @@ class ReactNativeTransport {
|
|
|
46785
46814
|
}
|
|
46786
46815
|
_autoConnect(selectedDevice$) {
|
|
46787
46816
|
const selectedDeviceAfterDisconnect$ = this.onDisconnected$.pipe(switchMap(() => selectedDevice$));
|
|
46788
|
-
return
|
|
46817
|
+
return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
|
|
46818
|
+
? merge(selectedDevice$, selectedDeviceAfterDisconnect$)
|
|
46819
|
+
: NEVER), switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice)
|
|
46789
46820
|
? NEVER
|
|
46790
46821
|
: this.scan().pipe(switchMap((peripherals) => {
|
|
46791
46822
|
const peripheralMatch = peripherals.find((peripheral) => peripheral.name === (selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceNickname));
|
|
@@ -46794,6 +46825,9 @@ class ReactNativeTransport {
|
|
|
46794
46825
|
return yield this.connect(peripheral);
|
|
46795
46826
|
})));
|
|
46796
46827
|
}
|
|
46828
|
+
enableAutoConnect(autoConnect) {
|
|
46829
|
+
this._isAutoConnectEnabled$.next(autoConnect);
|
|
46830
|
+
}
|
|
46797
46831
|
connection() {
|
|
46798
46832
|
return this.connectionStream$;
|
|
46799
46833
|
}
|
|
@@ -47247,6 +47281,9 @@ class BluetoothClient {
|
|
|
47247
47281
|
}
|
|
47248
47282
|
})))));
|
|
47249
47283
|
}
|
|
47284
|
+
enableAutoConnect(autoConnect) {
|
|
47285
|
+
this.transport.enableAutoConnect(autoConnect);
|
|
47286
|
+
}
|
|
47250
47287
|
_hasBluetoothSupport() {
|
|
47251
47288
|
return __awaiter$f(this, void 0, void 0, function* () {
|
|
47252
47289
|
const selectedDevice = yield firstValueFrom(this.selectedDevice$);
|
|
@@ -47475,7 +47512,7 @@ var __awaiter$g = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
47475
47512
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47476
47513
|
});
|
|
47477
47514
|
};
|
|
47478
|
-
const defaultOptions$
|
|
47515
|
+
const defaultOptions$3 = {
|
|
47479
47516
|
timesync: false,
|
|
47480
47517
|
autoSelectDevice: true,
|
|
47481
47518
|
streamingMode: STREAMING_MODE.WIFI_ONLY,
|
|
@@ -47513,7 +47550,7 @@ class Neurosity {
|
|
|
47513
47550
|
*/
|
|
47514
47551
|
this.streamingMode$ = new ReplaySubject(1);
|
|
47515
47552
|
const { streamingMode, bluetoothTransport } = options;
|
|
47516
|
-
this.options = Object.freeze(Object.assign(Object.assign({}, defaultOptions$
|
|
47553
|
+
this.options = Object.freeze(Object.assign(Object.assign({}, defaultOptions$3), options));
|
|
47517
47554
|
this.cloudClient = new CloudClient(this.options);
|
|
47518
47555
|
if (!!bluetoothTransport) {
|
|
47519
47556
|
this.bluetoothClient = new BluetoothClient({
|
|
@@ -48590,53 +48627,6 @@ class Neurosity {
|
|
|
48590
48627
|
removeOAuthAccess() {
|
|
48591
48628
|
return this.cloudClient.removeOAuthAccess();
|
|
48592
48629
|
}
|
|
48593
|
-
/**
|
|
48594
|
-
* @internal
|
|
48595
|
-
* Proof of Concept for Skills - Not user facing yet
|
|
48596
|
-
*
|
|
48597
|
-
* Accesses a skill by Bundle ID. Additionally, allows to observe
|
|
48598
|
-
* and push skill metrics
|
|
48599
|
-
*
|
|
48600
|
-
* @param bundleId Bundle ID of skill
|
|
48601
|
-
* @returns Skill instance
|
|
48602
|
-
*/
|
|
48603
|
-
skill(bundleId) {
|
|
48604
|
-
return __awaiter$g(this, void 0, void 0, function* () {
|
|
48605
|
-
if (!(yield this.cloudClient.didSelectDevice())) {
|
|
48606
|
-
return Promise.reject(mustSelectDevice);
|
|
48607
|
-
}
|
|
48608
|
-
const skillData = yield this.cloudClient.skills.get(bundleId);
|
|
48609
|
-
if (skillData === null) {
|
|
48610
|
-
return Promise.reject(new Error(`${prefix}Access denied for: ${bundleId}. Make sure the skill is installed.`));
|
|
48611
|
-
}
|
|
48612
|
-
return {
|
|
48613
|
-
metric: (label) => {
|
|
48614
|
-
const metricName = `skill~${skillData.id}~${label}`;
|
|
48615
|
-
const subscription = new Observable((observer) => {
|
|
48616
|
-
const subscription = this.cloudClient.metrics.subscribe({
|
|
48617
|
-
metric: metricName,
|
|
48618
|
-
labels: [label],
|
|
48619
|
-
atomic: true
|
|
48620
|
-
});
|
|
48621
|
-
const listener = this.cloudClient.metrics.on(subscription, (...data) => {
|
|
48622
|
-
observer.next(...data);
|
|
48623
|
-
});
|
|
48624
|
-
return () => {
|
|
48625
|
-
this.cloudClient.metrics.unsubscribe(subscription, listener);
|
|
48626
|
-
};
|
|
48627
|
-
}).pipe(map((metric) => metric[label]));
|
|
48628
|
-
Object.defineProperty(subscription, "next", {
|
|
48629
|
-
value: (metricValue) => {
|
|
48630
|
-
this.cloudClient.metrics.next(metricName, {
|
|
48631
|
-
[label]: metricValue
|
|
48632
|
-
});
|
|
48633
|
-
}
|
|
48634
|
-
});
|
|
48635
|
-
return subscription;
|
|
48636
|
-
}
|
|
48637
|
-
};
|
|
48638
|
-
});
|
|
48639
|
-
}
|
|
48640
48630
|
/**
|
|
48641
48631
|
* <StreamingModes wifi={true} />
|
|
48642
48632
|
*
|
|
@@ -48707,61 +48697,4 @@ class Notion extends Neurosity {
|
|
|
48707
48697
|
}
|
|
48708
48698
|
}
|
|
48709
48699
|
|
|
48710
|
-
|
|
48711
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48712
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
48713
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48714
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
48715
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
48716
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48717
|
-
});
|
|
48718
|
-
};
|
|
48719
|
-
/**
|
|
48720
|
-
* @internal
|
|
48721
|
-
*/
|
|
48722
|
-
function createNotionOnDevice(options) {
|
|
48723
|
-
return __awaiter$h(this, void 0, void 0, function* () {
|
|
48724
|
-
const neurosity = new Neurosity(options);
|
|
48725
|
-
const skill = Object.assign(Object.assign({}, (yield neurosity.skill(options.skill.bundleId))), { props: "props" in options.skill ? options.skill.props : {} });
|
|
48726
|
-
delete neurosity.skill;
|
|
48727
|
-
return [neurosity, skill];
|
|
48728
|
-
});
|
|
48729
|
-
}
|
|
48730
|
-
|
|
48731
|
-
var __awaiter$i = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
48732
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48733
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
48734
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48735
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
48736
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
48737
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48738
|
-
});
|
|
48739
|
-
};
|
|
48740
|
-
function createSkill(app) {
|
|
48741
|
-
return {
|
|
48742
|
-
subscribe: (options) => __awaiter$i(this, void 0, void 0, function* () {
|
|
48743
|
-
const [neurosity, skill] = yield createNotionOnDevice(Object.assign({}, options));
|
|
48744
|
-
const teardown = app(neurosity, skill);
|
|
48745
|
-
return {
|
|
48746
|
-
unsubscribe: () => __awaiter$i(this, void 0, void 0, function* () {
|
|
48747
|
-
yield neurosity.disconnect();
|
|
48748
|
-
if (teardown && "then" in teardown) {
|
|
48749
|
-
const cleanUp = yield teardown;
|
|
48750
|
-
if (typeof cleanUp === "function") {
|
|
48751
|
-
cleanUp();
|
|
48752
|
-
}
|
|
48753
|
-
}
|
|
48754
|
-
if (typeof teardown === "function" && "then" in teardown()) {
|
|
48755
|
-
return yield teardown();
|
|
48756
|
-
}
|
|
48757
|
-
if (typeof teardown === "function") {
|
|
48758
|
-
return teardown();
|
|
48759
|
-
}
|
|
48760
|
-
return teardown;
|
|
48761
|
-
})
|
|
48762
|
-
};
|
|
48763
|
-
})
|
|
48764
|
-
};
|
|
48765
|
-
}
|
|
48766
|
-
|
|
48767
|
-
export { Neurosity, Notion, BluetoothClient, WebBluetoothTransport, ReactNativeTransport, osHasBluetoothSupport, createSkill, createNotionOnDevice };
|
|
48700
|
+
export { Neurosity, Notion, BluetoothClient, WebBluetoothTransport, ReactNativeTransport, osHasBluetoothSupport };
|