@neurosity/sdk 6.0.0-next.12 → 6.0.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.
@@ -23,6 +23,18 @@ export declare class BluetoothClient {
23
23
  deviceInfo: DeviceInfo;
24
24
  selectedDevice$: ReplaySubject<DeviceInfo>;
25
25
  isAuthenticated$: ReplaySubject<boolean>;
26
+ _focus$: Observable<any>;
27
+ _calm$: Observable<any>;
28
+ _accelerometer$: Observable<any>;
29
+ _brainwavesRaw$: Observable<any>;
30
+ _brainwavesRawUnfiltered$: Observable<any>;
31
+ _brainwavesPSD$: Observable<any>;
32
+ _brainwavesPowerByBand$: Observable<any>;
33
+ _signalQuality$: Observable<any>;
34
+ _status$: Observable<any>;
35
+ _settings$: Observable<any>;
36
+ _wifiNearbyNetworks$: Observable<any>;
37
+ _wifiConnections$: Observable<any>;
26
38
  constructor(options: Options);
27
39
  _autoAuthenticate(createBluetoothToken: CreateBluetoothToken): Observable<IsAuthenticatedResponse>;
28
40
  _hasBluetoothSupport(): Promise<boolean>;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { defer, firstValueFrom, timer } from "rxjs";
11
11
  import { ReplaySubject, EMPTY } from "rxjs";
12
- import { switchMap, tap } from "rxjs/operators";
12
+ import { switchMap, share, tap } from "rxjs/operators";
13
13
  import { distinctUntilChanged } from "rxjs/operators";
14
14
  import { WebBluetoothTransport } from "./web/WebBluetoothTransport";
15
15
  import { ReactNativeTransport } from "./react-native/ReactNativeTransport";
@@ -46,6 +46,23 @@ export class BluetoothClient {
46
46
  }
47
47
  // Auto manage action notifications
48
48
  this.transport._autoToggleActionNotifications(this.selectedDevice$);
49
+ // Multicast metrics (share)
50
+ this._focus$ = this._subscribeWhileAuthenticated("focus");
51
+ this._calm$ = this._subscribeWhileAuthenticated("calm");
52
+ this._accelerometer$ = this._subscribeWhileAuthenticated("accelerometer");
53
+ this._brainwavesRaw$ = this._subscribeWhileAuthenticated("raw");
54
+ this._brainwavesRawUnfiltered$ =
55
+ this._subscribeWhileAuthenticated("rawUnfiltered");
56
+ this._brainwavesPSD$ = this._subscribeWhileAuthenticated("psd");
57
+ this._brainwavesPowerByBand$ =
58
+ this._subscribeWhileAuthenticated("powerByBand");
59
+ this._signalQuality$ = this._subscribeWhileAuthenticated("signalQuality");
60
+ this._status$ = this._subscribeWhileAuthenticated("status");
61
+ this._settings$ = this._subscribeWhileAuthenticated("settings");
62
+ this._wifiNearbyNetworks$ =
63
+ this._subscribeWhileAuthenticated("wifiNearbyNetworks");
64
+ this._wifiConnections$ =
65
+ this._subscribeWhileAuthenticated("wifiConnections");
49
66
  }
50
67
  _autoAuthenticate(createBluetoothToken) {
51
68
  const REAUTHENTICATE_INTERVAL = 3600000; // 1 hour
@@ -156,28 +173,32 @@ export class BluetoothClient {
156
173
  ? this.transport.subscribeToCharacteristic({
157
174
  characteristicName
158
175
  })
159
- : EMPTY))));
176
+ : EMPTY))), share());
160
177
  }
161
178
  focus() {
162
- return this._subscribeWhileAuthenticated("focus");
179
+ return this._focus$;
163
180
  }
164
181
  calm() {
165
- return this._subscribeWhileAuthenticated("calm");
182
+ return this._calm$;
166
183
  }
167
184
  accelerometer() {
168
- return this._subscribeWhileAuthenticated("accelerometer");
185
+ return this._accelerometer$;
169
186
  }
170
187
  brainwaves(label) {
171
188
  switch (label) {
189
+ default:
172
190
  case "raw":
191
+ return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRaw$.pipe(csvBufferToEpoch(deviceInfo))));
173
192
  case "rawUnfiltered":
174
- return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._subscribeWhileAuthenticated(label).pipe(csvBufferToEpoch(deviceInfo))));
175
- default:
176
- return this._subscribeWhileAuthenticated(label);
193
+ return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRawUnfiltered$.pipe(csvBufferToEpoch(deviceInfo))));
194
+ case "psd":
195
+ return this._brainwavesPSD$;
196
+ case "powerByBand":
197
+ return this._brainwavesPowerByBand$;
177
198
  }
178
199
  }
179
200
  signalQuality() {
180
- return this._subscribeWhileAuthenticated("signalQuality");
201
+ return this._signalQuality$;
181
202
  }
182
203
  addMarker(label) {
183
204
  return __awaiter(this, void 0, void 0, function* () {
@@ -198,9 +219,8 @@ export class BluetoothClient {
198
219
  })));
199
220
  });
200
221
  }
201
- // Tested
202
222
  status() {
203
- return this._subscribeWhileAuthenticated("status");
223
+ return this._status$;
204
224
  }
