@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.
- package/dist/browser/neurosity.iife.js +33 -13
- package/dist/browser/neurosity.js +1 -1
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +12 -0
- package/dist/cjs/api/bluetooth/BluetoothClient.js +33 -13
- package/dist/electron/index.js +1 -1
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +12 -0
- package/dist/esm/api/bluetooth/BluetoothClient.js +34 -14
- package/dist/esm/neurosity.mjs +33 -13
- package/dist/examples/neurosity.iife.js +33 -13
- package/dist/examples/neurosity.js +1 -1
- package/dist/examples/neurosity.mjs +33 -13
- package/package.json +1 -1
|
@@ -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.
|
|
47346
|
+
return this._focus$;
|
|
47330
47347
|
}
|
|
47331
47348
|
calm() {
|
|
47332
|
-
return this.
|
|
47349
|
+
return this._calm$;
|
|
47333
47350
|
}
|
|
47334
47351
|
accelerometer() {
|
|
47335
|
-
return this.
|
|
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.
|
|
47342
|
-
|
|
47343
|
-
return this.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
47397
|
-
connections: () => this.
|
|
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) {
|