@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.
Files changed (45) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/browser/neurosity.iife.js +44 -113
  3. package/dist/browser/neurosity.js +8 -14
  4. package/dist/browser/neurosity.js.map +1 -1
  5. package/dist/cjs/{Notion.d.ts → Neurosity.d.ts} +0 -0
  6. package/dist/cjs/{Notion.js → Neurosity.js} +0 -47
  7. package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +1 -0
  8. package/dist/cjs/api/bluetooth/BluetoothClient.js +3 -0
  9. package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +1 -0
  10. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +5 -0
  11. package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +23 -3
  12. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +8 -1
  13. package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +16 -2
  14. package/dist/cjs/index.d.ts +1 -2
  15. package/dist/cjs/index.js +1 -2
  16. package/dist/electron/index.js +8 -14
  17. package/dist/electron/index.js.map +1 -1
  18. package/dist/esm/{Notion.d.ts → Neurosity.d.ts} +0 -0
  19. package/dist/esm/{Notion.js → Neurosity.js} +1 -48
  20. package/dist/esm/api/bluetooth/BluetoothClient.d.ts +1 -0
  21. package/dist/esm/api/bluetooth/BluetoothClient.js +3 -0
  22. package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +1 -0
  23. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +5 -0
  24. package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +23 -3
  25. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +8 -1
  26. package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +16 -2
  27. package/dist/esm/index.d.ts +1 -2
  28. package/dist/esm/index.js +1 -2
  29. package/dist/esm/neurosity.mjs +45 -112
  30. package/dist/examples/neurosity.iife.js +44 -113
  31. package/dist/examples/neurosity.js +8 -14
  32. package/dist/examples/neurosity.mjs +45 -112
  33. package/package.json +1 -1
  34. package/dist/cjs/skills/NotionOnDevice.d.ts +0 -7
  35. package/dist/cjs/skills/NotionOnDevice.js +0 -25
  36. package/dist/cjs/skills/createSkill.d.ts +0 -7
  37. package/dist/cjs/skills/createSkill.js +0 -40
  38. package/dist/cjs/skills/index.d.ts +0 -2
  39. package/dist/cjs/skills/index.js +0 -18
  40. package/dist/esm/skills/NotionOnDevice.d.ts +0 -7
  41. package/dist/esm/skills/NotionOnDevice.js +0 -21
  42. package/dist/esm/skills/createSkill.d.ts +0 -7
  43. package/dist/esm/skills/createSkill.js +0 -36
  44. package/dist/esm/skills/index.d.ts +0 -2
  45. package/dist/esm/skills/index.js +0 -2
@@ -46328,8 +46328,11 @@ var Neurosity = (function (exports) {
46328
46328
  step((generator = generator.apply(thisArg, _arguments || [])).next());
46329
46329
  });
46330
46330
  };