205
225
  dispatchAction(action) {
206
226
  return __awaiter(this, void 0, void 0, function* () {
@@ -211,7 +231,7 @@ export class BluetoothClient {
211
231
  });
212
232
  }
213
233
  settings() {
214
- return this._subscribeWhileAuthenticated("settings");
234
+ return this._settings$;
215
235
  }
216
236
  haptics(effects) {
217
237
  const metric = "haptics";
@@ -226,8 +246,8 @@ export class BluetoothClient {
226
246
  }
227
247
  get wifi() {
228
248
  return {
229
- nearbyNetworks: () => this._subscribeWhileAuthenticated("wifiNearbyNetworks"),
230
- connections: () => this._subscribeWhileAuthenticated("wifiConnections"),
249
+ nearbyNetworks: () => this._wifiNearbyNetworks$,
250
+ connections: () => this._wifiConnections$,
231
251
  connect: (ssid, password) => {
232
252
  if (!ssid) {
233
253
  return Promise.reject(`Missing ssid`);
@@ -47210,6 +47210,23 @@ class BluetoothClient {
47210
47210
  }
47211
47211
  // Auto manage action notifications
47212
47212
  this.transport._autoToggleActionNotifications(this.selectedDevice$);
47213
+ // Multicast metrics (share)
47214
+ this._focus$ = this._subscribeWhileAuthenticated("focus");
47215
+ this._calm$ = this._subscribeWhileAuthenticated("calm");
47216
+ this._accelerometer$ = this._subscribeWhileAuthenticated("accelerometer");
47217
+ this._brainwavesRaw$ = this._subscribeWhileAuthenticated("raw");
47218
+ this._brainwavesRawUnfiltered$ =
47219
+ this._subscribeWhileAuthenticated("rawUnfiltered");
47220
+ this._brainwavesPSD$ = this._subscribeWhileAuthenticated("psd");
47221
+ this._brainwavesPowerByBand$ =
47222
+ this._subscribeWhileAuthenticated("powerByBand");
47223
+ this._signalQuality$ = this._subscribeWhileAuthenticated("signalQuality");
47224
+ this._status$ = this._subscribeWhileAuthenticated("status");
47225
+ this._settings$ = this._subscribeWhileAuthenticated("settings");
47226
+ this._wifiNearbyNetworks$ =
47227
+ this._subscribeWhileAuthenticated("wifiNearbyNetworks");
47228
+ this._wifiConnections$ =
47229
+ this._subscribeWhileAuthenticated("wifiConnections");
47213
47230
  }
47214
47231
  _autoAuthenticate(createBluetoothToken) {
47215
47232
  const REAUTHENTICATE_INTERVAL = 3600000; // 1 hour
@@ -47320,28 +47337,32 @@ class BluetoothClient {
47320
47337
  ? this.transport.subscribeToCharacteristic({
47321
47338
  characteristicName
47322
47339
  })
47323
- : EMPTY))));
47340
+ : EMPTY))), share());
47324
47341
  }
47325
47342
  focus() {
47326
- return this._subscribeWhileAuthenticated("focus");
47343
+ return this._focus$;
47327
47344
  }
47328
47345
  calm() {
47329
- return this._subscribeWhileAuthenticated("calm");
47346
+ return this._calm$;
47330
47347
  }
47331
47348
  accelerometer() {
47332
- return this._subscribeWhileAuthenticated("accelerometer");
47349
+ return this._accelerometer$;
47333
47350
  }
47334
47351
  brainwaves(label) {
47335
47352
  switch (label) {
47353
+ default:
47336
47354
  case "raw":
47355
+ return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRaw$.pipe(csvBufferToEpoch(deviceInfo))));
47337
47356
  case "rawUnfiltered":
47338
- return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._subscribeWhileAuthenticated(label).pipe(csvBufferToEpoch(deviceInfo))));
47339
- default:
47340
- return this._subscribeWhileAuthenticated(label);
47357
+ return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRawUnfiltered$.pipe(csvBufferToEpoch(deviceInfo))));
47358
+ case "psd":
47359
+ return this._brainwavesPSD$;
47360
+ case "powerByBand":
47361
+ return this._brainwavesPowerByBand$;
47341
47362
  }
47342
47363
  }
47343
47364
  signalQuality() {
47344
- return this._subscribeWhileAuthenticated("signalQuality");
47365
+ return this._signalQuality$;
47345
47366
  }
47346
47367
  addMarker(label) {
47347
47368
  return __awaiter$f(this, void 0, void 0, function* () {
@@ -47362,9 +47383,8 @@ class BluetoothClient {
47362
47383
  })));
47363
47384
  });
47364
47385
  }
47365
- // Tested
47366
47386
  status() {
47367
- return this._subscribeWhileAuthenticated("status");
47387
+ return this._status$;
47368
47388
  }
