@neurosity/sdk 6.2.4 → 6.4.0-next.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.
Files changed (40) hide show
  1. package/dist/browser/neurosity.iife.js +83 -17
  2. package/dist/browser/neurosity.js +7 -7
  3. package/dist/browser/neurosity.js.map +1 -1
  4. package/dist/cjs/Neurosity.d.ts +17 -1
  5. package/dist/cjs/Neurosity.js +26 -2
  6. package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +3 -1
  7. package/dist/cjs/api/bluetooth/BluetoothClient.js +9 -5
  8. package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +2 -2
  9. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +3 -3
  10. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +6 -4
  11. package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -2
  12. package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.js +4 -2
  13. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +3 -3
  14. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +8 -4
  15. package/dist/cjs/api/index.d.ts +3 -1
  16. package/dist/cjs/api/index.js +4 -0
  17. package/dist/cjs/types/deviceInfo.d.ts +2 -1
  18. package/dist/cjs/utils/oauth.js +1 -0
  19. package/dist/electron/index.js +7 -7
  20. package/dist/electron/index.js.map +1 -1
  21. package/dist/esm/Neurosity.d.ts +17 -1
  22. package/dist/esm/Neurosity.js +26 -2
  23. package/dist/esm/api/bluetooth/BluetoothClient.d.ts +3 -1
  24. package/dist/esm/api/bluetooth/BluetoothClient.js +10 -6
  25. package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +2 -2
  26. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +3 -3
  27. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +7 -5
  28. package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -2
  29. package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.js +4 -2
  30. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +3 -3
  31. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +9 -5
  32. package/dist/esm/api/index.d.ts +3 -1
  33. package/dist/esm/api/index.js +4 -0
  34. package/dist/esm/neurosity.mjs +83 -17
  35. package/dist/esm/types/deviceInfo.d.ts +2 -1
  36. package/dist/esm/utils/oauth.js +1 -0
  37. package/dist/examples/neurosity.iife.js +83 -17
  38. package/dist/examples/neurosity.js +7 -7
  39. package/dist/examples/neurosity.mjs +83 -17
  40. package/package.json +1 -1