46331
+ const defaultOptions$1 = {
46332
+ autoConnect: true
46333
+ };
46331
46334
  class WebBluetoothTransport {
46332
- constructor() {
46335
+ constructor(options = {}) {
46333
46336
  this.type = TRANSPORT_TYPE.WEB;
46334
46337
  this.characteristicsByName = {};
46335
46338
  this.connection$ = new BehaviorSubject(BLUETOOTH_CONNECTION.DISCONNECTED);
@@ -46339,11 +46342,17 @@ var Neurosity = (function (exports) {
46339
46342
  this.connectionStream$ = this.connection$
46340
46343
  .asObservable()
46341
46344
  .pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
46345
+ this._isAutoConnectEnabled$ = new ReplaySubject(1);
46346
+ this.options = Object.assign(Object.assign({}, defaultOptions$1), options);
46342
46347
  if (!isWebBluetoothSupported()) {
46343
46348
  const errorMessage = "Web Bluetooth is not supported";
46344
46349
  this.addLog(errorMessage);
46345
46350
  throw new Error(errorMessage);
46346
46351
  }
46352
+ this._isAutoConnectEnabled$.subscribe((autoConnect) => {
46353
+ this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
46354
+ });
46355
+ this._isAutoConnectEnabled$.next(this.options.autoConnect);
46347
46356
  this.connection$.asObservable().subscribe((connection) => {
46348
46357
  this.addLog(`connection status is ${connection}`);
46349
46358
  });
@@ -46357,7 +46366,9 @@ var Neurosity = (function (exports) {
46357
46366
  });
46358
46367
  }
46359
46368
  _autoConnect(selectedDevice$) {
46360
- return merge(selectedDevice$, this.onDisconnected$.pipe(switchMap(() => selectedDevice$))).pipe(switchMap((selectedDevice) => osHasBluetoothSupport(selectedDevice) ? of(selectedDevice) : EMPTY), switchMap((selectedDevice) => __awaiter$d(this, void 0, void 0, function* () {
46369
+ return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
46370
+ ? 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* () {
46361
46372
  var _a;
46362
46373
  const { deviceNickname } = selectedDevice;
46363
46374
  if (this.isConnected()) {
@@ -46388,6 +46399,9 @@ var Neurosity = (function (exports) {
46388
46399
  return yield this.getServerServiceAndCharacteristics(advertisement.device);
46389
46400
  })));
46390
46401
  }
46402
+ enableAutoConnect(autoConnect) {
46403
+ this._isAutoConnectEnabled$.next(autoConnect);
46404
+ }
46391
46405
  addLog(log) {
46392
46406
  this.logs$.next(log);
46393
46407
  }
@@ -46724,6 +46738,9 @@ var Neurosity = (function (exports) {
46724
46738
  step((generator = generator.apply(thisArg, _arguments || [])).next());
46725
46739
  });
46726
46740
  };
46741
+ const defaultOptions$2 = {
46742
+ autoConnect: true
46743
+ };
46727
46744
  class ReactNativeTransport {
46728
46745
  constructor(options) {
46729
46746
  this.type = TRANSPORT_TYPE.REACT_NATIVE;
@@ -46734,7 +46751,14 @@ var Neurosity = (function (exports) {
46734
46751
  this.connectionStream$ = this.connection$
46735
46752
  .asObservable()
46736
46753
  .pipe(filter((connection) => !!connection), distinctUntilChanged(), shareReplay(1));
46737
- const { BleManager, bleManagerEmitter, platform } = options;
46754
+ this._isAutoConnectEnabled$ = new ReplaySubject(1);
46755
+ if (!options) {
46756
+ const errorMessage = "React Native transport: missing options.";
46757
+ this.addLog(errorMessage);
46758
+ throw new Error(errorMessage);
46759
+ }
46760
+ this.options = Object.assign(Object.assign({}, defaultOptions$2), options);
46761
+ const { BleManager, bleManagerEmitter, platform, autoConnect } = this.options;
46738
46762
  if (!BleManager) {
46739
46763
  const errorMessage = "React Native option: BleManager not provided.";
46740
46764
  this.addLog(errorMessage);
@@ -46753,6 +46777,10 @@ var Neurosity = (function (exports) {
46753
46777
  this.BleManager = BleManager;
46754
46778
  this.bleManagerEmitter = bleManagerEmitter;
46755
46779
  this.platform = platform;
46780
+ this._isAutoConnectEnabled$.next(autoConnect);
46781
+ this._isAutoConnectEnabled$.subscribe((autoConnect) => {
46782
+ this.addLog(`Auto connect: ${autoConnect ? "enabled" : "disabled"}`);
46783
+ });
46756
46784
  // We create a single listener per event type to
46757
46785
  // avoid missing events when multiple listeners are attached.
46758
46786
  this.bleEvents = {
@@ -46760,7 +46788,8 @@ var Neurosity = (function (exports) {
46760
46788
  discoverPeripheral$: this._fromEvent("BleManagerDiscoverPeripheral"),
46761
46789
  connectPeripheral$: this._fromEvent("BleManagerConnectPeripheral"),
46762
46790
  disconnectPeripheral$: this._fromEvent("BleManagerDisconnectPeripheral"),
46763
- didUpdateValueForCharacteristic$: this._fromEvent("BleManagerDidUpdateValueForCharacteristic")
46791
+ didUpdateValueForCharacteristic$: this._fromEvent("BleManagerDidUpdateValueForCharacteristic"),
46792
+ didUpdateState$: this._fromEvent("BleManagerDidUpdateState")
46764
46793
  };
46765
46794
  this.onDisconnected$ = this.bleEvents.disconnectPeripheral$.pipe(share());
46766
46795
  // Initializes the module. This can only be called once.
@@ -46788,7 +46817,9 @@ var Neurosity = (function (exports) {
46788
46817
  }
46789
46818
  _autoConnect(selectedDevice$) {
46790
46819
  const selectedDeviceAfterDisconnect$ = this.onDisconnected$.pipe(switchMap(() => selectedDevice$));
46791
- return merge(selectedDevice$, selectedDeviceAfterDisconnect$).pipe(switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice)
46820
+ return this._isAutoConnectEnabled$.pipe(switchMap((isAutoConnectEnabled) => isAutoConnectEnabled
46821
+ ? merge(selectedDevice$, selectedDeviceAfterDisconnect$)
46822
+ : NEVER), switchMap((selectedDevice) => !osHasBluetoothSupport(selectedDevice)
46792
46823
  ? NEVER
46793
46824
  : this.scan().pipe(switchMap((peripherals) => {
46794
46825
  const peripheralMatch = peripherals.find((peripheral) => peripheral.name === (selectedDevice === null || selectedDevice === void 0 ? void 0 : selectedDevice.deviceNickname));
@@ -46797,6 +46828,9 @@ var Neurosity = (function (exports) {
46797
46828
  return yield this.connect(peripheral);
46798
46829
  })));
46799
46830
  }
46831
+ enableAutoConnect(autoConnect) {
46832
+ this._isAutoConnectEnabled$.next(autoConnect);
46833
+ }
46800
46834
  connection() {
46801
46835
  return this.connectionStream$;
46802
46836
  }
@@ -47250,6 +47284,9 @@ var Neurosity = (function (exports) {
47250
47284
  }
47251
47285
  })))));
47252
47286
  }
47287
+ enableAutoConnect(autoConnect) {
47288
+ this.transport.enableAutoConnect(autoConnect);
47289
+ }
47253
47290
  _hasBluetoothSupport() {
47254
47291
  return __awaiter$f(this, void 0, void 0, function* () {
47255
47292
  const selectedDevice = yield firstValueFrom(this.selectedDevice$);
@@ -47478,7 +47515,7 @@ var Neurosity = (function (exports) {
47478
47515
  step((generator = generator.apply(thisArg, _arguments || [])).next());
47479
47516
  });
47480
47517
  };
47481
- const defaultOptions$1 = {
47518
+ const defaultOptions$3 = {
47482
47519
  timesync: false,
47483
47520
  autoSelectDevice: true,
47484
47521
  streamingMode: STREAMING_MODE.WIFI_ONLY,
@@ -47516,7 +47553,7 @@ var Neurosity = (function (exports) {
47516
47553
  */
47517
47554
  this.streamingMode$ = new ReplaySubject(1);
47518
47555
  const { streamingMode, bluetoothTransport } = options;
47519
- this.options = Object.freeze(Object.assign(Object.assign({}, defaultOptions$1), options));
47556
+ this.options = Object.freeze(Object.assign(Object.assign({}, defaultOptions$3), options));
47520
47557
  this.cloudClient = new CloudClient(this.options);
47521
47558
  if (!!bluetoothTransport) {
47522
47559
  this.bluetoothClient = new BluetoothClient({
@@ -48593,53 +48630,6 @@ var Neurosity = (function (exports) {
48593
48630
  removeOAuthAccess() {
48594
48631
  return this.cloudClient.removeOAuthAccess();
48595
48632
  }
48596
- /**
48597
- * @internal
48598
- * Proof of Concept for Skills - Not user facing yet
48599
- *
48600
- * Accesses a skill by Bundle ID. Additionally, allows to observe
48601
- * and push skill metrics
48602
- *
48603
- * @param bundleId Bundle ID of skill
48604
- * @returns Skill instance
48605
- */
48606
- skill(bundleId) {
48607
- return __awaiter$g(this, void 0, void 0, function* () {
48608
- if (!(yield this.cloudClient.didSelectDevice())) {
48609
- return Promise.reject(mustSelectDevice);
48610
- }
48611
- const skillData = yield this.cloudClient.skills.get(bundleId);
48612
- if (skillData === null) {
48613
- return Promise.reject(new Error(`${prefix}Access denied for: ${bundleId}. Make sure the skill is installed.`));
48614
- }
48615
- return {
48616
- metric: (label) => {
48617
- const metricName = `skill~${skillData.id}~${label}`;
48618
- const subscription = new Observable((observer) => {
48619
- const subscription = this.cloudClient.metrics.subscribe({
48620
- metric: metricName,
48621
- labels: [label],
48622
- atomic: true
48623
- });
48624
- const listener = this.cloudClient.metrics.on(subscription, (...data) => {
48625
- observer.next(...data);
48626
- });
48627
- return () => {
48628
- this.cloudClient.metrics.unsubscribe(subscription, listener);
48629
- };
48630
- }).pipe(map((metric) => metric[label]));
48631
- Object.defineProperty(subscription, "next", {
48632
- value: (metricValue) => {
48633
- this.cloudClient.metrics.next(metricName, {
48634
- [label]: metricValue
48635
- });
48636
- }
48637
- });
48638
- return subscription;
48639
- }
48640
- };
48641
- });
48642
- }
48643
48633
  /**
48644
48634
  * <StreamingModes wifi={true} />
48645
48635
  *
@@ -48710,71 +48700,12 @@ var Neurosity = (function (exports) {
48710
48700
  }
48711
48701
  }
48712
48702
 
48713
- var __awaiter$h = function (thisArg, _arguments, P, generator) {
48714
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
48715
- return new (P || (P = Promise))(function (resolve, reject) {
48716
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
48717
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
48718
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
48719
- step((generator = generator.apply(thisArg, _arguments || [])).next());
48720
- });
48721
- };
48722
- /**
48723
- * @internal
48724
- */
48725
- function createNotionOnDevice(options) {
48726
- return __awaiter$h(this, void 0, void 0, function* () {
48727
- const neurosity = new Neurosity(options);
48728
- const skill = Object.assign(Object.assign({}, (yield neurosity.skill(options.skill.bundleId))), { props: "props" in options.skill ? options.skill.props : {} });
48729
- delete neurosity.skill;
48730
- return [neurosity, skill];
48731
- });
48732
- }
48733
-
48734
- var __awaiter$i = function (thisArg, _arguments, P, generator) {
48735
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
48736
- return new (P || (P = Promise))(function (resolve, reject) {
48737
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
48738
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
48739
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
48740
- step((generator = generator.apply(thisArg, _arguments || [])).next());
48741
- });
48742
- };
48743
- function createSkill(app) {
48744
- return {
48745
- subscribe: (options) => __awaiter$i(this, void 0, void 0, function* () {
48746
- const [neurosity, skill] = yield createNotionOnDevice(Object.assign({}, options));
48747
- const teardown = app(neurosity, skill);
48748
- return {
48749
- unsubscribe: () => __awaiter$i(this, void 0, void 0, function* () {
48750
- yield neurosity.disconnect();
48751
- if (teardown && "then" in teardown) {
48752
- const cleanUp = yield teardown;
48753
- if (typeof cleanUp === "function") {
48754
- cleanUp();
48755
- }
48756
- }
48757
- if (typeof teardown === "function" && "then" in teardown()) {
48758
- return yield teardown();
48759
- }
48760
- if (typeof teardown === "function") {
48761
- return teardown();
48762
- }
48763
- return teardown;
48764
- })
48765
- };
48766
- })
48767
- };
48768
- }
48769
-
48770
48703
  exports.Neurosity = Neurosity;
48771
48704
  exports.Notion = Notion;
48772
48705
  exports.BluetoothClient = BluetoothClient;
48773
48706
  exports.WebBluetoothTransport = WebBluetoothTransport;
48774
48707
  exports.ReactNativeTransport = ReactNativeTransport;
48775
48708
  exports.osHasBluetoothSupport = osHasBluetoothSupport;
48776
- exports.createSkill = createSkill;
48777
- exports.createNotionOnDevice = createNotionOnDevice;
48778
48709
 
48779
48710
  return exports;
48780
48711