47369
47389
  dispatchAction(action) {
47370
47390
  return __awaiter$f(this, void 0, void 0, function* () {
@@ -47375,7 +47395,7 @@ class BluetoothClient {
47375
47395
  });
47376
47396
  }
47377
47397
  settings() {
47378
- return this._subscribeWhileAuthenticated("settings");
47398
+ return this._settings$;
47379
47399
  }
47380
47400
  haptics(effects) {
47381
47401
  const metric = "haptics";
@@ -47390,8 +47410,8 @@ class BluetoothClient {
47390
47410
  }
47391
47411
  get wifi() {
47392
47412
  return {
47393
- nearbyNetworks: () => this._subscribeWhileAuthenticated("wifiNearbyNetworks"),
47394
- connections: () => this._subscribeWhileAuthenticated("wifiConnections"),
47413
+ nearbyNetworks: () => this._wifiNearbyNetworks$,
47414
+ connections: () => this._wifiConnections$,
47395
47415
  connect: (ssid, password) => {
47396
47416
  if (!ssid) {
47397
47417
  return Promise.reject(`Missing ssid`);
@@ -47213,6 +47213,23 @@ var Neurosity = (function (exports) {
47213
47213
  }
47214
47214
  // Auto manage action notifications
47215
47215
  this.transport._autoToggleActionNotifications(this.selectedDevice$);
47216
+ // Multicast metrics (share)
47217
+ this._focus$ = this._subscribeWhileAuthenticated("focus");
47218
+ this._calm$ = this._subscribeWhileAuthenticated("calm");
47219
+ this._accelerometer$ = this._subscribeWhileAuthenticated("accelerometer");
47220
+ this._brainwavesRaw$ = this._subscribeWhileAuthenticated("raw");
47221
+ this._brainwavesRawUnfiltered$ =
47222
+ this._subscribeWhileAuthenticated("rawUnfiltered");
47223
+ this._brainwavesPSD$ = this._subscribeWhileAuthenticated("psd");
47224
+ this._brainwavesPowerByBand$ =
47225
+ this._subscribeWhileAuthenticated("powerByBand");
47226
+ this._signalQuality$ = this._subscribeWhileAuthenticated("signalQuality");
47227
+ this._status$ = this._subscribeWhileAuthenticated("status");
47228
+ this._settings$ = this._subscribeWhileAuthenticated("settings");
47229
+ this._wifiNearbyNetworks$ =
47230
+ this._subscribeWhileAuthenticated("wifiNearbyNetworks");
47231
+ this._wifiConnections$ =
47232
+ this._subscribeWhileAuthenticated("wifiConnections");
47216
47233
  }
47217
47234
  _autoAuthenticate(createBluetoothToken) {
47218
47235
  const REAUTHENTICATE_INTERVAL = 3600000; // 1 hour
@@ -47323,28 +47340,32 @@ var Neurosity = (function (exports) {
47323
47340
  ? this.transport.subscribeToCharacteristic({
47324
47341
  characteristicName
47325
47342
  })
47326
- : EMPTY))));
47343
+ : EMPTY))), share());
47327
47344
  }
47328
47345
  focus() {
47329
- return this._subscribeWhileAuthenticated("focus");
47346
+ return this._focus$;
47330
47347
  }
47331
47348
  calm() {
47332
- return this._subscribeWhileAuthenticated("calm");
47349
+ return this._calm$;
47333
47350
  }
47334
47351
  accelerometer() {
47335
- return this._subscribeWhileAuthenticated("accelerometer");
47352
+ return this._accelerometer$;
47336
47353
  }
47337
47354
  brainwaves(label) {
47338
47355
  switch (label) {
47356
+ default:
47339
47357
  case "raw":
47358
+ return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRaw$.pipe(csvBufferToEpoch(deviceInfo))));
47340
47359
  case "rawUnfiltered":
47341
- return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._subscribeWhileAuthenticated(label).pipe(csvBufferToEpoch(deviceInfo))));
47342
- default:
47343
- return this._subscribeWhileAuthenticated(label);
47360
+ return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRawUnfiltered$.pipe(csvBufferToEpoch(deviceInfo))));
47361
+ case "psd":
47362
+ return this._brainwavesPSD$;
47363
+ case "powerByBand":
47364
+ return this._brainwavesPowerByBand$;
47344
47365
  }
47345
47366
  }
47346
47367
  signalQuality() {
47347
- return this._subscribeWhileAuthenticated("signalQuality");
47368
+ return this._signalQuality$;
47348
47369
  }
47349
47370
  addMarker(label) {
47350
47371
  return __awaiter$f(this, void 0, void 0, function* () {
@@ -47365,9 +47386,8 @@ var Neurosity = (function (exports) {
47365
47386
  })));
47366
47387
  });
47367
47388
  }
47368
- // Tested
47369
47389
  status() {
47370
- return this._subscribeWhileAuthenticated("status");
47390
+ return this._status$;
47371
47391
  }