@@ -2307,6 +2307,11 @@ var Neurosity = (function (exports) {
2307
2307
 
2308
2308
  var NEVER = new Observable(noop);
2309
2309
 
2310
+ var isArray$2 = Array.isArray;
2311
+ function argsOrArgArray(args) {
2312
+ return args.length === 1 && isArray$2(args[0]) ? args[0] : args;
2313
+ }
2314
+
2310
2315
  function filter(predicate, thisArg) {
2311
2316
  return operate(function (source, subscriber) {
2312
2317
  var index = 0;
@@ -2435,6 +2440,27 @@ var Neurosity = (function (exports) {
2435
2440
  };
2436
2441
  }
2437
2442
 
2443
+ function combineLatest$1() {
2444
+ var args = [];
2445
+ for (var _i = 0; _i < arguments.length; _i++) {
2446
+ args[_i] = arguments[_i];
2447
+ }
2448
+ var resultSelector = popResultSelector(args);
2449
+ return resultSelector
2450
+ ? pipe(combineLatest$1.apply(void 0, __spreadArray([], __read(args))), mapOneOrManyArgs(resultSelector))
2451
+ : operate(function (source, subscriber) {
2452
+ combineLatestInit(__spreadArray([source], __read(argsOrArgArray(args))))(subscriber);
2453
+ });
2454
+ }
2455
+
2456
+ function combineLatestWith() {
2457
+ var otherSources = [];
2458
+ for (var _i = 0; _i < arguments.length; _i++) {
2459
+ otherSources[_i] = arguments[_i];
2460
+ }
2461
+ return combineLatest$1.apply(void 0, __spreadArray([], __read(otherSources)));
2462
+ }
2463
+
2438
2464
  function concatMap(project, resultSelector) {
2439
2465
  return isFunction(resultSelector) ? mergeMap(project, resultSelector, 1) : mergeMap(project, 1);
2440
2466
  }
@@ -43007,6 +43033,7 @@ var Neurosity = (function (exports) {
43007
43033
  this.firebaseUser = new FirebaseUser(this.firebaseApp);
43008
43034
  this._selectedDevice.next(undefined);
43009
43035
  this.status$ = heartbeatAwareStatus(this.observeNamespace("status").pipe(share())).pipe(filterInternalKeys(), shareReplay(1));
43036
+ this.osVersion$ = this.observeNamespace("info/osVersion").pipe(shareReplay(1));
43010
43037
  this.firebaseUser.onAuthStateChanged().subscribe((user) => {
43011
43038
  this.user = user;
43012
43039
  });
@@ -43040,6 +43067,9 @@ var Neurosity = (function (exports) {
43040
43067
  .asObservable()
43041
43068
  .pipe(filter((value) => value !== undefined));
43042
43069
  }
43070
+ osVersion() {
43071
+ return this.osVersion$;
43072
+ }
43043
43073
  // Automatically select device when user logs in
43044
43074
  setAutoSelectedDevice() {
43045
43075
  return __awaiter$b(this, void 0, void 0, function* () {
@@ -43780,6 +43810,7 @@ var Neurosity = (function (exports) {
43780
43810
  selectDevice: "read:devices-info",
43781
43811
  onDeviceChange: "read:devices-info",
43782
43812
  onUserDevicesChange: "read:devices-info",
43813
+ osVersion: "read:devices-info",
43783
43814
  // end device info
43784
43815
  settings: "read:devices-settings",
43785
43816
  changeSettings: "write:devices-settings",
@@ -46303,7 +46334,7 @@ var Neurosity = (function (exports) {
46303
46334
  const gte = (a, b, loose) => compare_1(a, b, loose) >= 0;
46304
46335
  var gte_1 = gte;
46305
46336
 
46306
- function osHasBluetoothSupport(selectedDevice) {
46337
+ function osHasBluetoothSupport(selectedDevice, osVersion) {
46307
46338
  if (!selectedDevice) {
46308
46339
  return false;
46309
46340
  }
@@ -46316,7 +46347,9 @@ var Neurosity = (function (exports) {
46316
46347
  if (isEmulator) {
46317
46348
  return false;
46318
46349
  }
46319
- return gte_1(selectedDevice.osVersion, "16.0.0");
46350
+ // `osVersion` is updated in real time,
46351
+ // unlike accessing via `selectedDevice.osVersion`
46352
+ return gte_1(osVersion !== null && osVersion !== void 0 ? osVersion : selectedDevice.osVersion, "16.0.0");
46320
46353
  }
46321
46354
 
46322
46355
  var __awaiter$d = function (thisArg, _arguments, P, generator) {
@@ -46365,10 +46398,12 @@ var Neurosity = (function (exports) {
46365
46398
  return yield navigator.bluetooth.getDevices();
46366
46399
  });
46367
46400
  }
46368
- _autoConnect(selectedDevice$) {
46401
+ _autoConnect(selectedDevice$, osVersion$) {
46369
46402
  return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
46370
46403
  ? merge(selectedDevice$, this.onDisconnected$.pipe(switchMap(() => selectedDevice$)))
46371
- : NEVER), switchMap((selectedDevice) => osHasBluetoothSupport(selectedDevice) ? of(selectedDevice) : EMPTY), switchMap((selectedDevice) => __awaiter$d(this, void 0, void 0, function* () {
46404
+ : NEVER), combineLatestWith(osVersion$), switchMap(([selectedDevice, osVersion]) => osHasBluetoothSupport(selectedDevice, osVersion)
46405
+ ? of(selectedDevice)
46406
+ : EMPTY), switchMap((selectedDevice) => __awaiter$d(this, void 0, void 0, function* () {
46372
46407
  var _a;
46373
46408
  const { deviceNickname } = selectedDevice;
46374
46409
  if (this.isConnected()) {
@@ -46608,7 +46643,7 @@ var Neurosity = (function (exports) {
46608
46643
  const actions = this.pendingActions$.getValue();
46609
46644
  this.pendingActions$.next(actions.filter((id) => id !== actionId));
46610
46645
  }
46611
- _autoToggleActionNotifications(selectedDevice$) {
46646
+ _autoToggleActionNotifications(selectedDevice$, osVersion$) {
46612
46647
  return __awaiter$d(this, void 0, void 0, function* () {
46613
46648
  let actionsCharacteristic;
46614
46649
  let started = false;
@@ -46642,7 +46677,9 @@ var Neurosity = (function (exports) {
46642
46677
  }
46643
46678
  })));
46644
46679
  selectedDevice$
46645
- .pipe(switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice) ? EMPTY : sideEffects$))
46680
+ .pipe(combineLatestWith(osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
46681
+ ? EMPTY
46682
+ : sideEffects$))
46646
46683
  .subscribe();
46647
46684
  });
46648
46685
  }
@@ -46815,11 +46852,11 @@ var Neurosity = (function (exports) {
46815
46852
  const connection = this.connection$.getValue();
46816
46853
  return connection === exports.BLUETOOTH_CONNECTION.CONNECTED;
46817
46854
  }
46818
- _autoConnect(selectedDevice$) {
46855
+ _autoConnect(selectedDevice$, osVersion$) {
46819
46856
  const selectedDeviceAfterDisconnect$ = this.onDisconnected$.pipe(switchMap(() => selectedDevice$));
46820
46857
  return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
46821
46858
  ? merge(selectedDevice$, selectedDeviceAfterDisconnect$)
46822
- : NEVER), switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice)
46859
+ : NEVER), combineLatestWith(osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
46823
46860
  ? NEVER
46824
46861
  : this.scan().pipe(switchMap((peripherals) => {
46825
46862
  const peripheralMatch = peripherals.find((peripheral) => peripheral.name === (selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceNickname));
@@ -47047,7 +47084,7 @@ var Neurosity = (function (exports) {
47047
47084
  const actions = this.pendingActions$.getValue();
47048
47085
  this.pendingActions$.next(actions.filter((id) => id !== actionId));
47049
47086
  }
47050
- _autoToggleActionNotifications(selectedDevice$) {
47087
+ _autoToggleActionNotifications(selectedDevice$, osVersion$) {
47051
47088
  return __awaiter$e(this, void 0, void 0, function* () {
47052
47089
  let started = false;
47053
47090
  const sideEffects$ = this.connection$.asObservable().pipe(switchMap((connection) => connection === exports.BLUETOOTH_CONNECTION.CONNECTED
@@ -47078,7 +47115,9 @@ var Neurosity = (function (exports) {
47078
47115
  }
47079
47116
  })));
47080
47117
  selectedDevice$
47081
- .pipe(switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice) ? EMPTY : sideEffects$))
47118
+ .pipe(combineLatestWith(osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
47119
+ ? EMPTY
47120
+ : sideEffects$))
47082
47121
  .subscribe();
47083
47122
  });
47084
47123
  }
@@ -47231,6 +47270,7 @@ var Neurosity = (function (exports) {
47231
47270
  class BluetoothClient {
47232
47271
  constructor(options) {
47233
47272
  this.selectedDevice$ = new ReplaySubject(1);
47273
+ this.osVersion$ = new ReplaySubject(1);
47234
47274
  this.isAuthenticated$ = new ReplaySubject(1);
47235
47275
  const { transport, selectedDevice$, createBluetoothToken } = options !== null && options !== void 0 ? options : {};
47236
47276
  if (!transport) {
@@ -47242,7 +47282,9 @@ var Neurosity = (function (exports) {
47242
47282
  selectedDevice$.subscribe(this.selectedDevice$);
47243
47283
  }
47244
47284
  // Auto Connect
47245
- this.transport._autoConnect(this.selectedDevice$).subscribe({
47285
+ this.transport
47286
+ ._autoConnect(this.selectedDevice$, this.osVersion$)
47287
+ .subscribe({
47246
47288
  error: (error) => {
47247
47289
  var _a;
47248
47290
  this.transport.addLog(`Auto connect: error -> ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
@@ -47257,7 +47299,7 @@ var Neurosity = (function (exports) {
47257
47299
  this.transport.addLog("Auto authentication not enabled");
47258
47300
  }
47259
47301
  // Auto manage action notifications
47260
- this.transport._autoToggleActionNotifications(this.selectedDevice$);
47302
+ this.transport._autoToggleActionNotifications(this.selectedDevice$, this.osVersion$);
47261
47303
  // Multicast metrics (share)
47262
47304
  this._focus$ = this._subscribeWhileAuthenticated("focus");
47263
47305
  this._calm$ = this._subscribeWhileAuthenticated("calm");
@@ -47281,7 +47323,7 @@ var Neurosity = (function (exports) {
47281
47323
  const reauthenticateInterval$ = timer(0, REAUTHENTICATE_INTERVAL).pipe(tap(() => {
47282
47324
  this.transport.addLog(`Auto authentication in progress...`);
47283
47325
  }));
47284
- return this.selectedDevice$.pipe(switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice)
47326
+ return this.selectedDevice$.pipe(combineLatestWith(this.osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
47285
47327
  ? EMPTY
47286
47328
  : this.connection().pipe(switchMap((connection) => connection === exports.BLUETOOTH_CONNECTION.CONNECTED
47287
47329
  ? reauthenticateInterval$
@@ -47301,7 +47343,8 @@ var Neurosity = (function (exports) {
47301
47343
  _hasBluetoothSupport() {
47302
47344
  return __awaiter$f(this, void 0, void 0, function* () {
47303
47345
  const selectedDevice = yield firstValueFrom(this.selectedDevice$);
47304
- return osHasBluetoothSupport(selectedDevice);
47346
+ const osVersion = yield firstValueFrom(this.osVersion$);
47347
+ return osHasBluetoothSupport(selectedDevice, osVersion);
47305
47348
  });
47306
47349
  }
47307
47350
  authenticate(token) {
@@ -47382,7 +47425,7 @@ var Neurosity = (function (exports) {
47382
47425
  });
47383
47426
  }
47384
47427
  _subscribeWhileAuthenticated(characteristicName) {
47385
- return this.selectedDevice$.pipe(switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice)
47428
+ return this.selectedDevice$.pipe(combineLatestWith(this.osVersion$), switchMap(([selectedDevice, osVersion]) => !osHasBluetoothSupport(selectedDevice, osVersion)
47386
47429
  ? EMPTY
47387
47430
  : this.isAuthenticated$.pipe(distinctUntilChanged(), switchMap((isAuthenticated) => isAuthenticated
47388
47431
  ? this.transport.subscribeToCharacteristic({
@@ -47569,6 +47612,7 @@ var Neurosity = (function (exports) {
47569
47612
  if (!!bluetoothTransport) {
47570
47613
  this.bluetoothClient = new BluetoothClient({
47571
47614
  selectedDevice$: this.onDeviceChange(),
47615
+ osVersion$: this.osVersion(),
47572
47616
  createBluetoothToken: this.createBluetoothToken.bind(this),
47573
47617
  transport: bluetoothTransport
47574
47618
  });
@@ -47614,12 +47658,12 @@ var Neurosity = (function (exports) {
47614
47658
  streamingState() {
47615
47659
  const isWifiOnline = (state) => [STATUS.ONLINE, STATUS.UPDATING].includes(state);
47616
47660
  return this.streamingMode$.pipe(switchMap((streamingMode) => {
47617
- return this.onDeviceChange().pipe(switchMap((selectDevice) => {
47661
+ return this.onDeviceChange().pipe(combineLatestWith(this.osVersion()), switchMap(([selectDevice, osVersion]) => {
47618
47662
  if (!selectDevice) {
47619
47663
  return EMPTY;
47620
47664
  }
47621
47665
  const isUnableToUseBluetooth = this.isMissingBluetoothTransport ||
47622
- !osHasBluetoothSupport(selectDevice);
47666
+ !osHasBluetoothSupport(selectDevice, osVersion);
47623
47667
  if (isUnableToUseBluetooth) {
47624
47668
  return this.cloudClient.status().pipe(map(({ state }) => ({
47625
47669
  connected: isWifiOnline(state),
@@ -48265,6 +48309,28 @@ var Neurosity = (function (exports) {
48265
48309
  }
48266
48310
  return this.cloudClient.observeNamespace("settings");
48267
48311
  }
48312
+ /**
48313
+ * <StreamingModes wifi={true} />
48314
+ *
48315
+ * Observes the current OS version and all subsequent version changes in real-time.
48316
+ *
48317
+ * ```typescript
48318
+ * neurosity.osVersion().subscribe((osVersion) => {
48319
+ * console.log(osVersion);
48320
+ * });
48321
+ *
48322
+ * // "16.0.0"
48323
+ * ```
48324
+ *
48325
+ * @returns Observable of `osVersion` events. e.g 16.0.0
48326
+ */
48327
+ osVersion() {
48328
+ const [hasOAuthError, OAuthError] = validateOAuthScopeForFunctionName(this.cloudClient.userClaims, "osVersion");
48329
+ if (hasOAuthError) {
48330
+ return throwError(() => OAuthError);
48331
+ }
48332
+ return this.cloudClient.osVersion();
48333
+ }
48268
48334
  /**
48269
48335
  * <StreamingModes wifi={true} bluetooth={true} />
48270
48336
  *