47372
47392
  dispatchAction(action) {
47373
47393
  return __awaiter$f(this, void 0, void 0, function* () {
@@ -47378,7 +47398,7 @@ var Neurosity = (function (exports) {
47378
47398
  });
47379
47399
  }
47380
47400
  settings() {
47381
- return this._subscribeWhileAuthenticated("settings");
47401
+ return this._settings$;
47382
47402
  }
47383
47403
  haptics(effects) {
47384
47404
  const metric = "haptics";
@@ -47393,8 +47413,8 @@ var Neurosity = (function (exports) {
47393
47413
  }
47394
47414
  get wifi() {
47395
47415
  return {
47396
- nearbyNetworks: () => this._subscribeWhileAuthenticated("wifiNearbyNetworks"),
47397
- connections: () => this._subscribeWhileAuthenticated("wifiConnections"),
47416
+ nearbyNetworks: () => this._wifiNearbyNetworks$,
47417
+ connections: () => this._wifiConnections$,
47398
47418
  connect: (ssid, password) => {
47399
47419
  if (!ssid) {
47400
47420
  return Promise.reject(`Missing ssid`);
@@ -655,7 +655,7 @@ var r=require("./compare"),e=function(e,o,u){return r(e,o,u)>=0};module.exports=
655
655
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE"}],"WTrV":[function(require,module,exports) {
656
656
  "use strict";function e(e){return n(e)||t(e)||r()}function r(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function t(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function n(e){if(Array.isArray(e))return e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.csvBufferToSamples=exports.csvBufferToEpoch=void 0;var o=require("rxjs"),a=require("rxjs/operators"),i=require("../../../utils/pipes"),s=16,u=256;function p(e){var r;return(null==e?void 0:e.samplingRate)||console.warn("Didn't receive a sampling rate, defaulting to ".concat(u)),(0,o.pipe)(c(),(0,i.epoch)({duration:s,interval:s,samplingRate:null!==(r=null==e?void 0:e.samplingRate)&&void 0!==r?r:u}),(0,i.addInfo)({channelNames:e.channelNames,samplingRate:e.samplingRate}))}function c(){return(0,o.pipe)((0,a.mergeMap)(function(e){return(0,o.from)(e)}),(0,a.map)(function(r){var t=e(r),n=t[0];t[1];return{timestamp:n,data:t.slice(2)}}))}exports.csvBufferToEpoch=p,exports.csvBufferToSamples=c;
657
657
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE","../../../utils/pipes":"Oj1i"}],"fihV":[function(require,module,exports) {
658
- "use strict";function t(t,i){return n(t)||r(t,i)||e()}function e(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function r(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var r=[],n=!0,i=!1,s=void 0;try{for(var o,a=t[Symbol.iterator]();!(n=(o=a.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(u){i=!0,s=u}finally{try{n||null==a.return||a.return()}finally{if(i)throw s}}return r}}function n(t){if(Array.isArray(t))return t}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function o(t,e,r){return e&&s(t.prototype,e),r&&s(t,r),t}var a=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(i,s){function o(t){try{u(n.next(t))}catch(e){s(e)}}function a(t){try{u(n.throw(t))}catch(e){s(e)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(o,a)}u((n=n.apply(t,e||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BluetoothClient=void 0;var u=require("rxjs"),c=require("rxjs"),h=require("rxjs/operators"),p=require("rxjs/operators"),d=require("./web/WebBluetoothTransport"),f=require("./react-native/ReactNativeTransport"),l=require("./utils/csvBufferToEpoch"),v=require("./types"),m=require("./utils/osHasBluetoothSupport"),b=function(){function e(t){var r=this;i(this,e),this.selectedDevice$=new c.ReplaySubject(1),this.isAuthenticated$=new c.ReplaySubject(1);var n=null!=t?t:{},s=n.transport,o=n.selectedDevice$,a=n.createBluetoothToken;if(!s)throw new Error("No bluetooth transport provided.");this.transport=s,o&&o.subscribe(this.selectedDevice$),this.transport._autoConnect(this.selectedDevice$).subscribe({error:function(t){var e;r.transport.addLog("Auto connect: error -> ".concat(null!==(e=null==t?void 0:t.message)&&void 0!==e?e:t))}}),"function"==typeof a?(this.transport.addLog("Auto authentication enabled"),this._autoAuthenticate(a).subscribe()):this.transport.addLog("Auto authentication not enabled"),this.transport._autoToggleActionNotifications(this.selectedDevice$)}return o(e,[{key:"_autoAuthenticate",value:function(e){var r=this,n=(0,u.timer)(0,36e5).pipe((0,h.tap)(function(){r.transport.addLog("Auto authentication in progress...")}));return this.selectedDevice$.pipe((0,h.switchMap)(function(i){return(0,m.osHasBluetoothSupport)(i)?r.connection().pipe((0,h.switchMap)(function(t){return t===v.BLUETOOTH_CONNECTION.CONNECTED?n:c.EMPTY}),(0,h.switchMap)(function(){return a(r,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.isAuthenticated();case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}),(0,h.tap)(function(n){var i=t(n,1)[0];return a(r,void 0,void 0,regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i){t.next=8;break}return t.next=3,e();case 3:return r=t.sent,t.next=6,this.authenticate(r);case 6:t.next=9;break;case 8:this.transport.addLog("Already authenticated");case 9:case"end":return t.stop()}},t,this)}))})):c.EMPTY}))}},{key:"_hasBluetoothSupport",value:function(){return a(this,void 0,void 0,regeneratorRuntime.mark(function t(){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,(0,u.firstValueFrom)(this.selectedDevice$);case 2:return e=t.sent,t.abrupt("return",(0,m.osHasBluetoothSupport)(e));case 4:case"end":return t.stop()}},t,this)}))}},{key:"authenticate",value:function(e){return a(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s,o;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._hasBluetoothSupport();case 2:if(r.sent){r.next=7;break}return n="authenticate method: The OS version does not support Bluetooth.",this.transport.addLog(n),r.abrupt("return",Promise.reject(n));case 7:return r.next=9,this.transport.writeCharacteristic("auth",e);case 9:return r.next=11,this.isAuthenticated();case 11:return i=r.sent,s=t(i,1),o=s[0],this.transport.addLog("Authentication ".concat(o?"succeeded":"failed")),this.isAuthenticated$.next(o),r.abrupt("return",i);case 16:case"end":return r.stop()}},r,this)}))}},{key:"isAuthenticated",value:function(){return a(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r,n,i,s;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.transport.readCharacteristic("auth",!0);case 2:return r=e.sent,n=t(r,2),i=n[0],s=n[1],this.isAuthenticated$.next(i),e.abrupt("return",[i,s]);case 8:case"end":return e.stop()}},e,this)}))}},{key:"scan",value:function(t){if(this.transport instanceof f.ReactNativeTransport)return this.transport.scan(t);if(this.transport instanceof d.WebBluetoothTransport)throw new Error("scan method is compatibly with the React Native transport only");throw new Error("unknown transport")}},{key:"connect",value:function(t){return this.transport instanceof f.ReactNativeTransport?this.transport.connect(t):this.transport instanceof d.WebBluetoothTransport?t?this.transport.connect(t):this.transport.connect():void 0}},{key:"disconnect",value:function(){return this.transport.disconnect()}},{key:"connection",value:function(){return this.transport.connection()}},{key:"logs",value:function(){return this.transport.logs$.asObservable()}},{key:"getDeviceId",value:function(){return a(this,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.transport.readCharacteristic("deviceId"));case 1:case"end":return t.stop()}},t,this)}))}},{key:"_withAuthentication",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._hasBluetoothSupport();case 2:if(e.sent){e.next=7;break}return r="The OS version does not support Bluetooth.",this.transport.addLog(r),e.abrupt("return",Promise.reject(r));case 7:return e.next=9,(0,u.firstValueFrom)(this.isAuthenticated$);case 9:if(e.sent){e.next=14;break}return"Authentication required.",this.transport.addLog("Authentication required."),e.abrupt("return",Promise.reject("Authentication required."));case 14:return e.next=16,t();case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}},e,this)}))}},{key:"_subscribeWhileAuthenticated",value:function(t){var e=this;return this.selectedDevice$.pipe((0,h.switchMap)(function(r){return(0,m.osHasBluetoothSupport)(r)?e.isAuthenticated$.pipe((0,p.distinctUntilChanged)(),(0,h.switchMap)(function(r){return r?e.transport.subscribeToCharacteristic({characteristicName:t}):c.EMPTY})):c.EMPTY}))}},{key:"focus",value:function(){return this._subscribeWhileAuthenticated("focus")}},{key:"calm",value:function(){return this._subscribeWhileAuthenticated("calm")}},{key:"accelerometer",value:function(){return this._subscribeWhileAuthenticated("accelerometer")}},{key:"brainwaves",value:function(t){var e=this;switch(t){case"raw":case"rawUnfiltered":return(0,u.defer)(function(){return e.getInfo()}).pipe((0,h.switchMap)(function(r){return e._subscribeWhileAuthenticated(t).pipe((0,l.csvBufferToEpoch)(r))}));default:return this._subscribeWhileAuthenticated(t)}}},{key:"signalQuality",value:function(){return this._subscribeWhileAuthenticated("signalQuality")}},{key:"addMarker",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.dispatchAction({action:"marker",command:"add",message:{timestamp:Date.now(),label:t}});case 2:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return a(this,void 0,void 0,regeneratorRuntime.mark(function t(){var e=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._withAuthentication(function(){return(0,u.firstValueFrom)(e.transport.subscribeToCharacteristic({characteristicName:"deviceInfo"}))});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"status",value:function(){return this._subscribeWhileAuthenticated("status")}},{key:"dispatchAction",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._withAuthentication(function(){return r.transport.dispatchAction({characteristicName:"actions",action:t})});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"settings",value:function(){return this._subscribeWhileAuthenticated("settings")}},{key:"haptics",value:function(t){return this.dispatchAction({action:"haptics",command:"queue",responseRequired:!0,responseTimeout:4e3,message:{effects:t}})}},{key:"wifi",get:function(){var t=this;return{nearbyNetworks:function(){return t._subscribeWhileAuthenticated("wifiNearbyNetworks")},connections:function(){return t._subscribeWhileAuthenticated("wifiConnections")},connect:function(e,r){return e?t.dispatchAction({action:"wifi",command:"connect",responseRequired:!0,responseTimeout:12e4,message:{ssid:e,password:null!=r?r:null}}):Promise.reject("Missing ssid")},forgetConnection:function(e){return e?t.dispatchAction({action:"wifi",command:"forget-connection",responseRequired:!0,responseTimeout:15e3,message:{ssid:e}}):Promise.reject("Missing ssid")},reset:function(){return t.dispatchAction({action:"wifi",command:"reset",responseRequired:!0,responseTimeout:3e4,message:{respondOnSuccess:!0}})},speedTest:function(){return t.dispatchAction({action:"wifi",command:"speed-test",responseRequired:!0,responseTimeout:6e4})}}}}]),e}();exports.BluetoothClient=b;
658
+ "use strict";function t(t,i){return n(t)||r(t,i)||e()}function e(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function r(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var r=[],n=!0,i=!1,s=void 0;try{for(var a,o=t[Symbol.iterator]();!(n=(a=o.next()).done)&&(r.push(a.value),!e||r.length!==e);n=!0);}catch(u){i=!0,s=u}finally{try{n||null==o.return||o.return()}finally{if(i)throw s}}return r}}function n(t){if(Array.isArray(t))return t}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,e,r){return e&&s(t.prototype,e),r&&s(t,r),t}var o=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(i,s){function a(t){try{u(n.next(t))}catch(e){s(e)}}function o(t){try{u(n.throw(t))}catch(e){s(e)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(a,o)}u((n=n.apply(t,e||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BluetoothClient=void 0;var u=require("rxjs"),c=require("rxjs"),h=require("rxjs/operators"),p=require("rxjs/operators"),d=require("./web/WebBluetoothTransport"),f=require("./react-native/ReactNativeTransport"),l=require("./utils/csvBufferToEpoch"),v=require("./types"),w=require("./utils/osHasBluetoothSupport"),b=function(){function e(t){var r=this;i(this,e),this.selectedDevice$=new c.ReplaySubject(1),this.isAuthenticated$=new c.ReplaySubject(1);var n=null!=t?t:{},s=n.transport,a=n.selectedDevice$,o=n.createBluetoothToken;if(!s)throw new Error("No bluetooth transport provided.");this.transport=s,a&&a.subscribe(this.selectedDevice$),this.transport._autoConnect(this.selectedDevice$).subscribe({error:function(t){var e;r.transport.addLog("Auto connect: error -> ".concat(null!==(e=null==t?void 0:t.message)&&void 0!==e?e:t))}}),"function"==typeof o?(this.transport.addLog("Auto authentication enabled"),this._autoAuthenticate(o).subscribe()):this.transport.addLog("Auto authentication not enabled"),this.transport._autoToggleActionNotifications(this.selectedDevice$),this._focus$=this._subscribeWhileAuthenticated("focus"),this._calm$=this._subscribeWhileAuthenticated("calm"),this._accelerometer$=this._subscribeWhileAuthenticated("accelerometer"),this._brainwavesRaw$=this._subscribeWhileAuthenticated("raw"),this._brainwavesRawUnfiltered$=this._subscribeWhileAuthenticated("rawUnfiltered"),this._brainwavesPSD$=this._subscribeWhileAuthenticated("psd"),this._brainwavesPowerByBand$=this._subscribeWhileAuthenticated("powerByBand"),this._signalQuality$=this._subscribeWhileAuthenticated("signalQuality"),this._status$=this._subscribeWhileAuthenticated("status"),this._settings$=this._subscribeWhileAuthenticated("settings"),this._wifiNearbyNetworks$=this._subscribeWhileAuthenticated("wifiNearbyNetworks"),this._wifiConnections$=this._subscribeWhileAuthenticated("wifiConnections")}return a(e,[{key:"_autoAuthenticate",value:function(e){var r=this,n=(0,u.timer)(0,36e5).pipe((0,h.tap)(function(){r.transport.addLog("Auto authentication in progress...")}));return this.selectedDevice$.pipe((0,h.switchMap)(function(i){return(0,w.osHasBluetoothSupport)(i)?r.connection().pipe((0,h.switchMap)(function(t){return t===v.BLUETOOTH_CONNECTION.CONNECTED?n:c.EMPTY}),(0,h.switchMap)(function(){return o(r,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.isAuthenticated();case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}),(0,h.tap)(function(n){var i=t(n,1)[0];return o(r,void 0,void 0,regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i){t.next=8;break}return t.next=3,e();case 3:return r=t.sent,t.next=6,this.authenticate(r);case 6:t.next=9;break;case 8:this.transport.addLog("Already authenticated");case 9:case"end":return t.stop()}},t,this)}))})):c.EMPTY}))}},{key:"_hasBluetoothSupport",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function t(){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,(0,u.firstValueFrom)(this.selectedDevice$);case 2:return e=t.sent,t.abrupt("return",(0,w.osHasBluetoothSupport)(e));case 4:case"end":return t.stop()}},t,this)}))}},{key:"authenticate",value:function(e){return o(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._hasBluetoothSupport();case 2:if(r.sent){r.next=7;break}return n="authenticate method: The OS version does not support Bluetooth.",this.transport.addLog(n),r.abrupt("return",Promise.reject(n));case 7:return r.next=9,this.transport.writeCharacteristic("auth",e);case 9:return r.next=11,this.isAuthenticated();case 11:return i=r.sent,s=t(i,1),a=s[0],this.transport.addLog("Authentication ".concat(a?"succeeded":"failed")),this.isAuthenticated$.next(a),r.abrupt("return",i);case 16:case"end":return r.stop()}},r,this)}))}},{key:"isAuthenticated",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r,n,i,s;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.transport.readCharacteristic("auth",!0);case 2:return r=e.sent,n=t(r,2),i=n[0],s=n[1],this.isAuthenticated$.next(i),e.abrupt("return",[i,s]);case 8:case"end":return e.stop()}},e,this)}))}},{key:"scan",value:function(t){if(this.transport instanceof f.ReactNativeTransport)return this.transport.scan(t);if(this.transport instanceof d.WebBluetoothTransport)throw new Error("scan method is compatibly with the React Native transport only");throw new Error("unknown transport")}},{key:"connect",value:function(t){return this.transport instanceof f.ReactNativeTransport?this.transport.connect(t):this.transport instanceof d.WebBluetoothTransport?t?this.transport.connect(t):this.transport.connect():void 0}},{key:"disconnect",value:function(){return this.transport.disconnect()}},{key:"connection",value:function(){return this.transport.connection()}},{key:"logs",value:function(){return this.transport.logs$.asObservable()}},{key:"getDeviceId",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.transport.readCharacteristic("deviceId"));case 1:case"end":return t.stop()}},t,this)}))}},{key:"_withAuthentication",value:function(t){return o(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._hasBluetoothSupport();case 2:if(e.sent){e.next=7;break}return r="The OS version does not support Bluetooth.",this.transport.addLog(r),e.abrupt("return",Promise.reject(r));case 7:return e.next=9,(0,u.firstValueFrom)(this.isAuthenticated$);case 9:if(e.sent){e.next=14;break}return"Authentication required.",this.transport.addLog("Authentication required."),e.abrupt("return",Promise.reject("Authentication required."));case 14:return e.next=16,t();case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}},e,this)}))}},{key:"_subscribeWhileAuthenticated",value:function(t){var e=this;return this.selectedDevice$.pipe((0,h.switchMap)(function(r){return(0,w.osHasBluetoothSupport)(r)?e.isAuthenticated$.pipe((0,p.distinctUntilChanged)(),(0,h.switchMap)(function(r){return r?e.transport.subscribeToCharacteristic({characteristicName:t}):c.EMPTY})):c.EMPTY}),(0,h.share)())}},{key:"focus",value:function(){return this._focus$}},{key:"calm",value:function(){return this._calm$}},{key:"accelerometer",value:function(){return this._accelerometer$}},{key:"brainwaves",value:function(t){var e=this;switch(t){default:case"raw":return(0,u.defer)(function(){return e.getInfo()}).pipe((0,h.switchMap)(function(t){return e._brainwavesRaw$.pipe((0,l.csvBufferToEpoch)(t))}));case"rawUnfiltered":return(0,u.defer)(function(){return e.getInfo()}).pipe((0,h.switchMap)(function(t){return e._brainwavesRawUnfiltered$.pipe((0,l.csvBufferToEpoch)(t))}));case"psd":return this._brainwavesPSD$;case"powerByBand":return this._brainwavesPowerByBand$}}},{key:"signalQuality",value:function(){return this._signalQuality$}},{key:"addMarker",value:function(t){return o(this,void 0,void 0,regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.dispatchAction({action:"marker",command:"add",message:{timestamp:Date.now(),label:t}});case 2:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function t(){var e=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._withAuthentication(function(){return(0,u.firstValueFrom)(e.transport.subscribeToCharacteristic({characteristicName:"deviceInfo"}))});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"status",value:function(){return this._status$}},{key:"dispatchAction",value:function(t){return o(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._withAuthentication(function(){return r.transport.dispatchAction({characteristicName:"actions",action:t})});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"settings",value:function(){return this._settings$}},{key:"haptics",value:function(t){return this.dispatchAction({action:"haptics",command:"queue",responseRequired:!0,responseTimeout:4e3,message:{effects:t}})}},{key:"wifi",get:function(){var t=this;return{nearbyNetworks:function(){return t._wifiNearbyNetworks$},connections:function(){return t._wifiConnections$},connect:function(e,r){return e?t.dispatchAction({action:"wifi",command:"connect",responseRequired:!0,responseTimeout:12e4,message:{ssid:e,password:null!=r?r:null}}):Promise.reject("Missing ssid")},forgetConnection:function(e){return e?t.dispatchAction({action:"wifi",command:"forget-connection",responseRequired:!0,responseTimeout:15e3,message:{ssid:e}}):Promise.reject("Missing ssid")},reset:function(){return t.dispatchAction({action:"wifi",command:"reset",responseRequired:!0,responseTimeout:3e4,message:{respondOnSuccess:!0}})},speedTest:function(){return t.dispatchAction({action:"wifi",command:"speed-test",responseRequired:!0,responseTimeout:6e4})}}}}]),e}();exports.BluetoothClient=b;
659
659
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/csvBufferToEpoch":"WTrV","./types":"iwtf","./utils/osHasBluetoothSupport":"rH2Y"}],"TICO":[function(require,module,exports) {
660
660
  "use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),t=this&&this.__exportStar||function(t,r){for(var o in t)"default"===o||Object.prototype.hasOwnProperty.call(r,o)||e(r,t,o)};Object.defineProperty(exports,"__esModule",{value:!0}),t(require("./BluetoothClient"),exports),t(require("./web/WebBluetoothTransport"),exports),t(require("./react-native/ReactNativeTransport"),exports),t(require("./utils/osHasBluetoothSupport"),exports);
661
661
  },{"./BluetoothClient":"fihV","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/osHasBluetoothSupport":"rH2Y"}],"KQ4u":[function(require,module,exports) {
@@ -47210,6 +47210,23 @@ class BluetoothClient {
47210
47210
  }
47211
47211
  // Auto manage action notifications
47212
47212
  this.transport._autoToggleActionNotifications(this.selectedDevice$);
47213
+ // Multicast metrics (share)
47214
+ this._focus$ = this._subscribeWhileAuthenticated("focus");
47215
+ this._calm$ = this._subscribeWhileAuthenticated("calm");
47216
+ this._accelerometer$ = this._subscribeWhileAuthenticated("accelerometer");
47217
+ this._brainwavesRaw$ = this._subscribeWhileAuthenticated("raw");
47218
+ this._brainwavesRawUnfiltered$ =
47219
+ this._subscribeWhileAuthenticated("rawUnfiltered");
47220
+ this._brainwavesPSD$ = this._subscribeWhileAuthenticated("psd");
47221
+ this._brainwavesPowerByBand$ =
47222
+ this._subscribeWhileAuthenticated("powerByBand");
47223
+ this._signalQuality$ = this._subscribeWhileAuthenticated("signalQuality");
47224
+ this._status$ = this._subscribeWhileAuthenticated("status");
47225
+ this._settings$ = this._subscribeWhileAuthenticated("settings");
47226
+ this._wifiNearbyNetworks$ =
47227
+ this._subscribeWhileAuthenticated("wifiNearbyNetworks");
47228
+ this._wifiConnections$ =
47229
+ this._subscribeWhileAuthenticated("wifiConnections");
47213
47230
  }
47214
47231
  _autoAuthenticate(createBluetoothToken) {
47215
47232
  const REAUTHENTICATE_INTERVAL = 3600000; // 1 hour
@@ -47320,28 +47337,32 @@ class BluetoothClient {
47320
47337
  ? this.transport.subscribeToCharacteristic({
47321
47338
  characteristicName
47322
47339
  })
47323
- : EMPTY))));
47340
+ : EMPTY))), share());
47324
47341
  }
47325
47342
  focus() {
47326
- return this._subscribeWhileAuthenticated("focus");
47343
+ return this._focus$;
47327
47344
  }
47328
47345
  calm() {
47329
- return this._subscribeWhileAuthenticated("calm");
47346
+ return this._calm$;
47330
47347
  }
47331
47348
  accelerometer() {
47332
- return this._subscribeWhileAuthenticated("accelerometer");
47349
+ return this._accelerometer$;
47333
47350
  }
47334
47351
  brainwaves(label) {
47335
47352
  switch (label) {
47353
+ default:
47336
47354
  case "raw":
47355
+ return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRaw$.pipe(csvBufferToEpoch(deviceInfo))));
47337
47356
  case "rawUnfiltered":
47338
- return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._subscribeWhileAuthenticated(label).pipe(csvBufferToEpoch(deviceInfo))));
47339
- default:
47340
- return this._subscribeWhileAuthenticated(label);
47357
+ return defer(() => this.getInfo()).pipe(switchMap((deviceInfo) => this._brainwavesRawUnfiltered$.pipe(csvBufferToEpoch(deviceInfo))));
47358
+ case "psd":
47359
+ return this._brainwavesPSD$;
47360
+ case "powerByBand":
47361
+ return this._brainwavesPowerByBand$;
47341
47362
  }
47342
47363
  }
47343
47364
  signalQuality() {
47344
- return this._subscribeWhileAuthenticated("signalQuality");
47365
+ return this._signalQuality$;
47345
47366
  }
47346
47367
  addMarker(label) {
47347
47368
  return __awaiter$f(this, void 0, void 0, function* () {
@@ -47362,9 +47383,8 @@ class BluetoothClient {
47362
47383
  })));
47363
47384
  });
47364
47385
  }
47365
- // Tested
47366
47386
  status() {
47367
- return this._subscribeWhileAuthenticated("status");
47387
+ return this._status$;
47368
47388
  }
47369
47389
  dispatchAction(action) {
47370
47390
  return __awaiter$f(this, void 0, void 0, function* () {
@@ -47375,7 +47395,7 @@ class BluetoothClient {
47375
47395
  });
47376
47396
  }
47377
47397
  settings() {
47378
- return this._subscribeWhileAuthenticated("settings");
47398
+ return this._settings$;
47379
47399
  }
47380
47400
  haptics(effects) {
47381
47401
  const metric = "haptics";
@@ -47390,8 +47410,8 @@ class BluetoothClient {
47390
47410
  }
47391
47411
  get wifi() {
47392
47412
  return {
47393
- nearbyNetworks: () => this._subscribeWhileAuthenticated("wifiNearbyNetworks"),
47394
- connections: () => this._subscribeWhileAuthenticated("wifiConnections"),
47413
+ nearbyNetworks: () => this._wifiNearbyNetworks$,
47414
+ connections: () => this._wifiConnections$,
47395
47415
  connect: (ssid, password) => {
47396
47416
  if (!ssid) {
47397
47417
  return Promise.reject(`Missing ssid`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neurosity/sdk",
3
- "version": "6.0.0-next.12",
3
+ "version": "6.0.0",
4
4
  "description": "Neurosity SDK",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",