@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.
- package/dist/browser/neurosity.iife.js +83 -17
- package/dist/browser/neurosity.js +7 -7
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/Neurosity.d.ts +17 -1
- package/dist/cjs/Neurosity.js +26 -2
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +3 -1
- package/dist/cjs/api/bluetooth/BluetoothClient.js +9 -5
- package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +2 -2
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +3 -3
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +6 -4
- package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -2
- package/dist/cjs/api/bluetooth/utils/osHasBluetoothSupport.js +4 -2
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +3 -3
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +8 -4
- package/dist/cjs/api/index.d.ts +3 -1
- package/dist/cjs/api/index.js +4 -0
- package/dist/cjs/types/deviceInfo.d.ts +2 -1
- package/dist/cjs/utils/oauth.js +1 -0
- package/dist/electron/index.js +7 -7
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/Neurosity.d.ts +17 -1
- package/dist/esm/Neurosity.js +26 -2
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +3 -1
- package/dist/esm/api/bluetooth/BluetoothClient.js +10 -6
- package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +2 -2
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +3 -3
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +7 -5
- package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.d.ts +2 -2
- package/dist/esm/api/bluetooth/utils/osHasBluetoothSupport.js +4 -2
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +3 -3
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +9 -5
- package/dist/esm/api/index.d.ts +3 -1
- package/dist/esm/api/index.js +4 -0
- package/dist/esm/neurosity.mjs +83 -17
- package/dist/esm/types/deviceInfo.d.ts +2 -1
- package/dist/esm/utils/oauth.js +1 -0
- package/dist/examples/neurosity.iife.js +83 -17
- package/dist/examples/neurosity.js +7 -7
- package/dist/examples/neurosity.mjs +83 -17
- package/package.json +1 -1
|
@@ -524,7 +524,7 @@ var r=Array.isArray;function n(n){if(r(n))return t(n);var e=null,u="string"==typ
|
|
|
524
524
|
},{"rxjs":"Zr8e","rxjs/operators":"v3iE","fast-deep-equal":"jIGR","../types/status":"Ttuy"}],"qny3":[function(require,module,exports) {
|
|
525
525
|
"use strict";function r(r,i){return n(r)||e(r,i)||t()}function t(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function e(r,t){if(Symbol.iterator in Object(r)||"[object Arguments]"===Object.prototype.toString.call(r)){var e=[],n=!0,i=!1,o=void 0;try{for(var u,a=r[Symbol.iterator]();!(n=(u=a.next()).done)&&(e.push(u.value),!t||e.length!==t);n=!0);}catch(l){i=!0,o=l}finally{try{n||null==a.return||a.return()}finally{if(i)throw o}}return e}}function n(r){if(Array.isArray(r))return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.filterInternalKeys=void 0;var i=require("rxjs"),o=require("rxjs/operators");function u(){return(0,i.pipe)((0,o.map)(function(t){return t?Object.entries(t).reduce(function(t,e){var n=r(e,2),i=n[0],o=n[1];return i.startsWith("__")||(t[i]=o),t},{}):t}))}exports.filterInternalKeys=u;
|
|
526
526
|
},{"rxjs":"Zr8e","rxjs/operators":"v3iE"}],"LXvB":[function(require,module,exports) {
|
|
527
|
-
"use strict";function e(e,i){return n(e)||r(e,i)||t()}function t(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function r(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var r=[],n=!0,i=!1,s=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(c){i=!0,s=c}finally{try{n||null==a.return||a.return()}finally{if(i)throw s}}return r}}function n(e){if(Array.isArray(e))return e}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function u(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),e}var a=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,s){function u(e){try{c(n.next(e))}catch(t){s(t)}}function a(e){try{c(n.throw(e))}catch(t){s(t)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,a)}c((n=n.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CloudClient=exports.SERVER_TIMESTAMP=exports.createUser=exports.credentialWithLink=void 0;var c=require("rxjs"),o=require("rxjs"),f=require("rxjs/operators"),v=require("./firebase"),h=require("../timesync"),p=require("../subscriptions/SubscriptionManager"),d=require("../utils/heartbeat"),l=require("../utils/filterInternalKeys"),b=require("./firebase");Object.defineProperty(exports,"credentialWithLink",{enumerable:!0,get:function(){return b.credentialWithLink}}),Object.defineProperty(exports,"createUser",{enumerable:!0,get:function(){return b.createUser}}),Object.defineProperty(exports,"SERVER_TIMESTAMP",{enumerable:!0,get:function(){return b.SERVER_TIMESTAMP}});var m=function(){function t(e){var r=this;i(this,t),this._selectedDevice=new c.ReplaySubject(1),this.options=e,this.subscriptionManager=new p.SubscriptionManager,this.firebaseApp=new v.FirebaseApp(e),this.firebaseUser=new v.FirebaseUser(this.firebaseApp),this._selectedDevice.next(void 0),this.status$=(0,d.heartbeatAwareStatus)(this.observeNamespace("status").pipe((0,f.share)())).pipe((0,l.filterInternalKeys)(),(0,f.shareReplay)(1)),this.firebaseUser.onAuthStateChanged().subscribe(function(e){r.user=e}),this.firebaseUser.onUserClaimsChange().subscribe(function(e){r.userClaims=e}),this.onDeviceChange().subscribe(function(e){r.firebaseDevice&&r.firebaseDevice.disconnect(),e&&(r.firebaseDevice=new v.FirebaseDevice({deviceId:e.deviceId,firebaseApp:r.firebaseApp,dependencies:{subscriptionManager:r.subscriptionManager}}),r.options.timesync&&(r.timesync=new h.Timesync({status$:r.status(),getTimesync:r.firebaseDevice.getTimesync.bind(r.firebaseDevice)})))})}return u(t,[{key:"onDeviceChange",value:function(){return this._selectedDevice.asObservable().pipe((0,f.filter)(function(e){return void 0!==e}))}},{key:"setAutoSelectedDevice",value:function(){return a(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.options.deviceId){e.next=4;break}return e.next=3,this.selectDevice(function(e){return e.find(function(e){return e.deviceId===t.options.deviceId})});case 3:return e.abrupt("return",e.sent);case 4:if(this.options.deviceId||!this.options.autoSelectDevice){e.next=8;break}return e.next=7,this.selectDevice(function(e){return e[0]});case 7:return e.abrupt("return",e.sent);case 8:return e.abrupt("return",null);case 9:case"end":return e.stop()}},e,this)}))}},{key:"dispatchAction",value:function(e){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.next=2,this.firebaseDevice.dispatchAction(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"disconnect",value:function(){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.abrupt("return",this.firebaseApp.disconnect());case 1:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){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.firebaseDevice.getInfo();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"login",value:function(e){return a(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.user){t.next=2;break}return t.abrupt("return",Promise.reject("Already logged in."));case 2:return t.next=4,this.firebaseUser.login(e);case 4:return r=t.sent,t.next=7,this.setAutoSelectedDevice();case 7:return n=t.sent,t.abrupt("return",Object.assign(Object.assign({},r),{selectedDevice:n}));case 9:case"end":return t.stop()}},t,this)}))}},{key:"logout",value:function(){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 this.firebaseDevice&&this.firebaseDevice.disconnect(),e.next=3,this.firebaseUser.logout();case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)}))}},{key:"onAuthStateChanged",value:function(){var e=this;return this.firebaseUser.onAuthStateChanged().pipe((0,f.switchMap)(function(t){return a(e,void 0,void 0,regeneratorRuntime.mark(function e(){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return",null);case 2:if(!this.didSelectDevice()){e.next=8;break}return e.next=5,this.getSelectedDevice();case 5:e.t0=e.sent,e.next=11;break;case 8:return e.next=10,this.setAutoSelectedDevice();case 10:e.t0=e.sent;case 11:return r=e.t0,e.abrupt("return",Object.assign(Object.assign({},t),{selectedDevice:r}));case 13:case"end":return e.stop()}},e,this)}))}))}},{key:"getDevices",value:function(){return this.firebaseUser.getDevices()}},{key:"addDevice",value:function(e){return this.firebaseUser.addDevice(e)}},{key:"removeDevice",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s,u,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.firebaseUser.removeDevice(t).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 2:if(n=r.sent,i=e(n,2),s=i[0],u=i[1],!s){r.next=8;break}return r.abrupt("return",Promise.reject(u));case 8:return r.next=10,this.getSelectedDevice();case 10:(null==(a=r.sent)?void 0:a.deviceId)===t&&this._selectedDevice.next(null);case 12:case"end":return r.stop()}},r,this)}))}},{key:"transferDevice",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s,u,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.firebaseUser.transferDevice(t).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 2:if(n=r.sent,i=e(n,2),s=i[0],u=i[1],!s){r.next=8;break}return r.abrupt("return",Promise.reject(u));case 8:return r.next=10,this.getSelectedDevice();case 10:(null==(a=r.sent)?void 0:a.deviceId)===t.deviceId&&this._selectedDevice.next(null);case 12:case"end":return r.stop()}},r,this)}))}},{key:"onUserDevicesChange",value:function(){return this.firebaseUser.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.firebaseUser.onUserClaimsChange()}},{key:"didSelectDevice",value:function(){return a(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSelectedDevice();case 2:return t=e.sent,e.abrupt("return",!!t);case 4:case"end":return e.stop()}},e,this)}))}},{key:"selectDevice",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.getDevices();case 2:if(n=r.sent){r.next=5;break}return r.abrupt("return",Promise.reject("Did not find any devices for this user. Make sure your device is claimed by your Neurosity account."));case 5:if(i=function(r){return r.find(function(r){if(!Array.isArray(t))return!1;var n=e(t,2),i=n[0],s=n[1];return JSON.stringify(null==r?void 0:r[i])===JSON.stringify(s)})},s="function"==typeof t?t(n):i(n)){r.next=9;break}return r.abrupt("return",Promise.reject("A device was not provided. Try returning a device from the devicesList provided in the callback."));case 9:return r.next=11,this.firebaseUser.hasDevicePermission(s.deviceId);case 11:if(r.sent){r.next=14;break}return r.abrupt("return",Promise.reject("Rejected device access due to permissions."));case 14:return this._selectedDevice.next(s),r.abrupt("return",s);case 16:case"end":return r.stop()}},r,this)}))}},{key:"getSelectedDevice",value:function(){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,(0,o.firstValueFrom)(this._selectedDevice);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"status",value:function(){return this.status$}},{key:"observeNamespace",value:function(e){var t=this;return this.onDeviceChange().pipe((0,f.switchMap)(function(r){return r?(0,o.fromEventPattern)(function(r){return t.firebaseDevice.onNamespace(e,r)},function(r){return t.firebaseDevice.offNamespace(e,r)}):c.EMPTY}))}},{key:"onceNamespace",value:function(e){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.next=2,this.firebaseDevice.onceNamespace(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"createAccount",value:function(e){return this.firebaseUser.createAccount(e)}},{key:"deleteAccount",value:function(){return this.firebaseUser.deleteAccount()}},{key:"createBluetoothToken",value:function(){return this.firebaseDevice.createBluetoothToken()}},{key:"createCustomToken",value:function(){return this.firebaseUser.createCustomToken()}},{key:"removeOAuthAccess",value:function(){return this.firebaseUser.removeOAuthAccess()}},{key:"onUserExperiments",value:function(){return this.firebaseUser.onUserExperiments()}},{key:"deleteUserExperiment",value:function(e){return this.firebaseUser.deleteUserExperiment(e)}},{key:"getTimesyncOffset",value:function(){return this.timesync.offset}},{key:"changeSettings",value:function(e){return this.firebaseDevice.changeSettings(e)}},{key:"goOffline",value:function(){this.firebaseApp.goOffline()}},{key:"goOnline",value:function(){this.firebaseApp.goOnline()}},{key:"__getApp",value:function(){return this.firebaseApp.app}},{key:"actions",get:function(){var e=this;return{dispatch:function(t){return e.firebaseDevice.dispatchAction(t)}}}},{key:"metrics",get:function(){var e=this;return{next:function(t,r){e.firebaseDevice.nextMetric(t,r)},on:function(t,r){return e.firebaseDevice.onMetric(t,r)},subscribe:function(t){var r=e.firebaseDevice.subscribeToMetric(t);return e.subscriptionManager.add(r),r},unsubscribe:function(t,r){e.subscriptionManager.remove(t),e.firebaseDevice.unsubscribeFromMetric(t),e.firebaseDevice.removeMetricListener(t,r)}}}},{key:"skills",get:function(){var e=this;return{get:function(t){return a(e,void 0,void 0,regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.firebaseDevice.getSkill(t));case 1:case"end":return e.stop()}},e,this)}))}}}},{key:"timestamp",get:function(){return this.options.timesync?this.timesync.timestamp:Date.now()}}]),t}();exports.CloudClient=m;
|
|
527
|
+
"use strict";function e(e,i){return n(e)||r(e,i)||t()}function t(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function r(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var r=[],n=!0,i=!1,s=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(c){i=!0,s=c}finally{try{n||null==a.return||a.return()}finally{if(i)throw s}}return r}}function n(e){if(Array.isArray(e))return e}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function u(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),e}var a=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,s){function u(e){try{c(n.next(e))}catch(t){s(t)}}function a(e){try{c(n.throw(e))}catch(t){s(t)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,a)}c((n=n.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CloudClient=exports.SERVER_TIMESTAMP=exports.createUser=exports.credentialWithLink=void 0;var c=require("rxjs"),o=require("rxjs"),f=require("rxjs/operators"),v=require("./firebase"),h=require("../timesync"),p=require("../subscriptions/SubscriptionManager"),d=require("../utils/heartbeat"),l=require("../utils/filterInternalKeys"),b=require("./firebase");Object.defineProperty(exports,"credentialWithLink",{enumerable:!0,get:function(){return b.credentialWithLink}}),Object.defineProperty(exports,"createUser",{enumerable:!0,get:function(){return b.createUser}}),Object.defineProperty(exports,"SERVER_TIMESTAMP",{enumerable:!0,get:function(){return b.SERVER_TIMESTAMP}});var m=function(){function t(e){var r=this;i(this,t),this._selectedDevice=new c.ReplaySubject(1),this.options=e,this.subscriptionManager=new p.SubscriptionManager,this.firebaseApp=new v.FirebaseApp(e),this.firebaseUser=new v.FirebaseUser(this.firebaseApp),this._selectedDevice.next(void 0),this.status$=(0,d.heartbeatAwareStatus)(this.observeNamespace("status").pipe((0,f.share)())).pipe((0,l.filterInternalKeys)(),(0,f.shareReplay)(1)),this.osVersion$=this.observeNamespace("info/osVersion").pipe((0,f.shareReplay)(1)),this.firebaseUser.onAuthStateChanged().subscribe(function(e){r.user=e}),this.firebaseUser.onUserClaimsChange().subscribe(function(e){r.userClaims=e}),this.onDeviceChange().subscribe(function(e){r.firebaseDevice&&r.firebaseDevice.disconnect(),e&&(r.firebaseDevice=new v.FirebaseDevice({deviceId:e.deviceId,firebaseApp:r.firebaseApp,dependencies:{subscriptionManager:r.subscriptionManager}}),r.options.timesync&&(r.timesync=new h.Timesync({status$:r.status(),getTimesync:r.firebaseDevice.getTimesync.bind(r.firebaseDevice)})))})}return u(t,[{key:"onDeviceChange",value:function(){return this._selectedDevice.asObservable().pipe((0,f.filter)(function(e){return void 0!==e}))}},{key:"osVersion",value:function(){return this.osVersion$}},{key:"setAutoSelectedDevice",value:function(){return a(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.options.deviceId){e.next=4;break}return e.next=3,this.selectDevice(function(e){return e.find(function(e){return e.deviceId===t.options.deviceId})});case 3:return e.abrupt("return",e.sent);case 4:if(this.options.deviceId||!this.options.autoSelectDevice){e.next=8;break}return e.next=7,this.selectDevice(function(e){return e[0]});case 7:return e.abrupt("return",e.sent);case 8:return e.abrupt("return",null);case 9:case"end":return e.stop()}},e,this)}))}},{key:"dispatchAction",value:function(e){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.next=2,this.firebaseDevice.dispatchAction(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"disconnect",value:function(){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.abrupt("return",this.firebaseApp.disconnect());case 1:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){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.firebaseDevice.getInfo();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"login",value:function(e){return a(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.user){t.next=2;break}return t.abrupt("return",Promise.reject("Already logged in."));case 2:return t.next=4,this.firebaseUser.login(e);case 4:return r=t.sent,t.next=7,this.setAutoSelectedDevice();case 7:return n=t.sent,t.abrupt("return",Object.assign(Object.assign({},r),{selectedDevice:n}));case 9:case"end":return t.stop()}},t,this)}))}},{key:"logout",value:function(){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 this.firebaseDevice&&this.firebaseDevice.disconnect(),e.next=3,this.firebaseUser.logout();case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)}))}},{key:"onAuthStateChanged",value:function(){var e=this;return this.firebaseUser.onAuthStateChanged().pipe((0,f.switchMap)(function(t){return a(e,void 0,void 0,regeneratorRuntime.mark(function e(){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return",null);case 2:if(!this.didSelectDevice()){e.next=8;break}return e.next=5,this.getSelectedDevice();case 5:e.t0=e.sent,e.next=11;break;case 8:return e.next=10,this.setAutoSelectedDevice();case 10:e.t0=e.sent;case 11:return r=e.t0,e.abrupt("return",Object.assign(Object.assign({},t),{selectedDevice:r}));case 13:case"end":return e.stop()}},e,this)}))}))}},{key:"getDevices",value:function(){return this.firebaseUser.getDevices()}},{key:"addDevice",value:function(e){return this.firebaseUser.addDevice(e)}},{key:"removeDevice",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s,u,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.firebaseUser.removeDevice(t).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 2:if(n=r.sent,i=e(n,2),s=i[0],u=i[1],!s){r.next=8;break}return r.abrupt("return",Promise.reject(u));case 8:return r.next=10,this.getSelectedDevice();case 10:(null==(a=r.sent)?void 0:a.deviceId)===t&&this._selectedDevice.next(null);case 12:case"end":return r.stop()}},r,this)}))}},{key:"transferDevice",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s,u,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.firebaseUser.transferDevice(t).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 2:if(n=r.sent,i=e(n,2),s=i[0],u=i[1],!s){r.next=8;break}return r.abrupt("return",Promise.reject(u));case 8:return r.next=10,this.getSelectedDevice();case 10:(null==(a=r.sent)?void 0:a.deviceId)===t.deviceId&&this._selectedDevice.next(null);case 12:case"end":return r.stop()}},r,this)}))}},{key:"onUserDevicesChange",value:function(){return this.firebaseUser.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.firebaseUser.onUserClaimsChange()}},{key:"didSelectDevice",value:function(){return a(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSelectedDevice();case 2:return t=e.sent,e.abrupt("return",!!t);case 4:case"end":return e.stop()}},e,this)}))}},{key:"selectDevice",value:function(t){return a(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.getDevices();case 2:if(n=r.sent){r.next=5;break}return r.abrupt("return",Promise.reject("Did not find any devices for this user. Make sure your device is claimed by your Neurosity account."));case 5:if(i=function(r){return r.find(function(r){if(!Array.isArray(t))return!1;var n=e(t,2),i=n[0],s=n[1];return JSON.stringify(null==r?void 0:r[i])===JSON.stringify(s)})},s="function"==typeof t?t(n):i(n)){r.next=9;break}return r.abrupt("return",Promise.reject("A device was not provided. Try returning a device from the devicesList provided in the callback."));case 9:return r.next=11,this.firebaseUser.hasDevicePermission(s.deviceId);case 11:if(r.sent){r.next=14;break}return r.abrupt("return",Promise.reject("Rejected device access due to permissions."));case 14:return this._selectedDevice.next(s),r.abrupt("return",s);case 16:case"end":return r.stop()}},r,this)}))}},{key:"getSelectedDevice",value:function(){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,(0,o.firstValueFrom)(this._selectedDevice);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"status",value:function(){return this.status$}},{key:"observeNamespace",value:function(e){var t=this;return this.onDeviceChange().pipe((0,f.switchMap)(function(r){return r?(0,o.fromEventPattern)(function(r){return t.firebaseDevice.onNamespace(e,r)},function(r){return t.firebaseDevice.offNamespace(e,r)}):c.EMPTY}))}},{key:"onceNamespace",value:function(e){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.next=2,this.firebaseDevice.onceNamespace(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"createAccount",value:function(e){return this.firebaseUser.createAccount(e)}},{key:"deleteAccount",value:function(){return this.firebaseUser.deleteAccount()}},{key:"createBluetoothToken",value:function(){return this.firebaseDevice.createBluetoothToken()}},{key:"createCustomToken",value:function(){return this.firebaseUser.createCustomToken()}},{key:"removeOAuthAccess",value:function(){return this.firebaseUser.removeOAuthAccess()}},{key:"onUserExperiments",value:function(){return this.firebaseUser.onUserExperiments()}},{key:"deleteUserExperiment",value:function(e){return this.firebaseUser.deleteUserExperiment(e)}},{key:"getTimesyncOffset",value:function(){return this.timesync.offset}},{key:"changeSettings",value:function(e){return this.firebaseDevice.changeSettings(e)}},{key:"goOffline",value:function(){this.firebaseApp.goOffline()}},{key:"goOnline",value:function(){this.firebaseApp.goOnline()}},{key:"__getApp",value:function(){return this.firebaseApp.app}},{key:"actions",get:function(){var e=this;return{dispatch:function(t){return e.firebaseDevice.dispatchAction(t)}}}},{key:"metrics",get:function(){var e=this;return{next:function(t,r){e.firebaseDevice.nextMetric(t,r)},on:function(t,r){return e.firebaseDevice.onMetric(t,r)},subscribe:function(t){var r=e.firebaseDevice.subscribeToMetric(t);return e.subscriptionManager.add(r),r},unsubscribe:function(t,r){e.subscriptionManager.remove(t),e.firebaseDevice.unsubscribeFromMetric(t),e.firebaseDevice.removeMetricListener(t,r)}}}},{key:"skills",get:function(){var e=this;return{get:function(t){return a(e,void 0,void 0,regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.firebaseDevice.getSkill(t));case 1:case"end":return e.stop()}},e,this)}))}}}},{key:"timestamp",get:function(){return this.options.timesync?this.timesync.timestamp:Date.now()}}]),t}();exports.CloudClient=m;
|
|
528
528
|
},{"rxjs":"Zr8e","rxjs/operators":"v3iE","./firebase":"kM30","../timesync":"CXqr","../subscriptions/SubscriptionManager":"BX8M","../utils/heartbeat":"ImaE","../utils/filterInternalKeys":"qny3"}],"rekm":[function(require,module,exports) {
|
|
529
529
|
"use strict";var t,o;Object.defineProperty(exports,"__esModule",{value:!0}),exports.STREAMING_MODE=exports.STREAMING_TYPE=void 0,function(t){t.WIFI="wifi",t.BLUETOOTH="bluetooth"}(t=exports.STREAMING_TYPE||(exports.STREAMING_TYPE={})),function(t){t.WIFI_ONLY="wifi-only",t.WIFI_WITH_BLUETOOTH_FALLBACK="wifi-with-bluetooth-fallback",t.BLUETOOTH_WITH_WIFI_FALLBACK="bluetooth-with-wifi-fallback"}(o=exports.STREAMING_MODE||(exports.STREAMING_MODE={}));
|
|
530
530
|
},{}],"A5u5":[function(require,module,exports) {
|
|
@@ -540,7 +540,7 @@ var r=Array.isArray;function n(n){if(r(n))return t(n);var e=null,u="string"==typ
|
|
|
540
540
|
},{}],"lLai":[function(require,module,exports) {
|
|
541
541
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.buzz4_40=exports.buzz3_60=exports.buzz2_80=exports.buzz1_100=exports.longDoubleSharpTick3_60=exports.longDoubleSharpTick2_80=exports.longDoubleSharpTick1_100=exports.longDoubleSharpClickMedium3_60=exports.longDoubleSharpClickMedium2_80=exports.longDoubleSharpClickMedium1_100=exports.longDoubleSharpClickStrong4_30=exports.longDoubleSharpClickStrong3_60=exports.longDoubleSharpClickStrong2_80=exports.longDoubleSharpClickStrong1_100=exports.shortDoubleSharpTick3_60=exports.shortDoubleSharpTick2_80=exports.shortDoubleSharpTick1_100=exports.shortDoubleClickMedium3_60=exports.shortDoubleClickMedium2_80=exports.shortDoubleClickMedium1_100=exports.shortDoubleClickStrong4_30=exports.shortDoubleClickStrong3_60=exports.shortDoubleClickStrong2_80=exports.shortDoubleClickStrong1_100=exports.sharpTick3_60=exports.sharpTick2_80=exports.sharpTick1_100=exports.mediumClick3_60=exports.mediumClick2_80=exports.mediumClick1_100=exports.strongClick4_30=exports.strongClick3_60=exports.strongClick2_80=exports.strongClick1_100=exports.alert1000ms=exports.alert750ms=exports.strongBuzz100=exports.softFuzz60=exports.tripleClick100=exports.doubleClick60=exports.doubleClick100=exports.softBump30=exports.softBump60=exports.softBump100=exports.sharpClick30=exports.sharpClick60=exports.sharpClick100=exports.strongClick30=exports.strongClick60=exports.strongClick100=void 0,exports.transitionRampDownLongSharp1_50_to_0=exports.transitionRampDownShortSmooth2_50_to_0=exports.transitionRampDownShortSmooth1_50_to_0=exports.transitionRampDownMediumSmooth2_50_to_0=exports.transitionRampDownMediumSmooth1_50_to_0=exports.transitionRampDownLongSmooth2_50_to_0=exports.transitionRampDownLongSmooth1_50_to_0=exports.transitionRampUpShortSharp2_0_to_100=exports.transitionRampUpShortSharp1_0_to_100=exports.transitionRampUpMediumSharp2_0_to_100=exports.transitionRampUpMediumSharp1_0_to_100=exports.transitionRampUpLongSharp2_0_to_100=exports.transitionRampUpLongSharp1_0_to_100=exports.transitionRampUpShortSmooth2_0_to_100=exports.transitionRampUpShortSmooth1_0_to_100=exports.transitionRampUpMediumSmooth2_0_to_100=exports.transitionRampUpMediumSmooth1_0_to_100=exports.transitionRampUpLongSmooth2_0_to_100=exports.transitionRampUpLongSmooth1_0_to_100=exports.transitionRampDownShortSharp2_100_to_0=exports.transitionRampDownShortSharp1_100_to_0=exports.transitionRampDownLongMedium2_100_to_0=exports.transitionRampDownLongMedium1_100_to_0=exports.transitionRampDownLongSharp2_100_to_0=exports.transitionRampDownLongSharp1_100_to_0=exports.transitionRampDownShortSmooth2_100_to_0=exports.transitionRampDownShortSmooth1_100_to_0=exports.transitionRampDownMediumSmooth2_100_to_0=exports.transitionRampDownMediumSmooth1_100_to_0=exports.transitionRampDownLongSmooth2_100_to_0=exports.transitionRampDownLongSmooth1_100_to_0=exports.transistionHum6_10=exports.transistionHum5_20=exports.transistionHum4_40=exports.transistionHum3_60=exports.transistionHum2_80=exports.transistionHum1_100=exports.transistionClick6_10=exports.transistionClick5_20=exports.transistionClick4_40=exports.transistionClick3_60=exports.transistionClick2_80=exports.transistionClick1_100=exports.pulsingSharp2_60=exports.pulsingSharp1_100=exports.pulsingMedium2_60=exports.pulsingMedium1_100=exports.pulsingStong2_60=exports.pulsingStong1_100=exports.buzz5_20=void 0,exports.smoothHum5_10=exports.smoothHum4_20=exports.smoothHum3_30=exports.smoothHum2_40=exports.smoothHum1_50=exports.longBuzzForProgrammaticStopping_100=exports.transitionRampUpShortSharp2_0_to_50=exports.transitionRampUpShortSharp1_0_to_50=exports.transitionRampUpMediumSharp2_0_to_50=exports.transitionRampUpMediumSharp1_0_to_50=exports.transitionRampUpLongSharp2_0_to_50=exports.transitionRampUpLongSharp1_0_to_50=exports.transitionRampUpShortSmooth2_0_to_50=exports.transitionRampUpShortSmooth1_0_to_50=exports.transitionRampUpMediumSmooth2_0_to_50=exports.transitionRampUpMediumSmooth1_0_to_50=exports.transitionRampUpLongSmooth2_0_to_50=exports.transitionRampUpLongSmooth1_0_to_50=exports.transitionRampDownShortSharp2_50_to_0=exports.transitionRampDownShortSharp1_50_to_0=exports.transitionRampDownMediumSharp2_50_to_0=exports.transitionRampDownMediumSharp1_50_to_0=exports.transitionRampDownLongSharp2_50_to_0=void 0,exports.strongClick100="strongClick100",exports.strongClick60="strongClick60",exports.strongClick30="strongClick30",exports.sharpClick100="sharpClick100",exports.sharpClick60="sharpClick60",exports.sharpClick30="sharpClick30",exports.softBump100="softBump100",exports.softBump60="softBump60",exports.softBump30="softBump30",exports.doubleClick100="doubleClick100",exports.doubleClick60="doubleClick60",exports.tripleClick100="tripleClick100",exports.softFuzz60="softFuzz60",exports.strongBuzz100="strongBuzz100",exports.alert750ms="alert750ms",exports.alert1000ms="alert1000ms",exports.strongClick1_100="strongClick1_100",exports.strongClick2_80="strongClick2_80",exports.strongClick3_60="strongClick3_60",exports.strongClick4_30="strongClick4_30",exports.mediumClick1_100="mediumClick1_100",exports.mediumClick2_80="mediumClick2_80",exports.mediumClick3_60="mediumClick3_60",exports.sharpTick1_100="sharpTick1_100",exports.sharpTick2_80="sharpTick2_80",exports.sharpTick3_60="sharpTick3_60",exports.shortDoubleClickStrong1_100="shortDoubleClickStrong1_100",exports.shortDoubleClickStrong2_80="shortDoubleClickStrong2_80",exports.shortDoubleClickStrong3_60="shortDoubleClickStrong3_60",exports.shortDoubleClickStrong4_30="shortDoubleClickStrong4_30",exports.shortDoubleClickMedium1_100="shortDoubleClickMedium1_100",exports.shortDoubleClickMedium2_80="shortDoubleClickMedium2_80",exports.shortDoubleClickMedium3_60="shortDoubleClickMedium3_60",exports.shortDoubleSharpTick1_100="shortDoubleSharpTick1_100",exports.shortDoubleSharpTick2_80="shortDoubleSharpTick2_80",exports.shortDoubleSharpTick3_60="shortDoubleSharpTick3_60",exports.longDoubleSharpClickStrong1_100="longDoubleSharpClickStrong1_100",exports.longDoubleSharpClickStrong2_80="longDoubleSharpClickStrong2_80",exports.longDoubleSharpClickStrong3_60="longDoubleSharpClickStrong3_60",exports.longDoubleSharpClickStrong4_30="longDoubleSharpClickStrong4_30",exports.longDoubleSharpClickMedium1_100="longDoubleSharpClickMedium1_100",exports.longDoubleSharpClickMedium2_80="longDoubleSharpClickMedium2_80",exports.longDoubleSharpClickMedium3_60="longDoubleSharpClickMedium3_60",exports.longDoubleSharpTick1_100="longDoubleSharpTick1_100",exports.longDoubleSharpTick2_80="longDoubleSharpTick2_80",exports.longDoubleSharpTick3_60="longDoubleSharpTick3_60",exports.buzz1_100="buzz1_100",exports.buzz2_80="buzz2_80",exports.buzz3_60="buzz3_60",exports.buzz4_40="buzz4_40",exports.buzz5_20="buzz5_20",exports.pulsingStong1_100="pulsingStong1_100",exports.pulsingStong2_60="pulsingStong2_60",exports.pulsingMedium1_100="pulsingMedium1_100",exports.pulsingMedium2_60="pulsingMedium2_60",exports.pulsingSharp1_100="pulsingSharp1_100",exports.pulsingSharp2_60="pulsingSharp2_60",exports.transistionClick1_100="transistionClick1_100",exports.transistionClick2_80="transistionClick2_80",exports.transistionClick3_60="transistionClick3_60",exports.transistionClick4_40="transistionClick4_40",exports.transistionClick5_20="transistionClick5_20",exports.transistionClick6_10="transistionClick6_10",exports.transistionHum1_100="transistionHum1_100",exports.transistionHum2_80="transistionHum2_80",exports.transistionHum3_60="transistionHum3_60",exports.transistionHum4_40="transistionHum4_40",exports.transistionHum5_20="transistionHum5_20",exports.transistionHum6_10="transistionHum6_10",exports.transitionRampDownLongSmooth1_100_to_0="transitionRampDownLongSmooth1_100_to_0",exports.transitionRampDownLongSmooth2_100_to_0="transitionRampDownLongSmooth2_100_to_0",exports.transitionRampDownMediumSmooth1_100_to_0="transitionRampDownMediumSmooth1_100_to_0",exports.transitionRampDownMediumSmooth2_100_to_0="transitionRampDownMediumSmooth2_100_to_0",exports.transitionRampDownShortSmooth1_100_to_0="transitionRampDownShortSmooth1_100_to_0",exports.transitionRampDownShortSmooth2_100_to_0="transitionRampDownShortSmooth2_100_to_0",exports.transitionRampDownLongSharp1_100_to_0="transitionRampDownLongSharp1_100_to_0",exports.transitionRampDownLongSharp2_100_to_0="transitionRampDownLongSharp2_100_to_0",exports.transitionRampDownLongMedium1_100_to_0="transitionRampDownLongMedium1_100_to_0",exports.transitionRampDownLongMedium2_100_to_0="transitionRampDownLongMedium2_100_to_0",exports.transitionRampDownShortSharp1_100_to_0="transitionRampDownShortSharp1_100_to_0",exports.transitionRampDownShortSharp2_100_to_0="transitionRampDownShortSharp2_100_to_0",exports.transitionRampUpLongSmooth1_0_to_100="transitionRampUpLongSmooth1_0_to_100",exports.transitionRampUpLongSmooth2_0_to_100="transitionRampUpLongSmooth2_0_to_100",exports.transitionRampUpMediumSmooth1_0_to_100="transitionRampUpMediumSmooth1_0_to_100",exports.transitionRampUpMediumSmooth2_0_to_100="transitionRampUpMediumSmooth2_0_to_100",exports.transitionRampUpShortSmooth1_0_to_100="transitionRampUpShortSmooth1_0_to_100",exports.transitionRampUpShortSmooth2_0_to_100="transitionRampUpShortSmooth2_0_to_100",exports.transitionRampUpLongSharp1_0_to_100="transitionRampUpLongSharp1_0_to_100",exports.transitionRampUpLongSharp2_0_to_100="transitionRampUpLongSharp2_0_to_100",exports.transitionRampUpMediumSharp1_0_to_100="transitionRampUpMediumSharp1_0_to_100",exports.transitionRampUpMediumSharp2_0_to_100="transitionRampUpMediumSharp2_0_to_100",exports.transitionRampUpShortSharp1_0_to_100="transitionRampUpShortSharp1_0_to_100",exports.transitionRampUpShortSharp2_0_to_100="transitionRampUpShortSharp2_0_to_100",exports.transitionRampDownLongSmooth1_50_to_0="transitionRampDownLongSmooth1_50_to_0",exports.transitionRampDownLongSmooth2_50_to_0="transitionRampDownLongSmooth2_50_to_0",exports.transitionRampDownMediumSmooth1_50_to_0="transitionRampDownMediumSmooth1_50_to_0",exports.transitionRampDownMediumSmooth2_50_to_0="transitionRampDownMediumSmooth2_50_to_0",exports.transitionRampDownShortSmooth1_50_to_0="transitionRampDownShortSmooth1_50_to_0",exports.transitionRampDownShortSmooth2_50_to_0="transitionRampDownShortSmooth2_50_to_0",exports.transitionRampDownLongSharp1_50_to_0="transitionRampDownLongSharp1_50_to_0",exports.transitionRampDownLongSharp2_50_to_0="transitionRampDownLongSharp2_50_to_0",exports.transitionRampDownMediumSharp1_50_to_0="transitionRampDownMediumSharp1_50_to_0",exports.transitionRampDownMediumSharp2_50_to_0="transitionRampDownMediumSharp2_50_to_0",exports.transitionRampDownShortSharp1_50_to_0="transitionRampDownShortSharp1_50_to_0",exports.transitionRampDownShortSharp2_50_to_0="transitionRampDownShortSharp2_50_to_0",exports.transitionRampUpLongSmooth1_0_to_50="transitionRampUpLongSmooth1_0_to_50",exports.transitionRampUpLongSmooth2_0_to_50="transitionRampUpLongSmooth2_0_to_50",exports.transitionRampUpMediumSmooth1_0_to_50="transitionRampUpMediumSmooth1_0_to_50",exports.transitionRampUpMediumSmooth2_0_to_50="transitionRampUpMediumSmooth2_0_to_50",exports.transitionRampUpShortSmooth1_0_to_50="transitionRampUpShortSmooth1_0_to_50",exports.transitionRampUpShortSmooth2_0_to_50="transitionRampUpShortSmooth2_0_to_50",exports.transitionRampUpLongSharp1_0_to_50="transitionRampUpLongSharp1_0_to_50",exports.transitionRampUpLongSharp2_0_to_50="transitionRampUpLongSharp2_0_to_50",exports.transitionRampUpMediumSharp1_0_to_50="transitionRampUpMediumSharp1_0_to_50",exports.transitionRampUpMediumSharp2_0_to_50="transitionRampUpMediumSharp2_0_to_50",exports.transitionRampUpShortSharp1_0_to_50="transitionRampUpShortSharp1_0_to_50",exports.transitionRampUpShortSharp2_0_to_50="transitionRampUpShortSharp2_0_to_50",exports.longBuzzForProgrammaticStopping_100="longBuzzForProgrammaticStopping_100",exports.smoothHum1_50="smoothHum1_50",exports.smoothHum2_40="smoothHum2_40",exports.smoothHum3_30="smoothHum3_30",exports.smoothHum4_20="smoothHum4_20",exports.smoothHum5_10="smoothHum5_10";
|
|
542
542
|
},{}],"xIH5":[function(require,module,exports) {
|
|
543
|
-
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,i,r){void 0===r&&(r=i);var n=Object.getOwnPropertyDescriptor(t,i);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,r,n)}:function(e,t,i,r){void 0===r&&(r=i),e[r]=t[i]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var r={};if(null!=i)for(var n in i)"default"!==n&&Object.prototype.hasOwnProperty.call(i,n)&&e(r,i,n);return t(r,i),r};Object.defineProperty(exports,"__esModule",{value:!0}),exports.validateOAuthScopeForFunctionName=exports.validateOAuthScopeForAction=void 0;var r=i(require("../utils/errors")),n={"marker/add":"write:brainwave-markers","brainwaves/record":"write:brainwaves","haptics/queue":"write:haptics","training/record":"write:kinesis","training/stop":"write:kinesis","training/stopAll":"write:kinesis","wifi/reset":"write:wifi-settings"},a={accelerometer:"read:accelerometer",brainwaves:"read:brainwaves",calm:"read:calm",focus:"read:focus",kinesis:"read:kinesis",predictions:"read:kinesis",signalQuality:"read:signal-quality",getInfo:"read:devices-info",getSelectedDevice:"read:devices-info",selectDevice:"read:devices-info",onDeviceChange:"read:devices-info",onUserDevicesChange:"read:devices-info",settings:"read:devices-settings",changeSettings:"write:devices-settings",status:"read:devices-status",addDevice:"write:devices-add",removeDevice:"write:devices-remove",transferDevice:"write:devices-remove"};function s(e,t){var i=null!=e?e:{},r=i.oauth,a=i.scopes;if(!r)return[!1,null];var s=a.split(","),o=t.command,u=t.action,d=n["".concat(o,"/").concat(u)];return s.includes(d)?[!1,null]:[!0,c(d)]}function o(e,t){var i=null!=e?e:{},r=i.oauth,n=i.scopes;if(!r)return[!1,null];var s=n.split(","),o=a[t];return s.includes(o)?[!1,null]:[!0,c(o)]}function c(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return new Error("".concat(r.prefix,"You are trying to access data with an OAuth token without access to the following scopes: ").concat(t.join(", "),"."))}exports.validateOAuthScopeForAction=s,exports.validateOAuthScopeForFunctionName=o;
|
|
543
|
+
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,i,r){void 0===r&&(r=i);var n=Object.getOwnPropertyDescriptor(t,i);n&&("get"in n?t.__esModule:!n.writable&&!n.configurable)||(n={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,r,n)}:function(e,t,i,r){void 0===r&&(r=i),e[r]=t[i]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var r={};if(null!=i)for(var n in i)"default"!==n&&Object.prototype.hasOwnProperty.call(i,n)&&e(r,i,n);return t(r,i),r};Object.defineProperty(exports,"__esModule",{value:!0}),exports.validateOAuthScopeForFunctionName=exports.validateOAuthScopeForAction=void 0;var r=i(require("../utils/errors")),n={"marker/add":"write:brainwave-markers","brainwaves/record":"write:brainwaves","haptics/queue":"write:haptics","training/record":"write:kinesis","training/stop":"write:kinesis","training/stopAll":"write:kinesis","wifi/reset":"write:wifi-settings"},a={accelerometer:"read:accelerometer",brainwaves:"read:brainwaves",calm:"read:calm",focus:"read:focus",kinesis:"read:kinesis",predictions:"read:kinesis",signalQuality:"read:signal-quality",getInfo:"read:devices-info",getSelectedDevice:"read:devices-info",selectDevice:"read:devices-info",onDeviceChange:"read:devices-info",onUserDevicesChange:"read:devices-info",osVersion:"read:devices-info",settings:"read:devices-settings",changeSettings:"write:devices-settings",status:"read:devices-status",addDevice:"write:devices-add",removeDevice:"write:devices-remove",transferDevice:"write:devices-remove"};function s(e,t){var i=null!=e?e:{},r=i.oauth,a=i.scopes;if(!r)return[!1,null];var s=a.split(","),o=t.command,u=t.action,d=n["".concat(o,"/").concat(u)];return s.includes(d)?[!1,null]:[!0,c(d)]}function o(e,t){var i=null!=e?e:{},r=i.oauth,n=i.scopes;if(!r)return[!1,null];var s=n.split(","),o=a[t];return s.includes(o)?[!1,null]:[!0,c(o)]}function c(){for(var e=arguments.length,t=new Array(e),i=0;i<e;i++)t[i]=arguments[i];return new Error("".concat(r.prefix,"You are trying to access data with an OAuth token without access to the following scopes: ").concat(t.join(", "),"."))}exports.validateOAuthScopeForAction=s,exports.validateOAuthScopeForFunctionName=o;
|
|
544
544
|
},{"../utils/errors":"WDyG"}],"EDTP":[function(require,module,exports) {
|
|
545
545
|
"use strict";module.exports=function(r,n){return function(){for(var t=new Array(arguments.length),e=0;e<t.length;e++)t[e]=arguments[e];return r.apply(n,t)}};
|
|
546
546
|
},{}],"S1cf":[function(require,module,exports) {
|
|
@@ -645,21 +645,21 @@ var e=require("../classes/semver"),r=function(r,n,s){return new e(r,s).compare(n
|
|
|
645
645
|
},{"../classes/semver":"JAyN"}],"A2P2":[function(require,module,exports) {
|
|
646
646
|
var r=require("./compare"),e=function(e,o,u){return r(e,o,u)>=0};module.exports=e;
|
|
647
647
|
},{"./compare":"skdn"}],"rH2Y":[function(require,module,exports) {
|
|
648
|
-
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.osHasBluetoothSupport=void 0;var t=e(require("semver/functions/gte"));function o(e){return!!e&&(Number(e.modelVersion)>=3&&(!!!(null==e?void 0:e.emulator)&&(0,t.default)(e.osVersion,"16.0.0")))}exports.osHasBluetoothSupport=o;
|
|
648
|
+
"use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.osHasBluetoothSupport=void 0;var t=e(require("semver/functions/gte"));function o(e,o){return!!e&&(Number(e.modelVersion)>=3&&(!!!(null==e?void 0:e.emulator)&&(0,t.default)(null!=o?o:e.osVersion,"16.0.0")))}exports.osHasBluetoothSupport=o;
|
|
649
649
|
},{"semver/functions/gte":"A2P2"}],"ouKb":[function(require,module,exports) {
|
|
650
|
-
"use strict";function e(e){return r(e)||n(e)||t()}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function n(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function r(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}function i(e,t){return o(e)||a(e,t)||c()}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function a(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,i=!1,c=void 0;try{for(var a,o=e[Symbol.iterator]();!(r=(a=o.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(s){i=!0,c=s}finally{try{r||null==o.return||o.return()}finally{if(i)throw c}}return n}}function o(e){if(Array.isArray(e))return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),e}var h=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,c){function a(e){try{s(r.next(e))}catch(t){c(t)}}function o(e){try{s(r.throw(e))}catch(t){c(t)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,o)}s((r=r.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.WebBluetoothTransport=void 0;var v=require("@neurosity/ipk"),f=require("@neurosity/ipk"),p=require("@neurosity/ipk"),l=require("@neurosity/ipk"),g=require("rxjs"),m=require("rxjs"),b=require("rxjs/operators"),E=require("rxjs/operators"),N=require("rxjs/operators"),w=require("./isWebBluetoothSupported"),O=require("../utils/create6DigitPin"),C=require("../utils/stitch"),y=require("../utils/encoding"),x=require("../types"),T=require("../constants"),k=require("../constants"),R=require("../utils/osHasBluetoothSupport"),A={autoConnect:!0},_=function(){function t(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(s(this,t),this.type=x.TRANSPORT_TYPE.WEB,this.characteristicsByName={},this.connection$=new g.BehaviorSubject(x.BLUETOOTH_CONNECTION.DISCONNECTED),this.pendingActions$=new g.BehaviorSubject([]),this.logs$=new g.ReplaySubject(10),this.onDisconnected$=this._onDisconnected().pipe((0,N.share)()),this.connectionStream$=this.connection$.asObservable().pipe((0,b.filter)(function(e){return!!e}),(0,E.distinctUntilChanged)(),(0,E.shareReplay)(1)),this._isAutoConnectEnabled$=new g.ReplaySubject(1),this.options=Object.assign(Object.assign({},A),n),!(0,w.isWebBluetoothSupported)()){throw this.addLog("Web Bluetooth is not supported"),new Error("Web Bluetooth is not supported")}this._isAutoConnectEnabled$.subscribe(function(t){e.addLog("Auto connect: ".concat(t?"enabled":"disabled"))}),this._isAutoConnectEnabled$.next(this.options.autoConnect),this.connection$.asObservable().subscribe(function(t){e.addLog("connection status is ".concat(t))}),this.onDisconnected$.subscribe(function(){e.connection$.next(x.BLUETOOTH_CONNECTION.DISCONNECTED)})}return d(t,[{key:"_getPairedDevices",value:function(){return h(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,navigator.bluetooth.getDevices();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)}))}},{key:"_autoConnect",value:function(e){var t=this;return this._isAutoConnectEnabled$.pipe((0,b.switchMap)(function(n){return n?(0,g.merge)(e,t.onDisconnected$.pipe((0,b.switchMap)(function(){return e}))):m.NEVER}),(0,b.switchMap)(function(e){return(0,R.osHasBluetoothSupport)(e)?(0,g.of)(e):m.EMPTY}),(0,b.switchMap)(function(e){return h(t,void 0,void 0,regeneratorRuntime.mark(function t(){var n,r,c,a,o,s,u;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.deviceNickname,!this.isConnected()){t.next=4;break}return this.addLog("Auto connect: ".concat(r," is already connected. Skipping auto connect.")),t.abrupt("return");case 4:return t.next=6,this._getPairedDevices().then(function(e){return[null,e]}).catch(function(e){return[e,null]});case 6:if(c=t.sent,a=i(c,2),o=a[0],s=a[1],!o){t.next=12;break}throw new Error("failed to get devices: ".concat(null!==(n=null==o?void 0:o.message)&&void 0!==n?n:o));case 12:if(this.addLog("Auto connect: found ".concat(s.length," devices ").concat(s.map(function(e){return e.name}).join(", "))),u=s.findLast(function(e){return e.name===r})){t.next=16;break}throw new Error("couldn't find selected device in the list of paired devices.");case 16:return this.addLog("Auto connect: ".concat(r," was detected and previously paired")),t.abrupt("return",u);case 18:case"end":return t.stop()}},t,this)}))}),(0,b.tap)(function(){t.connection$.next(x.BLUETOOTH_CONNECTION.SCANNING)}),(0,b.switchMap)(function(e){return S(e)}),(0,b.switchMap)(function(e){return h(t,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.addLog("Advertisement received for ".concat(e.device.name)),t.next=3,this.getServerServiceAndCharacteristics(e.device);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t,this)}))}))}},{key:"enableAutoConnect",value:function(e){this._isAutoConnectEnabled$.next(e)}},{key:"addLog",value:function(e){this.logs$.next(e)}},{key:"isConnected",value:function(){return this.connection$.getValue()===x.BLUETOOTH_CONNECTION.CONNECTED}},{key:"connection",value:function(){return this.connectionStream$}},{key:"connect",value:function(e){return h(this,void 0,void 0,regeneratorRuntime.mark(function t(){var n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.requestDevice(e);case 3:return n=t.sent,t.next=6,this.getServerServiceAndCharacteristics(n);case 6:t.next=11;break;case 8:return t.prev=8,t.t0=t.catch(0),t.abrupt("return",Promise.reject(t.t0));case 11:case"end":return t.stop()}},t,this,[[0,8]])}))}},{key:"requestDevice",value:function(t){return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i,c;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,this.addLog("Requesting Bluetooth Device..."),r=p.BLUETOOTH_DEVICE_NAME_PREFIXES.map(function(e){return{namePrefix:e}}),i=t?[{name:t}]:r,n.next=6,window.navigator.bluetooth.requestDevice({filters:[].concat(e(i),[{manufacturerData:[{companyIdentifier:l.BLUETOOTH_COMPANY_IDENTIFIER_HEX}]}]),optionalServices:[v.BLUETOOTH_PRIMARY_SERVICE_UUID_HEX]});case 6:return c=n.sent,n.abrupt("return",c);case 10:return n.prev=10,n.t0=n.catch(0),n.abrupt("return",Promise.reject(n.t0));case 13:case"end":return n.stop()}},n,this,[[0,10]])}))}},{key:"getServerServiceAndCharacteristics",value:function(e){return h(this,void 0,void 0,regeneratorRuntime.mark(function t(){var n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,this.device=e,this.connection$.getValue()===x.BLUETOOTH_CONNECTION.CONNECTING||this.connection$.next(x.BLUETOOTH_CONNECTION.CONNECTING),t.next=6,e.gatt.connect();case 6:return this.server=t.sent,this.addLog("Getting service..."),t.next=10,this.server.getPrimaryService(v.BLUETOOTH_PRIMARY_SERVICE_UUID_HEX);case 10:return this.service=t.sent,this.addLog("Got service ".concat(this.service.uuid,", getting characteristics...")),t.next=14,this.service.getCharacteristics();case 14:n=t.sent,this.addLog("Got characteristics"),this.characteristicsByName=Object.fromEntries(n.map(function(e){return[k.CHARACTERISTIC_UUIDS_TO_NAMES[e.uuid],e]})),this.connection$.next(x.BLUETOOTH_CONNECTION.CONNECTED),t.next=23;break;case 20:return t.prev=20,t.t0=t.catch(0),t.abrupt("return",Promise.reject(t.t0));case 23:case"end":return t.stop()}},t,this,[[0,20]])}))}},{key:"_onDisconnected",value:function(){var e=this;return this.connection$.asObservable().pipe((0,b.switchMap)(function(t){return t===x.BLUETOOTH_CONNECTION.CONNECTED?L(e.device,"gattserverdisconnected"):m.NEVER}))}},{key:"disconnect",value:function(){var e,t;return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:(null===(t=null===(e=null==this?void 0:this.device)||void 0===e?void 0:e.gatt)||void 0===t?void 0:t.connected)&&this.device.gatt.disconnect();case 2:case"end":return n.stop()}},n,this)}))}},{key:"getCharacteristicByName",value:function(e){var t;return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",null===(t=this.characteristicsByName)||void 0===t?void 0:t[e]);case 1:case"end":return n.stop()}},n,this)}))}},{key:"subscribeToCharacteristic",value:function(e){var t=this,n=e.characteristicName,r=e.manageNotifications,i=void 0===r||r,c=(0,g.defer)(function(){return t.getCharacteristicByName(n)}).pipe((0,b.switchMap)(function(e){return h(t,void 0,void 0,regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isConnected()||!i){t.next=10;break}return t.prev=1,t.next=4,e.startNotifications();case 4:this.addLog("Started notifications for ".concat(n," characteristic")),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),this.addLog("Attemped to stop notifications for ".concat(n," characteristic: ").concat(null!==(r=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==r?r:t.t0));case 10:return t.abrupt("return",e);case 11:case"end":return t.stop()}},t,this,[[1,7]])}))}),(0,b.switchMap)(function(e){return L(e,"characteristicvaluechanged",function(){return h(t,void 0,void 0,regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isConnected()||!i){t.next=10;break}return t.prev=1,t.next=4,e.stopNotifications();case 4:this.addLog("Stopped notifications for ".concat(n," characteristic")),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),this.addLog("Attemped to stop notifications for ".concat(n," characteristic: ").concat(null!==(r=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==r?r:t.t0));case 10:case"end":return t.stop()}},t,this,[[1,7]])}))})}),(0,b.map)(function(e){var r=e.target.value,i=(0,y.decode)(t.type,r);return t.addLog("Received chunk with buffer size of ".concat(r.byteLength," and decoded size ").concat(i.length," for ").concat(n," characteristic: \n").concat(i)),i}),(0,C.stitchChunks)({delimiter:f.BLUETOOTH_CHUNK_DELIMITER}),(0,b.map)(function(e){var r;try{return JSON.parse(e)}catch(i){return t.addLog("Failed to parse JSON for ".concat(n," characteristic. Falling back to unparsed string. ").concat(null!==(r=null==i?void 0:i.message)&&void 0!==r?r:i)),e}}));return this.connection$.pipe((0,b.switchMap)(function(e){return e===x.BLUETOOTH_CONNECTION.CONNECTED?c:m.NEVER}))}},{key:"readCharacteristic",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i,c,a,o;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,this.addLog("Reading characteristic: ".concat(e)),n.next=4,this.getCharacteristicByName(e);case 4:if(r=n.sent){n.next=8;break}return this.addLog("Did not fund ".concat(e," characteristic")),n.abrupt("return",Promise.reject("Did not find characteristic by the name: ".concat(e)));case 8:return n.next=10,r.readValue();case 10:return i=n.sent,c=i,a=(0,y.decode)(this.type,c),o=t?JSON.parse(a):a,this.addLog("Received read data from ".concat(e," characteristic: \n").concat(o)),n.abrupt("return",o);case 18:return n.prev=18,n.t0=n.catch(0),n.abrupt("return",Promise.reject("Error reading characteristic: ".concat(n.t0.message)));case 21:case"end":return n.stop()}},n,this,[[0,18]])}))}},{key:"writeCharacteristic",value:function(e,t){return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.addLog("Writing characteristic: ".concat(e)),n.next=3,this.getCharacteristicByName(e);case 3:if(r=n.sent){n.next=7;break}return this.addLog("Did not fund ".concat(e," characteristic")),n.abrupt("return",Promise.reject("Did not find characteristic by the name: ".concat(e)));case 7:return i=(0,y.encode)(this.type,t),n.next=10,r.writeValueWithResponse(i);case 10:case"end":return n.stop()}},n,this)}))}},{key:"_addPendingAction",value:function(t){var n=this.pendingActions$.getValue();this.pendingActions$.next([].concat(e(n),[t]))}},{key:"_removePendingAction",value:function(e){var t=this.pendingActions$.getValue();this.pendingActions$.next(t.filter(function(t){return t!==e}))}},{key:"_autoToggleActionNotifications",value:function(e){return h(this,void 0,void 0,regeneratorRuntime.mark(function t(){var n,r,i,c=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:r=!1,i=this.connection$.asObservable().pipe((0,b.switchMap)(function(e){return e===x.BLUETOOTH_CONNECTION.CONNECTED?(0,g.defer)(function(){return c.getCharacteristicByName("actions")}).pipe((0,b.switchMap)(function(e){return n=e,c.pendingActions$})):m.NEVER}),(0,b.tap)(function(e){return h(c,void 0,void 0,regeneratorRuntime.mark(function t(){var i,c,a;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(a=!!e.length)||r){t.next=12;break}return r=!0,t.prev=3,t.next=6,n.startNotifications();case 6:this.addLog("Started notifications for [actions] characteristic"),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(3),this.addLog("Attemped to start notifications for [actions] characteristic: ".concat(null!==(i=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==i?i:t.t0));case 12:if(a||!r){t.next=23;break}return r=!1,t.prev=14,t.next=17,n.stopNotifications();case 17:this.addLog("Stopped notifications for actions characteristic"),t.next=23;break;case 20:t.prev=20,t.t1=t.catch(14),this.addLog("Attemped to stop notifications for [actions] characteristic: ".concat(null!==(c=null===t.t1||void 0===t.t1?void 0:t.t1.message)&&void 0!==c?c:t.t1));case 23:case"end":return t.stop()}},t,this,[[3,9],[14,20]])}))})),e.pipe((0,b.switchMap)(function(e){return(0,R.osHasBluetoothSupport)(e)?i:m.EMPTY})).subscribe();case 3:case"end":return t.stop()}},t,this)}))}},{key:"dispatchAction",value:function(e){var t=e.characteristicName,n=e.action;return h(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r,i,c,a,o=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.responseRequired,i=void 0!==r&&r,c=n.responseTimeout,a=void 0===c?T.DEFAULT_ACTION_RESPONSE_TIMEOUT:c,e.abrupt("return",new Promise(function(e,r){return h(o,void 0,void 0,regeneratorRuntime.mark(function c(){var o,s,u,d=this;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return c.next=2,this.getCharacteristicByName(t).catch(function(){r("Did not find characteristic by the name: ".concat(t))});case 2:if(c.sent){c.next=5;break}return c.abrupt("return");case 5:o=(0,O.create6DigitPin)(),s=JSON.stringify(Object.assign({actionId:o},n)),this.addLog("Dispatched action with id ".concat(o)),i&&a?(this._addPendingAction(o),u=(0,g.timer)(a).subscribe(function(){d._removePendingAction(o),r("Action with id ".concat(o," timed out after ").concat(a,"ms"))}),this.subscribeToCharacteristic({characteristicName:t,manageNotifications:!1}).pipe((0,b.filter)(function(e){return(null==e?void 0:e.actionId)===o}),(0,N.take)(1)).subscribe(function(t){u.unsubscribe(),d._removePendingAction(o),e(t)}),this.writeCharacteristic(t,s).catch(function(e){d._removePendingAction(o),r(e.message)})):this.writeCharacteristic(t,s).then(function(){e(null)}).catch(function(e){r(e.message)});case 9:case"end":return c.stop()}},c,this)}))}));case 2:case"end":return e.stop()}},e)}))}}]),t}();function L(e,t,n){var r=this;return(0,m.fromEventPattern)(function(n){e.addEventListener(t,n)},function(i){return h(r,void 0,void 0,regeneratorRuntime.mark(function r(){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(!n){r.next=3;break}return r.next=3,n();case 3:e.removeEventListener(t,i);case 4:case"end":return r.stop()}},r)}))})}function S(e){return new m.Observable(function(t){var n=new AbortController,r=n.signal,i=e.addEventListener("advertisementreceived",function(e){n.abort(),t.next(e),t.complete()},{once:!0});try{e.watchAdvertisements({signal:r})}catch(c){t.error(c)}return function(){n.abort(),e.removeEventListener("advertisementreceived",i)}})}exports.WebBluetoothTransport=_;
|
|
650
|
+
"use strict";function e(e){return r(e)||n(e)||t()}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function n(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function r(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}function i(e,t){return o(e)||a(e,t)||c()}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function a(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,i=!1,c=void 0;try{for(var a,o=e[Symbol.iterator]();!(r=(a=o.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(s){i=!0,c=s}finally{try{r||null==o.return||o.return()}finally{if(i)throw c}}return n}}function o(e){if(Array.isArray(e))return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),e}var h=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,c){function a(e){try{s(r.next(e))}catch(t){c(t)}}function o(e){try{s(r.throw(e))}catch(t){c(t)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(a,o)}s((r=r.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.WebBluetoothTransport=void 0;var v=require("@neurosity/ipk"),f=require("@neurosity/ipk"),p=require("@neurosity/ipk"),l=require("@neurosity/ipk"),g=require("rxjs"),m=require("rxjs"),b=require("rxjs/operators"),E=require("rxjs/operators"),N=require("rxjs/operators"),w=require("./isWebBluetoothSupported"),O=require("../utils/create6DigitPin"),C=require("../utils/stitch"),y=require("../utils/encoding"),x=require("../types"),T=require("../constants"),k=require("../constants"),R=require("../utils/osHasBluetoothSupport"),A={autoConnect:!0},_=function(){function t(){var e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(s(this,t),this.type=x.TRANSPORT_TYPE.WEB,this.characteristicsByName={},this.connection$=new g.BehaviorSubject(x.BLUETOOTH_CONNECTION.DISCONNECTED),this.pendingActions$=new g.BehaviorSubject([]),this.logs$=new g.ReplaySubject(10),this.onDisconnected$=this._onDisconnected().pipe((0,N.share)()),this.connectionStream$=this.connection$.asObservable().pipe((0,b.filter)(function(e){return!!e}),(0,E.distinctUntilChanged)(),(0,E.shareReplay)(1)),this._isAutoConnectEnabled$=new g.ReplaySubject(1),this.options=Object.assign(Object.assign({},A),n),!(0,w.isWebBluetoothSupported)()){throw this.addLog("Web Bluetooth is not supported"),new Error("Web Bluetooth is not supported")}this._isAutoConnectEnabled$.subscribe(function(t){e.addLog("Auto connect: ".concat(t?"enabled":"disabled"))}),this._isAutoConnectEnabled$.next(this.options.autoConnect),this.connection$.asObservable().subscribe(function(t){e.addLog("connection status is ".concat(t))}),this.onDisconnected$.subscribe(function(){e.connection$.next(x.BLUETOOTH_CONNECTION.DISCONNECTED)})}return d(t,[{key:"_getPairedDevices",value:function(){return h(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,navigator.bluetooth.getDevices();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e)}))}},{key:"_autoConnect",value:function(e,t){var n=this;return this._isAutoConnectEnabled$.pipe((0,b.switchMap)(function(t){return t?(0,g.merge)(e,n.onDisconnected$.pipe((0,b.switchMap)(function(){return e}))):m.NEVER}),(0,b.combineLatestWith)(t),(0,b.switchMap)(function(e){var t=i(e,2),n=t[0],r=t[1];return(0,R.osHasBluetoothSupport)(n,r)?(0,g.of)(n):m.EMPTY}),(0,b.switchMap)(function(e){return h(n,void 0,void 0,regeneratorRuntime.mark(function t(){var n,r,c,a,o,s,u;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.deviceNickname,!this.isConnected()){t.next=4;break}return this.addLog("Auto connect: ".concat(r," is already connected. Skipping auto connect.")),t.abrupt("return");case 4:return t.next=6,this._getPairedDevices().then(function(e){return[null,e]}).catch(function(e){return[e,null]});case 6:if(c=t.sent,a=i(c,2),o=a[0],s=a[1],!o){t.next=12;break}throw new Error("failed to get devices: ".concat(null!==(n=null==o?void 0:o.message)&&void 0!==n?n:o));case 12:if(this.addLog("Auto connect: found ".concat(s.length," devices ").concat(s.map(function(e){return e.name}).join(", "))),u=s.findLast(function(e){return e.name===r})){t.next=16;break}throw new Error("couldn't find selected device in the list of paired devices.");case 16:return this.addLog("Auto connect: ".concat(r," was detected and previously paired")),t.abrupt("return",u);case 18:case"end":return t.stop()}},t,this)}))}),(0,b.tap)(function(){n.connection$.next(x.BLUETOOTH_CONNECTION.SCANNING)}),(0,b.switchMap)(function(e){return S(e)}),(0,b.switchMap)(function(e){return h(n,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.addLog("Advertisement received for ".concat(e.device.name)),t.next=3,this.getServerServiceAndCharacteristics(e.device);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},t,this)}))}))}},{key:"enableAutoConnect",value:function(e){this._isAutoConnectEnabled$.next(e)}},{key:"addLog",value:function(e){this.logs$.next(e)}},{key:"isConnected",value:function(){return this.connection$.getValue()===x.BLUETOOTH_CONNECTION.CONNECTED}},{key:"connection",value:function(){return this.connectionStream$}},{key:"connect",value:function(e){return h(this,void 0,void 0,regeneratorRuntime.mark(function t(){var n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.requestDevice(e);case 3:return n=t.sent,t.next=6,this.getServerServiceAndCharacteristics(n);case 6:t.next=11;break;case 8:return t.prev=8,t.t0=t.catch(0),t.abrupt("return",Promise.reject(t.t0));case 11:case"end":return t.stop()}},t,this,[[0,8]])}))}},{key:"requestDevice",value:function(t){return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i,c;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,this.addLog("Requesting Bluetooth Device..."),r=p.BLUETOOTH_DEVICE_NAME_PREFIXES.map(function(e){return{namePrefix:e}}),i=t?[{name:t}]:r,n.next=6,window.navigator.bluetooth.requestDevice({filters:[].concat(e(i),[{manufacturerData:[{companyIdentifier:l.BLUETOOTH_COMPANY_IDENTIFIER_HEX}]}]),optionalServices:[v.BLUETOOTH_PRIMARY_SERVICE_UUID_HEX]});case 6:return c=n.sent,n.abrupt("return",c);case 10:return n.prev=10,n.t0=n.catch(0),n.abrupt("return",Promise.reject(n.t0));case 13:case"end":return n.stop()}},n,this,[[0,10]])}))}},{key:"getServerServiceAndCharacteristics",value:function(e){return h(this,void 0,void 0,regeneratorRuntime.mark(function t(){var n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,this.device=e,this.connection$.getValue()===x.BLUETOOTH_CONNECTION.CONNECTING||this.connection$.next(x.BLUETOOTH_CONNECTION.CONNECTING),t.next=6,e.gatt.connect();case 6:return this.server=t.sent,this.addLog("Getting service..."),t.next=10,this.server.getPrimaryService(v.BLUETOOTH_PRIMARY_SERVICE_UUID_HEX);case 10:return this.service=t.sent,this.addLog("Got service ".concat(this.service.uuid,", getting characteristics...")),t.next=14,this.service.getCharacteristics();case 14:n=t.sent,this.addLog("Got characteristics"),this.characteristicsByName=Object.fromEntries(n.map(function(e){return[k.CHARACTERISTIC_UUIDS_TO_NAMES[e.uuid],e]})),this.connection$.next(x.BLUETOOTH_CONNECTION.CONNECTED),t.next=23;break;case 20:return t.prev=20,t.t0=t.catch(0),t.abrupt("return",Promise.reject(t.t0));case 23:case"end":return t.stop()}},t,this,[[0,20]])}))}},{key:"_onDisconnected",value:function(){var e=this;return this.connection$.asObservable().pipe((0,b.switchMap)(function(t){return t===x.BLUETOOTH_CONNECTION.CONNECTED?L(e.device,"gattserverdisconnected"):m.NEVER}))}},{key:"disconnect",value:function(){var e,t;return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:(null===(t=null===(e=null==this?void 0:this.device)||void 0===e?void 0:e.gatt)||void 0===t?void 0:t.connected)&&this.device.gatt.disconnect();case 2:case"end":return n.stop()}},n,this)}))}},{key:"getCharacteristicByName",value:function(e){var t;return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",null===(t=this.characteristicsByName)||void 0===t?void 0:t[e]);case 1:case"end":return n.stop()}},n,this)}))}},{key:"subscribeToCharacteristic",value:function(e){var t=this,n=e.characteristicName,r=e.manageNotifications,i=void 0===r||r,c=(0,g.defer)(function(){return t.getCharacteristicByName(n)}).pipe((0,b.switchMap)(function(e){return h(t,void 0,void 0,regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isConnected()||!i){t.next=10;break}return t.prev=1,t.next=4,e.startNotifications();case 4:this.addLog("Started notifications for ".concat(n," characteristic")),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),this.addLog("Attemped to stop notifications for ".concat(n," characteristic: ").concat(null!==(r=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==r?r:t.t0));case 10:return t.abrupt("return",e);case 11:case"end":return t.stop()}},t,this,[[1,7]])}))}),(0,b.switchMap)(function(e){return L(e,"characteristicvaluechanged",function(){return h(t,void 0,void 0,regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isConnected()||!i){t.next=10;break}return t.prev=1,t.next=4,e.stopNotifications();case 4:this.addLog("Stopped notifications for ".concat(n," characteristic")),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),this.addLog("Attemped to stop notifications for ".concat(n," characteristic: ").concat(null!==(r=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==r?r:t.t0));case 10:case"end":return t.stop()}},t,this,[[1,7]])}))})}),(0,b.map)(function(e){var r=e.target.value,i=(0,y.decode)(t.type,r);return t.addLog("Received chunk with buffer size of ".concat(r.byteLength," and decoded size ").concat(i.length," for ").concat(n," characteristic: \n").concat(i)),i}),(0,C.stitchChunks)({delimiter:f.BLUETOOTH_CHUNK_DELIMITER}),(0,b.map)(function(e){var r;try{return JSON.parse(e)}catch(i){return t.addLog("Failed to parse JSON for ".concat(n," characteristic. Falling back to unparsed string. ").concat(null!==(r=null==i?void 0:i.message)&&void 0!==r?r:i)),e}}));return this.connection$.pipe((0,b.switchMap)(function(e){return e===x.BLUETOOTH_CONNECTION.CONNECTED?c:m.NEVER}))}},{key:"readCharacteristic",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i,c,a,o;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.prev=0,this.addLog("Reading characteristic: ".concat(e)),n.next=4,this.getCharacteristicByName(e);case 4:if(r=n.sent){n.next=8;break}return this.addLog("Did not fund ".concat(e," characteristic")),n.abrupt("return",Promise.reject("Did not find characteristic by the name: ".concat(e)));case 8:return n.next=10,r.readValue();case 10:return i=n.sent,c=i,a=(0,y.decode)(this.type,c),o=t?JSON.parse(a):a,this.addLog("Received read data from ".concat(e," characteristic: \n").concat(o)),n.abrupt("return",o);case 18:return n.prev=18,n.t0=n.catch(0),n.abrupt("return",Promise.reject("Error reading characteristic: ".concat(n.t0.message)));case 21:case"end":return n.stop()}},n,this,[[0,18]])}))}},{key:"writeCharacteristic",value:function(e,t){return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.addLog("Writing characteristic: ".concat(e)),n.next=3,this.getCharacteristicByName(e);case 3:if(r=n.sent){n.next=7;break}return this.addLog("Did not fund ".concat(e," characteristic")),n.abrupt("return",Promise.reject("Did not find characteristic by the name: ".concat(e)));case 7:return i=(0,y.encode)(this.type,t),n.next=10,r.writeValueWithResponse(i);case 10:case"end":return n.stop()}},n,this)}))}},{key:"_addPendingAction",value:function(t){var n=this.pendingActions$.getValue();this.pendingActions$.next([].concat(e(n),[t]))}},{key:"_removePendingAction",value:function(e){var t=this.pendingActions$.getValue();this.pendingActions$.next(t.filter(function(t){return t!==e}))}},{key:"_autoToggleActionNotifications",value:function(e,t){return h(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,c,a,o=this;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:c=!1,a=this.connection$.asObservable().pipe((0,b.switchMap)(function(e){return e===x.BLUETOOTH_CONNECTION.CONNECTED?(0,g.defer)(function(){return o.getCharacteristicByName("actions")}).pipe((0,b.switchMap)(function(e){return r=e,o.pendingActions$})):m.NEVER}),(0,b.tap)(function(e){return h(o,void 0,void 0,regeneratorRuntime.mark(function t(){var n,i,a;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!(a=!!e.length)||c){t.next=12;break}return c=!0,t.prev=3,t.next=6,r.startNotifications();case 6:this.addLog("Started notifications for [actions] characteristic"),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(3),this.addLog("Attemped to start notifications for [actions] characteristic: ".concat(null!==(n=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==n?n:t.t0));case 12:if(a||!c){t.next=23;break}return c=!1,t.prev=14,t.next=17,r.stopNotifications();case 17:this.addLog("Stopped notifications for actions characteristic"),t.next=23;break;case 20:t.prev=20,t.t1=t.catch(14),this.addLog("Attemped to stop notifications for [actions] characteristic: ".concat(null!==(i=null===t.t1||void 0===t.t1?void 0:t.t1.message)&&void 0!==i?i:t.t1));case 23:case"end":return t.stop()}},t,this,[[3,9],[14,20]])}))})),e.pipe((0,b.combineLatestWith)(t),(0,b.switchMap)(function(e){var t=i(e,2),n=t[0],r=t[1];return(0,R.osHasBluetoothSupport)(n,r)?a:m.EMPTY})).subscribe();case 3:case"end":return n.stop()}},n,this)}))}},{key:"dispatchAction",value:function(e){var t=e.characteristicName,n=e.action;return h(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r,i,c,a,o=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.responseRequired,i=void 0!==r&&r,c=n.responseTimeout,a=void 0===c?T.DEFAULT_ACTION_RESPONSE_TIMEOUT:c,e.abrupt("return",new Promise(function(e,r){return h(o,void 0,void 0,regeneratorRuntime.mark(function c(){var o,s,u,d=this;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return c.next=2,this.getCharacteristicByName(t).catch(function(){r("Did not find characteristic by the name: ".concat(t))});case 2:if(c.sent){c.next=5;break}return c.abrupt("return");case 5:o=(0,O.create6DigitPin)(),s=JSON.stringify(Object.assign({actionId:o},n)),this.addLog("Dispatched action with id ".concat(o)),i&&a?(this._addPendingAction(o),u=(0,g.timer)(a).subscribe(function(){d._removePendingAction(o),r("Action with id ".concat(o," timed out after ").concat(a,"ms"))}),this.subscribeToCharacteristic({characteristicName:t,manageNotifications:!1}).pipe((0,b.filter)(function(e){return(null==e?void 0:e.actionId)===o}),(0,N.take)(1)).subscribe(function(t){u.unsubscribe(),d._removePendingAction(o),e(t)}),this.writeCharacteristic(t,s).catch(function(e){d._removePendingAction(o),r(e.message)})):this.writeCharacteristic(t,s).then(function(){e(null)}).catch(function(e){r(e.message)});case 9:case"end":return c.stop()}},c,this)}))}));case 2:case"end":return e.stop()}},e)}))}}]),t}();function L(e,t,n){var r=this;return(0,m.fromEventPattern)(function(n){e.addEventListener(t,n)},function(i){return h(r,void 0,void 0,regeneratorRuntime.mark(function r(){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(!n){r.next=3;break}return r.next=3,n();case 3:e.removeEventListener(t,i);case 4:case"end":return r.stop()}},r)}))})}function S(e){return new m.Observable(function(t){var n=new AbortController,r=n.signal,i=e.addEventListener("advertisementreceived",function(e){n.abort(),t.next(e),t.complete()},{once:!0});try{e.watchAdvertisements({signal:r})}catch(c){t.error(c)}return function(){n.abort(),e.removeEventListener("advertisementreceived",i)}})}exports.WebBluetoothTransport=_;
|
|
651
651
|
},{"@neurosity/ipk":"ZOGh","rxjs":"Zr8e","rxjs/operators":"v3iE","./isWebBluetoothSupported":"ljun","../utils/create6DigitPin":"UDAB","../utils/stitch":"V73a","../utils/encoding":"jTvL","../types":"iwtf","../constants":"dGLb","../utils/osHasBluetoothSupport":"rH2Y"}],"FtS5":[function(require,module,exports) {
|
|
652
|
-
"use strict";function e(e){return r(e)||n(e)||t()}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function n(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}function r(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function o(e,t,n){return t&&c(e.prototype,t),n&&c(e,n),e}var s=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))(function(i,a){function c(e){try{s(r.next(e))}catch(t){a(t)}}function o(e){try{s(r.throw(e))}catch(t){a(t)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(c,o)}s((r=r.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ReactNativeTransport=void 0;var u=require("@neurosity/ipk"),d=require("@neurosity/ipk"),h=require("@neurosity/ipk"),l=require("rxjs"),v=require("rxjs"),p=require("rxjs/operators"),f=require("rxjs/operators"),g=require("rxjs/operators"),m=require("../utils/create6DigitPin"),E=require("../utils/stitch"),b=require("../utils/encoding"),N=require("../types"),O=require("../constants"),C=require("../constants"),w=require("../constants"),T=require("../constants"),y=require("../utils/osHasBluetoothSupport"),_={autoConnect:!0},R=function(){function t(e){var n=this;if(a(this,t),this.type=N.TRANSPORT_TYPE.REACT_NATIVE,this.characteristicsByName={},this.connection$=new l.BehaviorSubject(N.BLUETOOTH_CONNECTION.DISCONNECTED),this.pendingActions$=new l.BehaviorSubject([]),this.logs$=new l.ReplaySubject(10),this.connectionStream$=this.connection$.asObservable().pipe((0,p.filter)(function(e){return!!e}),(0,f.distinctUntilChanged)(),(0,f.shareReplay)(1)),this._isAutoConnectEnabled$=new l.ReplaySubject(1),!e){var r="React Native transport: missing options.";throw this.addLog(r),new Error(r)}this.options=Object.assign(Object.assign({},_),e);var i=this.options,c=i.BleManager,o=i.bleManagerEmitter,s=i.platform,u=i.autoConnect;if(!c){var d="React Native option: BleManager not provided.";throw this.addLog(d),new Error(d)}if(!o){var h="React Native option: bleManagerEmitter not provided.";throw this.addLog(h),new Error(h)}if(!s){var v="React Native option: platform not provided.";throw this.addLog(v),new Error(v)}this.BleManager=c,this.bleManagerEmitter=o,this.platform=s,this._isAutoConnectEnabled$.next(u),this._isAutoConnectEnabled$.subscribe(function(e){n.addLog("Auto connect: ".concat(e?"enabled":"disabled"))}),this.bleEvents={stopScan$:this._fromEvent("BleManagerStopScan"),discoverPeripheral$:this._fromEvent("BleManagerDiscoverPeripheral"),connectPeripheral$:this._fromEvent("BleManagerConnectPeripheral"),disconnectPeripheral$:this._fromEvent("BleManagerDisconnectPeripheral"),didUpdateValueForCharacteristic$:this._fromEvent("BleManagerDidUpdateValueForCharacteristic"),didUpdateState$:this._fromEvent("BleManagerDidUpdateState")},this.onDisconnected$=this.bleEvents.disconnectPeripheral$.pipe((0,g.share)()),this.BleManager.start({showAlert:!1}).then(function(){n.addLog("BleManger started")}).catch(function(e){var t;n.addLog("BleManger failed to start. ".concat(null!==(t=null==e?void 0:e.message)&&void 0!==t?t:e))}),this.connection$.asObservable().subscribe(function(e){n.addLog("connection status is ".concat(e))}),this.onDisconnected$.subscribe(function(){n.connection$.next(N.BLUETOOTH_CONNECTION.DISCONNECTED)})}return o(t,[{key:"addLog",value:function(e){this.logs$.next(e)}},{key:"isConnected",value:function(){return this.connection$.getValue()===N.BLUETOOTH_CONNECTION.CONNECTED}},{key:"_autoConnect",value:function(e){var t=this,n=this.onDisconnected$.pipe((0,p.switchMap)(function(){return e}));return this._isAutoConnectEnabled$.pipe((0,p.switchMap)(function(t){return t?(0,l.merge)(e,n):v.NEVER}),(0,p.switchMap)(function(e){return(0,y.osHasBluetoothSupport)(e)?t.scan().pipe((0,p.switchMap)(function(t){var n=t.find(function(t){return t.name===(null==e?void 0:e.deviceNickname)});return n?(0,l.of)(n):v.NEVER}),(0,g.distinct)(function(e){return e.id}),(0,g.take)(1)):v.NEVER}),(0,p.switchMap)(function(e){return s(t,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.connect(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}))}},{key:"enableAutoConnect",value:function(e){this._isAutoConnectEnabled$.next(e)}},{key:"connection",value:function(){return this.connectionStream$}},{key:"_fromEvent",value:function(e){var t=this;return(0,v.fromEventPattern)(function(n){t.bleManagerEmitter.addListener(e,n)},function(){t.bleManagerEmitter.removeAllListeners(e)}).pipe((0,g.share)())}},{key:"scan",value:function(e){var t,n,r,a=this,c=null!==(t=null==e?void 0:e.seconds)&&void 0!==t?t:10,o=null!==(n=null==e?void 0:e.once)&&void 0!==n&&n,s=null!==(r=null==e?void 0:e.skipConnectionUpdate)&&void 0!==r&&r,d=[u.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING],m={},E=new v.Observable(function(e){var t;try{a.BleManager.scan(d,c,!0,m).then(function(){a.addLog("BleManger scanning ".concat(o?"once":"indefintely")),e.next()})}catch(n){a.addLog("BleManger scanning ".concat(o?"once":"indefintely"," failed. ").concat(null!==(t=null==n?void 0:n.message)&&void 0!==t?t:n)),e.error(n)}return function(){a.BleManager.stopScan()}});return(o?E:(0,l.timer)(0,1e4).pipe((0,p.switchMap)(function(){return E}))).pipe((0,p.tap)(function(){s||a.connection$.next(N.BLUETOOTH_CONNECTION.SCANNING)}),(0,p.takeUntil)(this.onDisconnected$),(0,p.switchMap)(function(){return a.bleEvents.discoverPeripheral$}),(0,p.filter)(function(e){var t,n,r,i=null!==(r=null!==(n=null===(t=null==e?void 0:e.advertising)||void 0===t?void 0:t.localName)&&void 0!==n?n:e.name)&&void 0!==r?r:"";return!!i&&-1!==h.BLUETOOTH_DEVICE_NAME_PREFIXES.findIndex(function(e){return i.startsWith(e)})}),(0,g.scan)(function(e,t){var n,r,c,o,s,u,d,h,l=null!==(c=null!==(r=null===(n=null==t?void 0:t.advertising)||void 0===n?void 0:n.localName)&&void 0!==r?r:t.name)&&void 0!==c?c:"",v=null===(h=null===(d=(0,b.decode)(a.type,null!==(u=null===(s=null===(o=null==t?void 0:t.advertising)||void 0===o?void 0:o.manufacturerData)||void 0===s?void 0:s.bytes)&&void 0!==u?u:[]))||void 0===d?void 0:d.slice)||void 0===h?void 0:h.call(d,2);return Object.assign(Object.assign({},e),i({},t.id,Object.assign(Object.assign({},t),{name:l,manufactureDataString:v})))},{}),(0,f.distinctUntilChanged)(function(e,t){return JSON.stringify(e)===JSON.stringify(t)}),(0,p.map)(function(e){return Object.values(e)}),(0,g.share)())}},{key:"connect",value:function(e){return s(this,void 0,void 0,regeneratorRuntime.mark(function t(){var n=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",new Promise(function(t,r){return s(n,void 0,void 0,regeneratorRuntime.mark(function n(){var i,a=this;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,e){n.next=4;break}return this.addLog("Peripheral not found"),n.abrupt("return");case 4:return this.connection$.next(N.BLUETOOTH_CONNECTION.CONNECTING),n.next=7,this.BleManager.connect(e.id);case 7:return this.addLog("Getting service..."),n.next=10,this.BleManager.retrieveServices(e.id,[u.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING]);case 10:if(i=n.sent){n.next=15;break}return this.addLog("Could not retreive services"),r(new Error("Could not retreive services")),n.abrupt("return");case 15:if(this.addLog("Got service ".concat(u.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING,", getting characteristics...")),this.device=e,this.characteristicsByName=Object.fromEntries(i.characteristics.map(function(t){return[C.CHARACTERISTIC_UUIDS_TO_NAMES[t.characteristic.toLowerCase()],{characteristicUUID:t.characteristic,serviceUUID:t.service,peripheralId:e.id}]})),this.addLog("Got characteristics."),"android"!==this.platform){n.next=22;break}return n.next=22,this.BleManager.requestMTU(e.id,w.ANDROID_MAX_MTU).then(function(e){a.addLog("Successfully updated Android MTU to ".concat(e," bytes. Requested MTU: ").concat(w.ANDROID_MAX_MTU," bytes."))}).catch(function(e){a.addLog("Failed to set Android MTU of ".concat(w.ANDROID_MAX_MTU," bytes. Error: ").concat(e))});case 22:this.addLog("Successfully connected to peripheral ".concat(e.id)),this.connection$.next(N.BLUETOOTH_CONNECTION.CONNECTED),t(),n.next=30;break;case 27:n.prev=27,n.t0=n.catch(0),r(n.t0);case 30:case"end":return n.stop()}},n,this,[[0,27]])}))}));case 1:case"end":return t.stop()}},t)}))}},{key:"disconnect",value:function(){var e;return s(this,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,!(this.isConnected()&&(null===(e=null==this?void 0:this.device)||void 0===e?void 0:e.id))){t.next=4;break}return t.next=4,this.BleManager.disconnect(this.device.id);case 4:t.next=9;break;case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",Promise.reject(t.t0));case 9:case"end":return t.stop()}},t,this,[[0,6]])}))}},{key:"getCharacteristicByName",value:function(e){var t;if(!(e in this.characteristicsByName))throw new Error("Characteristic by name ".concat(e," is not found"));return null===(t=this.characteristicsByName)||void 0===t?void 0:t[e]}},{key:"subscribeToCharacteristic",value:function(e){var t=this,n=e.characteristicName,r=e.manageNotifications,i=void 0===r||r;return this.connection$.pipe((0,p.switchMap)(function(e){return e===N.BLUETOOTH_CONNECTION.CONNECTED?(r=t.getCharacteristicByName(n),a=r.peripheralId,c=r.serviceUUID,o=r.characteristicUUID,(0,l.defer)(function(){return s(t,void 0,void 0,regeneratorRuntime.mark(function e(){var t;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!i){e.next=10;break}return e.prev=1,e.next=4,this.BleManager.startNotification(a,c,o);case 4:this.addLog("Started notifications for ".concat(n," characteristic")),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(1),this.addLog("Attemped to stop notifications for ".concat(n," characteristic: ").concat(null!==(t=null===e.t0||void 0===e.t0?void 0:e.t0.message)&&void 0!==t?t:e.t0));case 10:case"end":return e.stop()}},e,this,[[1,7]])}))}).pipe((0,p.switchMap)(function(){return t.bleEvents.didUpdateValueForCharacteristic$}),(0,f.finalize)(function(){return s(t,void 0,void 0,regeneratorRuntime.mark(function e(){var t;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!i){e.next=10;break}return e.prev=1,e.next=4,this.BleManager.stopNotification(a,c,o);case 4:this.addLog("Stopped notifications for ".concat(n," characteristic")),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(1),this.addLog("Attemped to stop notifications for ".concat(n," characteristic: ").concat(null!==(t=null===e.t0||void 0===e.t0?void 0:e.t0.message)&&void 0!==t?t:e.t0));case 10:case"end":return e.stop()}},e,this,[[1,7]])}))}),(0,p.filter)(function(e){return e.characteristic===o}),(0,p.map)(function(e){var n=e.value;return(0,b.decode)(t.type,n)}),(0,E.stitchChunks)({delimiter:d.BLUETOOTH_CHUNK_DELIMITER}),(0,p.map)(function(e){var r;try{return JSON.parse(e)}catch(i){return t.addLog("Failed to parse JSON for ".concat(n," characteristic. Falling back to unparsed string. ").concat(null!==(r=null==i?void 0:i.message)&&void 0!==r?r:i)),e}}))):v.NEVER;var r,a,c,o}))}},{key:"readCharacteristic",value:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return s(this,void 0,void 0,regeneratorRuntime.mark(function r(){var i,a,c,o,s,u,d;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(this.addLog("Reading characteristic: ".concat(e)),i=this.getCharacteristicByName(e),a=i.peripheralId,c=i.serviceUUID,o=i.characteristicUUID){r.next=4;break}return r.abrupt("return",Promise.reject(new Error("Did not find characteristic matching ".concat(e))));case 4:return r.prev=4,r.next=7,this.BleManager.read(a,c,o);case 7:return s=r.sent,u=(0,b.decode)(this.type,s),d=n?JSON.parse(u):u,this.addLog("Received read data from ".concat(e," characteristic: \n").concat(d)),r.abrupt("return",d);case 14:return r.prev=14,r.t0=r.catch(4),r.abrupt("return",Promise.reject(new Error("readCharacteristic ".concat(e," error. ").concat(null!==(t=null===r.t0||void 0===r.t0?void 0:r.t0.message)&&void 0!==t?t:r.t0))));case 17:case"end":return r.stop()}},r,this,[[4,14]])}))}},{key:"writeCharacteristic",value:function(e,t){return s(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i,a,c,o;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.addLog("Writing characteristic: ".concat(e)),r=this.getCharacteristicByName(e),i=r.peripheralId,a=r.serviceUUID,c=r.characteristicUUID){n.next=4;break}return n.abrupt("return",Promise.reject(new Error("Did not find characteristic matching ".concat(e))));case 4:return o=(0,b.encode)(this.type,t),n.next=7,this.BleManager.write(i,a,c,o,T.REACT_NATIVE_MAX_BYTE_SIZE);case 7:case"end":return n.stop()}},n,this)}))}},{key:"_addPendingAction",value:function(t){var n=this.pendingActions$.getValue();this.pendingActions$.next([].concat(e(n),[t]))}},{key:"_removePendingAction",value:function(e){var t=this.pendingActions$.getValue();this.pendingActions$.next(t.filter(function(t){return t!==e}))}},{key:"_autoToggleActionNotifications",value:function(e){return s(this,void 0,void 0,regeneratorRuntime.mark(function t(){var n,r,i=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:n=!1,r=this.connection$.asObservable().pipe((0,p.switchMap)(function(e){return e===N.BLUETOOTH_CONNECTION.CONNECTED?i.pendingActions$:v.NEVER}),(0,p.tap)(function(e){return s(i,void 0,void 0,regeneratorRuntime.mark(function t(){var r,i,a,c,o,s,u;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(a=this.getCharacteristicByName("actions"),c=a.peripheralId,o=a.serviceUUID,s=a.characteristicUUID,!(u=!!e.length)||n){t.next=13;break}return n=!0,t.prev=4,t.next=7,this.BleManager.startNotification(c,o,s);case 7:this.addLog("Started notifications for [actions] characteristic"),t.next=13;break;case 10:t.prev=10,t.t0=t.catch(4),this.addLog("Attemped to start notifications for [actions] characteristic: ".concat(null!==(r=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==r?r:t.t0));case 13:if(u||!n){t.next=24;break}return n=!1,t.prev=15,t.next=18,this.BleManager.stopNotification(c,o,s);case 18:this.addLog("Stopped notifications for actions characteristic"),t.next=24;break;case 21:t.prev=21,t.t1=t.catch(15),this.addLog("Attemped to stop notifications for [actions] characteristic: ".concat(null!==(i=null===t.t1||void 0===t.t1?void 0:t.t1.message)&&void 0!==i?i:t.t1));case 24:case"end":return t.stop()}},t,this,[[4,10],[15,21]])}))})),e.pipe((0,p.switchMap)(function(e){return(0,y.osHasBluetoothSupport)(e)?r:v.EMPTY})).subscribe();case 3:case"end":return t.stop()}},t,this)}))}},{key:"dispatchAction",value:function(e){var t=e.characteristicName,n=e.action;return s(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r,i,a,c,o=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.responseRequired,i=void 0!==r&&r,a=n.responseTimeout,c=void 0===a?O.DEFAULT_ACTION_RESPONSE_TIMEOUT:a,e.abrupt("return",new Promise(function(e,r){return s(o,void 0,void 0,regeneratorRuntime.mark(function a(){var o,s,u,d=this;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:o=(0,m.create6DigitPin)(),s=JSON.stringify(Object.assign({actionId:o},n)),this.addLog("Dispatched action with id ".concat(o)),i&&c?(this._addPendingAction(o),u=(0,l.timer)(c).subscribe(function(){d._removePendingAction(o),r(new Error("Action with id ".concat(o," timed out after ").concat(c,"ms")))}),this.subscribeToCharacteristic({characteristicName:t,manageNotifications:!1}).pipe((0,p.filter)(function(e){return(null==e?void 0:e.actionId)===o}),(0,g.take)(1)).subscribe(function(t){u.unsubscribe(),d._removePendingAction(o),e(t)}),this.writeCharacteristic(t,s).catch(function(e){d._removePendingAction(o),r(e)})):this.writeCharacteristic(t,s).then(function(){e(null)}).catch(function(e){r(e)});case 4:case"end":return a.stop()}},a,this)}))}));case 2:case"end":return e.stop()}},e)}))}}]),t}();exports.ReactNativeTransport=R;
|
|
652
|
+
"use strict";function t(t){return r(t)||n(t)||e()}function e(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function n(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function r(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}function i(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t,e){return s(t)||o(t,e)||c()}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function o(t,e){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)){var n=[],r=!0,i=!1,a=void 0;try{for(var c,o=t[Symbol.iterator]();!(r=(c=o.next()).done)&&(n.push(c.value),!e||n.length!==e);r=!0);}catch(s){i=!0,a=s}finally{try{r||null==o.return||o.return()}finally{if(i)throw a}}return n}}function s(t){if(Array.isArray(t))return t}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function d(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function h(t,e,n){return e&&d(t.prototype,e),n&&d(t,n),t}var l=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))(function(i,a){function c(t){try{s(r.next(t))}catch(e){a(e)}}function o(t){try{s(r.throw(t))}catch(e){a(e)}}function s(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(c,o)}s((r=r.apply(t,e||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ReactNativeTransport=void 0;var v=require("@neurosity/ipk"),f=require("@neurosity/ipk"),p=require("@neurosity/ipk"),g=require("rxjs"),m=require("rxjs"),b=require("rxjs/operators"),E=require("rxjs/operators"),N=require("rxjs/operators"),O=require("../utils/create6DigitPin"),w=require("../utils/stitch"),y=require("../utils/encoding"),C=require("../types"),T=require("../constants"),_=require("../constants"),R=require("../constants"),M=require("../constants"),x=require("../utils/osHasBluetoothSupport"),A={autoConnect:!0},U=function(){function e(t){var n=this;if(u(this,e),this.type=C.TRANSPORT_TYPE.REACT_NATIVE,this.characteristicsByName={},this.connection$=new g.BehaviorSubject(C.BLUETOOTH_CONNECTION.DISCONNECTED),this.pendingActions$=new g.BehaviorSubject([]),this.logs$=new g.ReplaySubject(10),this.connectionStream$=this.connection$.asObservable().pipe((0,b.filter)(function(t){return!!t}),(0,E.distinctUntilChanged)(),(0,E.shareReplay)(1)),this._isAutoConnectEnabled$=new g.ReplaySubject(1),!t){var r="React Native transport: missing options.";throw this.addLog(r),new Error(r)}this.options=Object.assign(Object.assign({},A),t);var i=this.options,a=i.BleManager,c=i.bleManagerEmitter,o=i.platform,s=i.autoConnect;if(!a){var d="React Native option: BleManager not provided.";throw this.addLog(d),new Error(d)}if(!c){var h="React Native option: bleManagerEmitter not provided.";throw this.addLog(h),new Error(h)}if(!o){var l="React Native option: platform not provided.";throw this.addLog(l),new Error(l)}this.BleManager=a,this.bleManagerEmitter=c,this.platform=o,this._isAutoConnectEnabled$.next(s),this._isAutoConnectEnabled$.subscribe(function(t){n.addLog("Auto connect: ".concat(t?"enabled":"disabled"))}),this.bleEvents={stopScan$:this._fromEvent("BleManagerStopScan"),discoverPeripheral$:this._fromEvent("BleManagerDiscoverPeripheral"),connectPeripheral$:this._fromEvent("BleManagerConnectPeripheral"),disconnectPeripheral$:this._fromEvent("BleManagerDisconnectPeripheral"),didUpdateValueForCharacteristic$:this._fromEvent("BleManagerDidUpdateValueForCharacteristic"),didUpdateState$:this._fromEvent("BleManagerDidUpdateState")},this.onDisconnected$=this.bleEvents.disconnectPeripheral$.pipe((0,N.share)()),this.BleManager.start({showAlert:!1}).then(function(){n.addLog("BleManger started")}).catch(function(t){var e;n.addLog("BleManger failed to start. ".concat(null!==(e=null==t?void 0:t.message)&&void 0!==e?e:t))}),this.connection$.asObservable().subscribe(function(t){n.addLog("connection status is ".concat(t))}),this.onDisconnected$.subscribe(function(){n.connection$.next(C.BLUETOOTH_CONNECTION.DISCONNECTED)})}return h(e,[{key:"addLog",value:function(t){this.logs$.next(t)}},{key:"isConnected",value:function(){return this.connection$.getValue()===C.BLUETOOTH_CONNECTION.CONNECTED}},{key:"_autoConnect",value:function(t,e){var n=this,r=this.onDisconnected$.pipe((0,b.switchMap)(function(){return t}));return this._isAutoConnectEnabled$.pipe((0,b.switchMap)(function(e){return e?(0,g.merge)(t,r):m.NEVER}),(0,N.combineLatestWith)(e),(0,b.switchMap)(function(t){var e=a(t,2),r=e[0],i=e[1];return(0,x.osHasBluetoothSupport)(r,i)?n.scan().pipe((0,b.switchMap)(function(t){var e=t.find(function(t){return t.name===(null==r?void 0:r.deviceNickname)});return e?(0,g.of)(e):m.NEVER}),(0,N.distinct)(function(t){return t.id}),(0,N.take)(1)):m.NEVER}),(0,b.switchMap)(function(t){return l(n,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.connect(t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}))}},{key:"enableAutoConnect",value:function(t){this._isAutoConnectEnabled$.next(t)}},{key:"connection",value:function(){return this.connectionStream$}},{key:"_fromEvent",value:function(t){var e=this;return(0,m.fromEventPattern)(function(n){e.bleManagerEmitter.addListener(t,n)},function(){e.bleManagerEmitter.removeAllListeners(t)}).pipe((0,N.share)())}},{key:"scan",value:function(t){var e,n,r,a=this,c=null!==(e=null==t?void 0:t.seconds)&&void 0!==e?e:10,o=null!==(n=null==t?void 0:t.once)&&void 0!==n&&n,s=null!==(r=null==t?void 0:t.skipConnectionUpdate)&&void 0!==r&&r,u=[v.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING],d={},h=new m.Observable(function(t){var e;try{a.BleManager.scan(u,c,!0,d).then(function(){a.addLog("BleManger scanning ".concat(o?"once":"indefintely")),t.next()})}catch(n){a.addLog("BleManger scanning ".concat(o?"once":"indefintely"," failed. ").concat(null!==(e=null==n?void 0:n.message)&&void 0!==e?e:n)),t.error(n)}return function(){a.BleManager.stopScan()}});return(o?h:(0,g.timer)(0,1e4).pipe((0,b.switchMap)(function(){return h}))).pipe((0,b.tap)(function(){s||a.connection$.next(C.BLUETOOTH_CONNECTION.SCANNING)}),(0,b.takeUntil)(this.onDisconnected$),(0,b.switchMap)(function(){return a.bleEvents.discoverPeripheral$}),(0,b.filter)(function(t){var e,n,r,i=null!==(r=null!==(n=null===(e=null==t?void 0:t.advertising)||void 0===e?void 0:e.localName)&&void 0!==n?n:t.name)&&void 0!==r?r:"";return!!i&&-1!==p.BLUETOOTH_DEVICE_NAME_PREFIXES.findIndex(function(t){return i.startsWith(t)})}),(0,N.scan)(function(t,e){var n,r,c,o,s,u,d,h,l=null!==(c=null!==(r=null===(n=null==e?void 0:e.advertising)||void 0===n?void 0:n.localName)&&void 0!==r?r:e.name)&&void 0!==c?c:"",v=null===(h=null===(d=(0,y.decode)(a.type,null!==(u=null===(s=null===(o=null==e?void 0:e.advertising)||void 0===o?void 0:o.manufacturerData)||void 0===s?void 0:s.bytes)&&void 0!==u?u:[]))||void 0===d?void 0:d.slice)||void 0===h?void 0:h.call(d,2);return Object.assign(Object.assign({},t),i({},e.id,Object.assign(Object.assign({},e),{name:l,manufactureDataString:v})))},{}),(0,E.distinctUntilChanged)(function(t,e){return JSON.stringify(t)===JSON.stringify(e)}),(0,b.map)(function(t){return Object.values(t)}),(0,N.share)())}},{key:"connect",value:function(t){return l(this,void 0,void 0,regeneratorRuntime.mark(function e(){var n=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise(function(e,r){return l(n,void 0,void 0,regeneratorRuntime.mark(function n(){var i,a=this;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(n.prev=0,t){n.next=4;break}return this.addLog("Peripheral not found"),n.abrupt("return");case 4:return this.connection$.next(C.BLUETOOTH_CONNECTION.CONNECTING),n.next=7,this.BleManager.connect(t.id);case 7:return this.addLog("Getting service..."),n.next=10,this.BleManager.retrieveServices(t.id,[v.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING]);case 10:if(i=n.sent){n.next=15;break}return this.addLog("Could not retreive services"),r(new Error("Could not retreive services")),n.abrupt("return");case 15:if(this.addLog("Got service ".concat(v.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING,", getting characteristics...")),this.device=t,this.characteristicsByName=Object.fromEntries(i.characteristics.map(function(e){return[_.CHARACTERISTIC_UUIDS_TO_NAMES[e.characteristic.toLowerCase()],{characteristicUUID:e.characteristic,serviceUUID:e.service,peripheralId:t.id}]})),this.addLog("Got characteristics."),"android"!==this.platform){n.next=22;break}return n.next=22,this.BleManager.requestMTU(t.id,R.ANDROID_MAX_MTU).then(function(t){a.addLog("Successfully updated Android MTU to ".concat(t," bytes. Requested MTU: ").concat(R.ANDROID_MAX_MTU," bytes."))}).catch(function(t){a.addLog("Failed to set Android MTU of ".concat(R.ANDROID_MAX_MTU," bytes. Error: ").concat(t))});case 22:this.addLog("Successfully connected to peripheral ".concat(t.id)),this.connection$.next(C.BLUETOOTH_CONNECTION.CONNECTED),e(),n.next=30;break;case 27:n.prev=27,n.t0=n.catch(0),r(n.t0);case 30:case"end":return n.stop()}},n,this,[[0,27]])}))}));case 1:case"end":return e.stop()}},e)}))}},{key:"disconnect",value:function(){var t;return l(this,void 0,void 0,regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,!(this.isConnected()&&(null===(t=null==this?void 0:this.device)||void 0===t?void 0:t.id))){e.next=4;break}return e.next=4,this.BleManager.disconnect(this.device.id);case 4:e.next=9;break;case 6:return e.prev=6,e.t0=e.catch(0),e.abrupt("return",Promise.reject(e.t0));case 9:case"end":return e.stop()}},e,this,[[0,6]])}))}},{key:"getCharacteristicByName",value:function(t){var e;if(!(t in this.characteristicsByName))throw new Error("Characteristic by name ".concat(t," is not found"));return null===(e=this.characteristicsByName)||void 0===e?void 0:e[t]}},{key:"subscribeToCharacteristic",value:function(t){var e=this,n=t.characteristicName,r=t.manageNotifications,i=void 0===r||r;return this.connection$.pipe((0,b.switchMap)(function(t){return t===C.BLUETOOTH_CONNECTION.CONNECTED?(r=e.getCharacteristicByName(n),a=r.peripheralId,c=r.serviceUUID,o=r.characteristicUUID,(0,g.defer)(function(){return l(e,void 0,void 0,regeneratorRuntime.mark(function t(){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!i){t.next=10;break}return t.prev=1,t.next=4,this.BleManager.startNotification(a,c,o);case 4:this.addLog("Started notifications for ".concat(n," characteristic")),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),this.addLog("Attemped to stop notifications for ".concat(n," characteristic: ").concat(null!==(e=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==e?e:t.t0));case 10:case"end":return t.stop()}},t,this,[[1,7]])}))}).pipe((0,b.switchMap)(function(){return e.bleEvents.didUpdateValueForCharacteristic$}),(0,E.finalize)(function(){return l(e,void 0,void 0,regeneratorRuntime.mark(function t(){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!i){t.next=10;break}return t.prev=1,t.next=4,this.BleManager.stopNotification(a,c,o);case 4:this.addLog("Stopped notifications for ".concat(n," characteristic")),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),this.addLog("Attemped to stop notifications for ".concat(n," characteristic: ").concat(null!==(e=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==e?e:t.t0));case 10:case"end":return t.stop()}},t,this,[[1,7]])}))}),(0,b.filter)(function(t){return t.characteristic===o}),(0,b.map)(function(t){var n=t.value;return(0,y.decode)(e.type,n)}),(0,w.stitchChunks)({delimiter:f.BLUETOOTH_CHUNK_DELIMITER}),(0,b.map)(function(t){var r;try{return JSON.parse(t)}catch(i){return e.addLog("Failed to parse JSON for ".concat(n," characteristic. Falling back to unparsed string. ").concat(null!==(r=null==i?void 0:i.message)&&void 0!==r?r:i)),t}}))):m.NEVER;var r,a,c,o}))}},{key:"readCharacteristic",value:function(t){var e,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return l(this,void 0,void 0,regeneratorRuntime.mark(function r(){var i,a,c,o,s,u,d;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(this.addLog("Reading characteristic: ".concat(t)),i=this.getCharacteristicByName(t),a=i.peripheralId,c=i.serviceUUID,o=i.characteristicUUID){r.next=4;break}return r.abrupt("return",Promise.reject(new Error("Did not find characteristic matching ".concat(t))));case 4:return r.prev=4,r.next=7,this.BleManager.read(a,c,o);case 7:return s=r.sent,u=(0,y.decode)(this.type,s),d=n?JSON.parse(u):u,this.addLog("Received read data from ".concat(t," characteristic: \n").concat(d)),r.abrupt("return",d);case 14:return r.prev=14,r.t0=r.catch(4),r.abrupt("return",Promise.reject(new Error("readCharacteristic ".concat(t," error. ").concat(null!==(e=null===r.t0||void 0===r.t0?void 0:r.t0.message)&&void 0!==e?e:r.t0))));case 17:case"end":return r.stop()}},r,this,[[4,14]])}))}},{key:"writeCharacteristic",value:function(t,e){return l(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i,a,c,o;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(this.addLog("Writing characteristic: ".concat(t)),r=this.getCharacteristicByName(t),i=r.peripheralId,a=r.serviceUUID,c=r.characteristicUUID){n.next=4;break}return n.abrupt("return",Promise.reject(new Error("Did not find characteristic matching ".concat(t))));case 4:return o=(0,y.encode)(this.type,e),n.next=7,this.BleManager.write(i,a,c,o,M.REACT_NATIVE_MAX_BYTE_SIZE);case 7:case"end":return n.stop()}},n,this)}))}},{key:"_addPendingAction",value:function(e){var n=this.pendingActions$.getValue();this.pendingActions$.next([].concat(t(n),[e]))}},{key:"_removePendingAction",value:function(t){var e=this.pendingActions$.getValue();this.pendingActions$.next(e.filter(function(e){return e!==t}))}},{key:"_autoToggleActionNotifications",value:function(t,e){return l(this,void 0,void 0,regeneratorRuntime.mark(function n(){var r,i,c=this;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:r=!1,i=this.connection$.asObservable().pipe((0,b.switchMap)(function(t){return t===C.BLUETOOTH_CONNECTION.CONNECTED?c.pendingActions$:m.NEVER}),(0,b.tap)(function(t){return l(c,void 0,void 0,regeneratorRuntime.mark(function e(){var n,i,a,c,o,s,u;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(a=this.getCharacteristicByName("actions"),c=a.peripheralId,o=a.serviceUUID,s=a.characteristicUUID,!(u=!!t.length)||r){e.next=13;break}return r=!0,e.prev=4,e.next=7,this.BleManager.startNotification(c,o,s);case 7:this.addLog("Started notifications for [actions] characteristic"),e.next=13;break;case 10:e.prev=10,e.t0=e.catch(4),this.addLog("Attemped to start notifications for [actions] characteristic: ".concat(null!==(n=null===e.t0||void 0===e.t0?void 0:e.t0.message)&&void 0!==n?n:e.t0));case 13:if(u||!r){e.next=24;break}return r=!1,e.prev=15,e.next=18,this.BleManager.stopNotification(c,o,s);case 18:this.addLog("Stopped notifications for actions characteristic"),e.next=24;break;case 21:e.prev=21,e.t1=e.catch(15),this.addLog("Attemped to stop notifications for [actions] characteristic: ".concat(null!==(i=null===e.t1||void 0===e.t1?void 0:e.t1.message)&&void 0!==i?i:e.t1));case 24:case"end":return e.stop()}},e,this,[[4,10],[15,21]])}))})),t.pipe((0,N.combineLatestWith)(e),(0,b.switchMap)(function(t){var e=a(t,2),n=e[0],r=e[1];return(0,x.osHasBluetoothSupport)(n,r)?i:m.EMPTY})).subscribe();case 3:case"end":return n.stop()}},n,this)}))}},{key:"dispatchAction",value:function(t){var e=t.characteristicName,n=t.action;return l(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,i,a,c,o=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.responseRequired,i=void 0!==r&&r,a=n.responseTimeout,c=void 0===a?T.DEFAULT_ACTION_RESPONSE_TIMEOUT:a,t.abrupt("return",new Promise(function(t,r){return l(o,void 0,void 0,regeneratorRuntime.mark(function a(){var o,s,u,d=this;return regeneratorRuntime.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:o=(0,O.create6DigitPin)(),s=JSON.stringify(Object.assign({actionId:o},n)),this.addLog("Dispatched action with id ".concat(o)),i&&c?(this._addPendingAction(o),u=(0,g.timer)(c).subscribe(function(){d._removePendingAction(o),r(new Error("Action with id ".concat(o," timed out after ").concat(c,"ms")))}),this.subscribeToCharacteristic({characteristicName:e,manageNotifications:!1}).pipe((0,b.filter)(function(t){return(null==t?void 0:t.actionId)===o}),(0,N.take)(1)).subscribe(function(e){u.unsubscribe(),d._removePendingAction(o),t(e)}),this.writeCharacteristic(e,s).catch(function(t){d._removePendingAction(o),r(t)})):this.writeCharacteristic(e,s).then(function(){t(null)}).catch(function(t){r(t)});case 4:case"end":return a.stop()}},a,this)}))}));case 2:case"end":return t.stop()}},t)}))}}]),e}();exports.ReactNativeTransport=U;
|
|
653
653
|
},{"@neurosity/ipk":"ZOGh","rxjs":"Zr8e","rxjs/operators":"v3iE","../utils/create6DigitPin":"UDAB","../utils/stitch":"V73a","../utils/encoding":"jTvL","../types":"iwtf","../constants":"dGLb","../utils/osHasBluetoothSupport":"rH2Y"}],"Oj1i":[function(require,module,exports) {
|
|
654
654
|
"use strict";function n(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}Object.defineProperty(exports,"__esModule",{value:!0}),exports.epoch=exports.bufferToEpoch=exports.addInfo=void 0;var e=require("rxjs"),t=require("rxjs/operators"),r="data",o=256,i=function(n){return n instanceof Object&&n===Object(n)},a=function(n){return"function"==typeof n},u=function(n){return function(e){var t;return Object.assign(Object.assign({},n),{info:Object.assign(Object.assign({},null!==(t=null==n?void 0:n.info)&&void 0!==t?t:{}),e||{})})}},f=function(n){return(0,e.pipe)((0,t.map)(function(e){if(!i(e)||!i(n)&&!a(n))return e;var t=a(n)?n(e):n;return u(e)(t)}))};exports.addInfo=f;var c=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r;return n[0][e].map(function(t,r){return n.map(function(n){return n[e][r]})})},p=function(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=i.samplingRate,u=void 0===a?o:a,f=i.dataProp,p=void 0===f?r:f;return(0,e.pipe)((0,t.map)(function(e){var t;return n(t={},p,c(e,p)),n(t,"info",Object.assign(Object.assign({},e[0]&&e[0].info?e[0].info:{}),{startTime:e[0].timestamp,samplingRate:e[0].info&&e[0].info.samplingRate?e[0].info.samplingRate:u})),t}))};exports.bufferToEpoch=p;var s=function(n){var o=n.duration,i=n.interval,a=n.samplingRate,u=n.dataProp,f=void 0===u?r:u;return(0,e.pipe)((0,t.bufferCount)(i),(0,t.scan)(function(n,e){return n.concat(e).slice(n.length<o?0:-o)}),(0,t.filter)(function(n){return n.length===o}),(0,exports.bufferToEpoch)({samplingRate:a,dataProp:f}))};exports.epoch=s;
|
|
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 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"),b=require("./utils/osHasBluetoothSupport"),w=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,b.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:"enableAutoConnect",value:function(t){this.transport.enableAutoConnect(t)}},{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,b.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,b.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=w;
|
|
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"),b=require("./utils/osHasBluetoothSupport"),w=function(){function e(t){var r=this;i(this,e),this.selectedDevice$=new c.ReplaySubject(1),this.osVersion$=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$,this.osVersion$).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.osVersion$),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.combineLatestWith)(this.osVersion$),(0,h.switchMap)(function(i){var s=t(i,2),a=s[0],u=s[1];return(0,b.osHasBluetoothSupport)(a,u)?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:"enableAutoConnect",value:function(t){this.transport.enableAutoConnect(t)}},{key:"_hasBluetoothSupport",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function t(){var e,r;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.next=5,(0,u.firstValueFrom)(this.osVersion$);case 5:return r=t.sent,t.abrupt("return",(0,b.osHasBluetoothSupport)(e,r));case 7: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(e){var r=this;return this.selectedDevice$.pipe((0,h.combineLatestWith)(this.osVersion$),(0,h.switchMap)(function(n){var i=t(n,2),s=i[0],a=i[1];return(0,b.osHasBluetoothSupport)(s,a)?r.isAuthenticated$.pipe((0,p.distinctUntilChanged)(),(0,h.switchMap)(function(t){return t?r.transport.subscribeToCharacteristic({characteristicName:e}):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=w;
|
|
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),t(require("./types/index"),exports);
|
|
661
661
|
},{"./BluetoothClient":"fihV","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/osHasBluetoothSupport":"rH2Y","./types/index":"iwtf"}],"BZP9":[function(require,module,exports) {
|
|
662
|
-
"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(t,n){return!n||"object"!==e(n)&&"function"!=typeof n?r(t):n}function r(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e,t){return a(e)||c(e,t)||s()}function s(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function c(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var r=[],n=!0,i=!1,o=void 0;try{for(var u,s=e[Symbol.iterator]();!(n=(u=s.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(c){i=!0,o=c}finally{try{n||null==s.return||s.return()}finally{if(i)throw o}}return r}}function a(e){if(Array.isArray(e))return e}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function d(e,t,r){return t&&h(e.prototype,t),r&&h(e,r),e}var f=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=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,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),m=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),v=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&f(t,e,r);return m(t,e),t},p=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function u(e){try{c(n.next(e))}catch(t){o(t)}}function s(e){try{c(n.throw(e))}catch(t){o(t)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,s)}c((n=n.apply(e,t||[])).next())})},b=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Notion=exports.Neurosity=void 0;var g=require("rxjs"),C=require("rxjs"),y=require("rxjs/operators"),w=b(require("fast-deep-equal")),O=require("./api/index"),k=require("./api/index"),S=require("./types/streaming"),M=require("./utils/subscription"),_=require("./types/status"),x=v(require("./utils/errors")),E=v(require("./utils/platform")),T=v(require("./utils/hapticEffects")),A=require("./utils/oauth"),D=require("./utils/oauth"),N=require("./api/https/createOAuthURL"),I=require("./api/https/getOAuthToken"),R=require("./utils/is-node"),F=require("./utils/metrics"),P=require("./api/bluetooth"),j=require("./api/bluetooth/types"),L={timesync:!1,autoSelectDevice:!0,streamingMode:S.STREAMING_MODE.WIFI_ONLY,emulator:!1,emulatorHost:"localhost",emulatorAuthPort:9099,emulatorDatabasePort:9e3,emulatorFunctionsPort:5001,emulatorFirestorePort:8080,emulatorOptions:{}},U=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};l(this,e),this.streamingMode$=new C.ReplaySubject(1);var r=t.streamingMode,n=t.bluetoothTransport;this.options=Object.freeze(Object.assign(Object.assign({},L),t)),this.cloudClient=new O.CloudClient(this.options),n&&(this.bluetoothClient=new P.BluetoothClient({selectedDevice$:this.onDeviceChange(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:n})),this._initStreamingMode(r,!!n)}return d(e,[{key:"_initStreamingMode",value:function(e,t){var r=[S.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,S.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),n=!Object.values(S.STREAMING_MODE).includes(e),i=r&&!t;this.isMissingBluetoothTransport=i,!e||n||i?this.streamingMode$.next(S.STREAMING_MODE.WIFI_ONLY):this.streamingMode$.next(e)}},{key:"streamingState",value:function(){var e=this,t=function(e){return[_.STATUS.ONLINE,_.STATUS.UPDATING].includes(e)};return this.streamingMode$.pipe((0,y.switchMap)(function(r){return e.onDeviceChange().pipe((0,y.switchMap)(function(n){return n?e.isMissingBluetoothTransport||!(0,P.osHasBluetoothSupport)(n)?e.cloudClient.status().pipe((0,y.map)(function(e){var n=e.state;return{connected:t(n),streamingMode:r,activeMode:S.STREAMING_TYPE.WIFI}})):(0,g.combineLatest)({wifiStatus:e.cloudClient.status(),bluetoothConnection:(null==e?void 0:e.bluetoothClient)?e.bluetoothClient.connection():(0,g.of)(j.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe((0,y.map)(function(e){var n=e.wifiStatus,i=e.bluetoothConnection===j.BLUETOOTH_CONNECTION.CONNECTED;switch(r){default:case S.STREAMING_MODE.WIFI_ONLY:return{connected:t(n.state),streamingMode:r,activeMode:S.STREAMING_TYPE.WIFI};case S.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:t(n.state)||!i?t(n.state):i,streamingMode:r,activeMode:t(n.state)||!i?S.STREAMING_TYPE.WIFI:S.STREAMING_TYPE.BLUETOOTH};case S.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!i||t(n.state),streamingMode:r,activeMode:i?S.STREAMING_TYPE.BLUETOOTH:S.STREAMING_TYPE.WIFI}}}),(0,y.distinctUntilChanged)(function(e,t){return(0,w.default)(e,t)})):C.EMPTY}))}))}},{key:"_withStreamingModeObservable",value:function(e){var t=e.wifi,r=e.bluetooth;return this.streamingState().pipe((0,y.switchMap)(function(e){switch(e.activeMode){case S.STREAMING_TYPE.WIFI:return t();case S.STREAMING_TYPE.BLUETOOTH:return r();default:return t()}}))}},{key:"_withStreamingModePromise",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.wifi,n=e.bluetooth,t.next=3,(0,C.firstValueFrom)(this.streamingState());case 3:i=t.sent,o=i.activeMode,t.t0=o,t.next=t.t0===S.STREAMING_TYPE.WIFI?8:t.t0===S.STREAMING_TYPE.BLUETOOTH?11:14;break;case 8:return t.next=10,r();case 10:return t.abrupt("return",t.sent);case 11:return t.next=13,n();case 13:return t.abrupt("return",t.sent);case 14:return t.next=16,r();case 16:return t.abrupt("return",t.sent);case 17:case"end":return t.stop()}},t,this)}))}},{key:"_getCloudMetricDependencies",value:function(){return{options:this.options,cloudClient:this.cloudClient,onDeviceChange:this.onDeviceChange.bind(this),status:this.status.bind(this)}}},{key:"login",value:function(e){return p(this,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.cloudClient.login(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"logout",value:function(){return p(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.cloudClient.logout();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"__getApp",value:function(){return this.cloudClient.__getApp()}},{key:"onAuthStateChanged",value:function(){return this.cloudClient.onAuthStateChanged()}},{key:"addDevice",value:function(e){var t=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"addDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.addDevice(e)}},{key:"removeDevice",value:function(e){var t=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"removeDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.removeDevice(e)}},{key:"transferDevice",value:function(e){var t=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"transferDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.transferDevice(e)}},{key:"onUserDevicesChange",value:function(){var e=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onUserDevicesChange"),2),t=e[0],r=e[1];return t?(0,g.throwError)(function(){return r}):this.cloudClient.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.cloudClient.onUserClaimsChange()}},{key:"getDevices",value:function(){return p(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.cloudClient.getDevices();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"selectDevice",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"selectDevice"),n=u(r,2),i=n[0],o=n[1],!i){t.next=3;break}return t.abrupt("return",Promise.reject(o));case 3:return t.next=5,this.cloudClient.selectDevice(e);case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}},t,this)}))}},{key:"getSelectedDevice",value:function(){return p(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t,r,n,i;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=(0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getSelectedDevice"),r=u(t,2),n=r[0],i=r[1],!n){e.next=3;break}return e.abrupt("return",Promise.reject(i));case 3:return e.next=5,this.cloudClient.getSelectedDevice();case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return p(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t,r,n,i,o=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}return e.abrupt("return",Promise.reject(x.mustSelectDevice));case 4:if(t=(0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getInfo"),r=u(t,2),n=r[0],i=r[1],!n){e.next=7;break}return e.abrupt("return",Promise.reject(i));case 7:return e.next=9,this._withStreamingModePromise({wifi:function(){return o.cloudClient.getInfo()},bluetooth:function(){return o.bluetoothClient.getInfo()}});case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}},e,this)}))}},{key:"onDeviceChange",value:function(){var e=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onDeviceChange"),2),t=e[0],r=e[1];return t?(0,g.throwError)(function(){return r}):this.cloudClient.onDeviceChange()}},{key:"disconnect",value:function(){return p(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._withStreamingModePromise({wifi:function(){return t.cloudClient.disconnect()},bluetooth:function(){return t.bluetoothClient.disconnect()}});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"dispatchAction",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o,s=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}return t.abrupt("return",Promise.reject(x.mustSelectDevice));case 4:if(r=(0,D.validateOAuthScopeForAction)(this.cloudClient.userClaims,e),n=u(r,2),i=n[0],o=n[1],!i){t.next=7;break}return t.abrupt("return",Promise.reject(o));case 7:return t.next=9,this._withStreamingModePromise({wifi:function(){return s.cloudClient.dispatchAction(e)},bluetooth:function(){return s.bluetoothClient.dispatchAction(e)}});case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}},t,this)}))}},{key:"addMarker",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}throw x.mustSelectDevice;case 4:if(e){t.next=6;break}throw new Error("".concat(x.prefix,"A label is required for addMarker"));case 6:return t.next=8,this._withStreamingModePromise({wifi:function(){return r.cloudClient.dispatchAction({command:"marker",action:"add",message:{label:e,timestamp:r.cloudClient.timestamp}})},bluetooth:function(){return r.bluetoothClient.addMarker(e)}});case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}},t,this)}))}},{key:"haptics",value:function(e){var t;return p(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,o,u,s,c,a=this;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return n="haptics",r.next=3,this.cloudClient.didSelectDevice();case 3:if(r.sent){r.next=5;break}return r.abrupt("return",Promise.reject(x.mustSelectDevice));case 5:return r.next=7,this.getSelectedDevice();case 7:if(r.t1=t=r.sent,r.t0=null===r.t1,r.t0){r.next=11;break}r.t0=void 0===t;case 11:if(!r.t0){r.next=15;break}r.t2=void 0,r.next=16;break;case 15:r.t2=t.modelVersion;case 16:if(i=r.t2,E.supportsHaptics(i)){r.next=20;break}return r.abrupt("return",Promise.reject(x.metricNotSupportedByModel(n,i)));case 20:o=E.getPlatformHapticMotors(i),r.t3=regeneratorRuntime.keys(e);case 22:if((r.t4=r.t3()).done){r.next=33;break}if(u=r.t4.value,Object.keys(o).includes(u)){r.next=26;break}return r.abrupt("return",Promise.reject(x.locationNotFound(u,i)));case 26:if(s=e[u],7,!(s.length>7)){r.next=30;break}return r.abrupt("return",Promise.reject(x.exceededMaxItems(7)));case 30:o[u]=s,r.next=22;break;case 33:return c={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}},r.next=36,this._withStreamingModePromise({wifi:function(){return a.cloudClient.dispatchAction(c)},bluetooth:function(){return a.bluetoothClient.dispatchAction(c)}});case 36:return r.abrupt("return",r.sent);case 37:case"end":return r.stop()}},r,this)}))}},{key:"getHapticEffects",value:function(){return T}},{key:"accelerometer",value:function(){var e=this,t="accelerometer",r=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,g.throwError)(function(){return i}):this.onDeviceChange().pipe((0,y.switchMap)(function(r){var n=(null==r?void 0:r.modelVersion)||E.MODEL_VERSION_1;return E.supportsAccel(n)?e._withStreamingModeObservable({wifi:function(){return(0,F.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,M.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.accelerometer()}}):(0,g.throwError)(function(){return x.metricNotSupportedByModel(t,n)})}))}},{key:"brainwaves",value:function(e){var t=this,r=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"brainwaves"),2),n=r[0],i=r[1];return n?(0,g.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,F.getCloudMetric)(t._getCloudMetricDependencies(),{metric:"brainwaves",labels:e?[e]:[],atomic:!1})},bluetooth:function(){return t.bluetoothClient.brainwaves(e)}})}},{key:"calm",value:function(){var e=this,t=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"calm"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,F.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["calm"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.calm()}})}},{key:"signalQuality",value:function(){var e=this,t="signalQuality",r=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,g.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,F.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,M.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.signalQuality()}})}},{key:"settings",value:function(){var e=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"settings"),2),t=e[0],r=e[1];return t?(0,g.throwError)(function(){return r}):this.cloudClient.observeNamespace("settings")}},{key:"focus",value:function(){var e=this,t=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"focus"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,F.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["focus"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.focus()}})}},{key:"kinesis",value:function(e){var t=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"kinesis"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):(0,F.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"kinesis",labels:e?[e]:[],atomic:!1})}},{key:"predictions",value:function(e){var t=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"predictions"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):(0,F.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"predictions",labels:e?[e]:[],atomic:!1})}},{key:"status",value:function(){var e=this,t=u((0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"status"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return e.cloudClient.status()},bluetooth:function(){return e.bluetoothClient.status()}})}},{key:"changeSettings",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}return t.abrupt("return",Promise.reject(x.mustSelectDevice));case 4:if(r=(0,A.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"changeSettings"),n=u(r,2),i=n[0],o=n[1],!i){t.next=7;break}return t.abrupt("return",Promise.reject(o));case 7:return t.next=9,this.cloudClient.changeSettings(e);case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}},t,this)}))}},{key:"goOffline",value:function(){this.cloudClient.goOffline()}},{key:"goOnline",value:function(){this.cloudClient.goOnline()}},{key:"createAccount",value:function(e){return this.cloudClient.createAccount(e)}},{key:"deleteAccount",value:function(){return this.cloudClient.deleteAccount()}},{key:"createBluetoothToken",value:function(){return this.cloudClient.createBluetoothToken()}},{key:"createCustomToken",value:function(){return this.cloudClient.createCustomToken()}},{key:"getTimesyncOffset",value:function(){return this.options.timesync||console.warn("getTimesyncOffset() requires options.timesync to be true."),this.options.timesync?this.cloudClient.getTimesyncOffset():0}},{key:"createOAuthURL",value:function(e){return R.isNode?(0,N.createOAuthURL)(e,this.options):Promise.reject(new Error("".concat(x.prefix,"the createOAuthURL method must be used on the server side (node.js) for security reasons.")))}},{key:"getOAuthToken",value:function(e){return R.isNode?(0,I.getOAuthToken)(e,this.options):Promise.reject(new Error("".concat(x.prefix,"the getOAuthToken method must be used on the server side (node.js) for security reasons.")))}},{key:"removeOAuthAccess",value:function(){return this.cloudClient.removeOAuthAccess()}},{key:"onUserExperiments",value:function(){return this.cloudClient.onUserExperiments()}},{key:"deleteUserExperiment",value:function(e){return this.cloudClient.deleteUserExperiment(e)}},{key:"bluetooth",get:function(){return null==this?void 0:this.bluetoothClient}},{key:"training",get:function(){var e=this;return{record:function(t){return p(e,void 0,void 0,regeneratorRuntime.mark(function e(){var r,n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw x.mustSelectDevice;case 4:return r=this.cloudClient.user&&"uid"in this.cloudClient.user?this.cloudClient.user.uid:null,n=Object.assign(Object.assign({fit:!1,baseline:!1,timestamp:this.cloudClient.timestamp},t),{userId:r}),e.next=8,this.cloudClient.actions.dispatch({command:"training",action:"record",message:n});case 8:case"end":return e.stop()}},e,this)}))},stop:function(t){return p(e,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.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw x.mustSelectDevice;case 4:return e.next=6,this.cloudClient.actions.dispatch({command:"training",action:"stop",message:Object.assign({},t)});case 6:case"end":return e.stop()}},e,this)}))},stopAll:function(){return p(e,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.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw x.mustSelectDevice;case 4:return e.next=6,this.cloudClient.actions.dispatch({command:"training",action:"stopAll",message:{}});case 6:case"end":return e.stop()}},e,this)}))}}}}]),e}();exports.Neurosity=U,U.credentialWithLink=k.credentialWithLink,U.createUser=O.createUser,U.SERVER_TIMESTAMP=k.SERVER_TIMESTAMP;var q=function(e){function r(){var e,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return l(this,r),e=t(this,n(r).call(this,i)),console.log("The Notion class is deprecated and will be removed in the next version of the SDK. Please use the Neurosity class instead. e.g. new Notion() => new Neurosity()"),e}return i(r,U),r}();exports.Notion=q;
|
|
662
|
+
"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(t,n){return!n||"object"!==e(n)&&"function"!=typeof n?r(t):n}function r(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&o(e,t)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function u(e,t){return a(e)||c(e,t)||s()}function s(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function c(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var r=[],n=!0,i=!1,o=void 0;try{for(var u,s=e[Symbol.iterator]();!(n=(u=s.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(c){i=!0,o=c}finally{try{n||null==s.return||s.return()}finally{if(i)throw o}}return r}}function a(e){if(Array.isArray(e))return e}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function d(e,t,r){return t&&h(e.prototype,t),r&&h(e,r),e}var f=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=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,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),m=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),v=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&f(t,e,r);return m(t,e),t},p=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function u(e){try{c(n.next(e))}catch(t){o(t)}}function s(e){try{c(n.throw(e))}catch(t){o(t)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,s)}c((n=n.apply(e,t||[])).next())})},b=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Notion=exports.Neurosity=void 0;var g=require("rxjs"),C=require("rxjs"),y=require("rxjs/operators"),w=require("rxjs/operators"),O=b(require("fast-deep-equal")),k=require("./api/index"),S=require("./api/index"),M=require("./types/streaming"),x=require("./utils/subscription"),_=require("./types/status"),E=v(require("./utils/errors")),T=v(require("./utils/platform")),A=v(require("./utils/hapticEffects")),D=require("./utils/oauth"),N=require("./utils/oauth"),I=require("./api/https/createOAuthURL"),R=require("./api/https/getOAuthToken"),F=require("./utils/is-node"),P=require("./utils/metrics"),j=require("./api/bluetooth"),L=require("./api/bluetooth/types"),U={timesync:!1,autoSelectDevice:!0,streamingMode:M.STREAMING_MODE.WIFI_ONLY,emulator:!1,emulatorHost:"localhost",emulatorAuthPort:9099,emulatorDatabasePort:9e3,emulatorFunctionsPort:5001,emulatorFirestorePort:8080,emulatorOptions:{}},q=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};l(this,e),this.streamingMode$=new C.ReplaySubject(1);var r=t.streamingMode,n=t.bluetoothTransport;this.options=Object.freeze(Object.assign(Object.assign({},U),t)),this.cloudClient=new k.CloudClient(this.options),n&&(this.bluetoothClient=new j.BluetoothClient({selectedDevice$:this.onDeviceChange(),osVersion$:this.osVersion(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:n})),this._initStreamingMode(r,!!n)}return d(e,[{key:"_initStreamingMode",value:function(e,t){var r=[M.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,M.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),n=!Object.values(M.STREAMING_MODE).includes(e),i=r&&!t;this.isMissingBluetoothTransport=i,!e||n||i?this.streamingMode$.next(M.STREAMING_MODE.WIFI_ONLY):this.streamingMode$.next(e)}},{key:"streamingState",value:function(){var e=this,t=function(e){return[_.STATUS.ONLINE,_.STATUS.UPDATING].includes(e)};return this.streamingMode$.pipe((0,y.switchMap)(function(r){return e.onDeviceChange().pipe((0,w.combineLatestWith)(e.osVersion()),(0,y.switchMap)(function(n){var i=u(n,2),o=i[0],s=i[1];return o?e.isMissingBluetoothTransport||!(0,j.osHasBluetoothSupport)(o,s)?e.cloudClient.status().pipe((0,y.map)(function(e){var n=e.state;return{connected:t(n),streamingMode:r,activeMode:M.STREAMING_TYPE.WIFI}})):(0,g.combineLatest)({wifiStatus:e.cloudClient.status(),bluetoothConnection:(null==e?void 0:e.bluetoothClient)?e.bluetoothClient.connection():(0,g.of)(L.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe((0,y.map)(function(e){var n=e.wifiStatus,i=e.bluetoothConnection===L.BLUETOOTH_CONNECTION.CONNECTED;switch(r){default:case M.STREAMING_MODE.WIFI_ONLY:return{connected:t(n.state),streamingMode:r,activeMode:M.STREAMING_TYPE.WIFI};case M.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:t(n.state)||!i?t(n.state):i,streamingMode:r,activeMode:t(n.state)||!i?M.STREAMING_TYPE.WIFI:M.STREAMING_TYPE.BLUETOOTH};case M.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!i||t(n.state),streamingMode:r,activeMode:i?M.STREAMING_TYPE.BLUETOOTH:M.STREAMING_TYPE.WIFI}}}),(0,y.distinctUntilChanged)(function(e,t){return(0,O.default)(e,t)})):C.EMPTY}))}))}},{key:"_withStreamingModeObservable",value:function(e){var t=e.wifi,r=e.bluetooth;return this.streamingState().pipe((0,y.switchMap)(function(e){switch(e.activeMode){case M.STREAMING_TYPE.WIFI:return t();case M.STREAMING_TYPE.BLUETOOTH:return r();default:return t()}}))}},{key:"_withStreamingModePromise",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.wifi,n=e.bluetooth,t.next=3,(0,C.firstValueFrom)(this.streamingState());case 3:i=t.sent,o=i.activeMode,t.t0=o,t.next=t.t0===M.STREAMING_TYPE.WIFI?8:t.t0===M.STREAMING_TYPE.BLUETOOTH?11:14;break;case 8:return t.next=10,r();case 10:return t.abrupt("return",t.sent);case 11:return t.next=13,n();case 13:return t.abrupt("return",t.sent);case 14:return t.next=16,r();case 16:return t.abrupt("return",t.sent);case 17:case"end":return t.stop()}},t,this)}))}},{key:"_getCloudMetricDependencies",value:function(){return{options:this.options,cloudClient:this.cloudClient,onDeviceChange:this.onDeviceChange.bind(this),status:this.status.bind(this)}}},{key:"login",value:function(e){return p(this,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.cloudClient.login(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"logout",value:function(){return p(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.cloudClient.logout();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"__getApp",value:function(){return this.cloudClient.__getApp()}},{key:"onAuthStateChanged",value:function(){return this.cloudClient.onAuthStateChanged()}},{key:"addDevice",value:function(e){var t=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"addDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.addDevice(e)}},{key:"removeDevice",value:function(e){var t=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"removeDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.removeDevice(e)}},{key:"transferDevice",value:function(e){var t=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"transferDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.transferDevice(e)}},{key:"onUserDevicesChange",value:function(){var e=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onUserDevicesChange"),2),t=e[0],r=e[1];return t?(0,g.throwError)(function(){return r}):this.cloudClient.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.cloudClient.onUserClaimsChange()}},{key:"getDevices",value:function(){return p(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.cloudClient.getDevices();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"selectDevice",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"selectDevice"),n=u(r,2),i=n[0],o=n[1],!i){t.next=3;break}return t.abrupt("return",Promise.reject(o));case 3:return t.next=5,this.cloudClient.selectDevice(e);case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}},t,this)}))}},{key:"getSelectedDevice",value:function(){return p(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t,r,n,i;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=(0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getSelectedDevice"),r=u(t,2),n=r[0],i=r[1],!n){e.next=3;break}return e.abrupt("return",Promise.reject(i));case 3:return e.next=5,this.cloudClient.getSelectedDevice();case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return p(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t,r,n,i,o=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}return e.abrupt("return",Promise.reject(E.mustSelectDevice));case 4:if(t=(0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getInfo"),r=u(t,2),n=r[0],i=r[1],!n){e.next=7;break}return e.abrupt("return",Promise.reject(i));case 7:return e.next=9,this._withStreamingModePromise({wifi:function(){return o.cloudClient.getInfo()},bluetooth:function(){return o.bluetoothClient.getInfo()}});case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}},e,this)}))}},{key:"onDeviceChange",value:function(){var e=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onDeviceChange"),2),t=e[0],r=e[1];return t?(0,g.throwError)(function(){return r}):this.cloudClient.onDeviceChange()}},{key:"disconnect",value:function(){return p(this,void 0,void 0,regeneratorRuntime.mark(function e(){var t=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._withStreamingModePromise({wifi:function(){return t.cloudClient.disconnect()},bluetooth:function(){return t.bluetoothClient.disconnect()}});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"dispatchAction",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o,s=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}return t.abrupt("return",Promise.reject(E.mustSelectDevice));case 4:if(r=(0,N.validateOAuthScopeForAction)(this.cloudClient.userClaims,e),n=u(r,2),i=n[0],o=n[1],!i){t.next=7;break}return t.abrupt("return",Promise.reject(o));case 7:return t.next=9,this._withStreamingModePromise({wifi:function(){return s.cloudClient.dispatchAction(e)},bluetooth:function(){return s.bluetoothClient.dispatchAction(e)}});case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}},t,this)}))}},{key:"addMarker",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}throw E.mustSelectDevice;case 4:if(e){t.next=6;break}throw new Error("".concat(E.prefix,"A label is required for addMarker"));case 6:return t.next=8,this._withStreamingModePromise({wifi:function(){return r.cloudClient.dispatchAction({command:"marker",action:"add",message:{label:e,timestamp:r.cloudClient.timestamp}})},bluetooth:function(){return r.bluetoothClient.addMarker(e)}});case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}},t,this)}))}},{key:"haptics",value:function(e){var t;return p(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,o,u,s,c,a=this;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return n="haptics",r.next=3,this.cloudClient.didSelectDevice();case 3:if(r.sent){r.next=5;break}return r.abrupt("return",Promise.reject(E.mustSelectDevice));case 5:return r.next=7,this.getSelectedDevice();case 7:if(r.t1=t=r.sent,r.t0=null===r.t1,r.t0){r.next=11;break}r.t0=void 0===t;case 11:if(!r.t0){r.next=15;break}r.t2=void 0,r.next=16;break;case 15:r.t2=t.modelVersion;case 16:if(i=r.t2,T.supportsHaptics(i)){r.next=20;break}return r.abrupt("return",Promise.reject(E.metricNotSupportedByModel(n,i)));case 20:o=T.getPlatformHapticMotors(i),r.t3=regeneratorRuntime.keys(e);case 22:if((r.t4=r.t3()).done){r.next=33;break}if(u=r.t4.value,Object.keys(o).includes(u)){r.next=26;break}return r.abrupt("return",Promise.reject(E.locationNotFound(u,i)));case 26:if(s=e[u],7,!(s.length>7)){r.next=30;break}return r.abrupt("return",Promise.reject(E.exceededMaxItems(7)));case 30:o[u]=s,r.next=22;break;case 33:return c={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}},r.next=36,this._withStreamingModePromise({wifi:function(){return a.cloudClient.dispatchAction(c)},bluetooth:function(){return a.bluetoothClient.dispatchAction(c)}});case 36:return r.abrupt("return",r.sent);case 37:case"end":return r.stop()}},r,this)}))}},{key:"getHapticEffects",value:function(){return A}},{key:"accelerometer",value:function(){var e=this,t="accelerometer",r=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,g.throwError)(function(){return i}):this.onDeviceChange().pipe((0,y.switchMap)(function(r){var n=(null==r?void 0:r.modelVersion)||T.MODEL_VERSION_1;return T.supportsAccel(n)?e._withStreamingModeObservable({wifi:function(){return(0,P.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,x.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.accelerometer()}}):(0,g.throwError)(function(){return E.metricNotSupportedByModel(t,n)})}))}},{key:"brainwaves",value:function(e){var t=this,r=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"brainwaves"),2),n=r[0],i=r[1];return n?(0,g.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,P.getCloudMetric)(t._getCloudMetricDependencies(),{metric:"brainwaves",labels:e?[e]:[],atomic:!1})},bluetooth:function(){return t.bluetoothClient.brainwaves(e)}})}},{key:"calm",value:function(){var e=this,t=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"calm"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,P.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["calm"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.calm()}})}},{key:"signalQuality",value:function(){var e=this,t="signalQuality",r=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,g.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,P.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,x.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.signalQuality()}})}},{key:"settings",value:function(){var e=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"settings"),2),t=e[0],r=e[1];return t?(0,g.throwError)(function(){return r}):this.cloudClient.observeNamespace("settings")}},{key:"osVersion",value:function(){var e=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"osVersion"),2),t=e[0],r=e[1];return t?(0,g.throwError)(function(){return r}):this.cloudClient.osVersion()}},{key:"focus",value:function(){var e=this,t=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"focus"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,P.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["focus"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.focus()}})}},{key:"kinesis",value:function(e){var t=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"kinesis"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):(0,P.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"kinesis",labels:e?[e]:[],atomic:!1})}},{key:"predictions",value:function(e){var t=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"predictions"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):(0,P.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"predictions",labels:e?[e]:[],atomic:!1})}},{key:"status",value:function(){var e=this,t=u((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"status"),2),r=t[0],n=t[1];return r?(0,g.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return e.cloudClient.status()},bluetooth:function(){return e.bluetoothClient.status()}})}},{key:"changeSettings",value:function(e){return p(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}return t.abrupt("return",Promise.reject(E.mustSelectDevice));case 4:if(r=(0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"changeSettings"),n=u(r,2),i=n[0],o=n[1],!i){t.next=7;break}return t.abrupt("return",Promise.reject(o));case 7:return t.next=9,this.cloudClient.changeSettings(e);case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}},t,this)}))}},{key:"goOffline",value:function(){this.cloudClient.goOffline()}},{key:"goOnline",value:function(){this.cloudClient.goOnline()}},{key:"createAccount",value:function(e){return this.cloudClient.createAccount(e)}},{key:"deleteAccount",value:function(){return this.cloudClient.deleteAccount()}},{key:"createBluetoothToken",value:function(){return this.cloudClient.createBluetoothToken()}},{key:"createCustomToken",value:function(){return this.cloudClient.createCustomToken()}},{key:"getTimesyncOffset",value:function(){return this.options.timesync||console.warn("getTimesyncOffset() requires options.timesync to be true."),this.options.timesync?this.cloudClient.getTimesyncOffset():0}},{key:"createOAuthURL",value:function(e){return F.isNode?(0,I.createOAuthURL)(e,this.options):Promise.reject(new Error("".concat(E.prefix,"the createOAuthURL method must be used on the server side (node.js) for security reasons.")))}},{key:"getOAuthToken",value:function(e){return F.isNode?(0,R.getOAuthToken)(e,this.options):Promise.reject(new Error("".concat(E.prefix,"the getOAuthToken method must be used on the server side (node.js) for security reasons.")))}},{key:"removeOAuthAccess",value:function(){return this.cloudClient.removeOAuthAccess()}},{key:"onUserExperiments",value:function(){return this.cloudClient.onUserExperiments()}},{key:"deleteUserExperiment",value:function(e){return this.cloudClient.deleteUserExperiment(e)}},{key:"bluetooth",get:function(){return null==this?void 0:this.bluetoothClient}},{key:"training",get:function(){var e=this;return{record:function(t){return p(e,void 0,void 0,regeneratorRuntime.mark(function e(){var r,n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw E.mustSelectDevice;case 4:return r=this.cloudClient.user&&"uid"in this.cloudClient.user?this.cloudClient.user.uid:null,n=Object.assign(Object.assign({fit:!1,baseline:!1,timestamp:this.cloudClient.timestamp},t),{userId:r}),e.next=8,this.cloudClient.actions.dispatch({command:"training",action:"record",message:n});case 8:case"end":return e.stop()}},e,this)}))},stop:function(t){return p(e,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.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw E.mustSelectDevice;case 4:return e.next=6,this.cloudClient.actions.dispatch({command:"training",action:"stop",message:Object.assign({},t)});case 6:case"end":return e.stop()}},e,this)}))},stopAll:function(){return p(e,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.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw E.mustSelectDevice;case 4:return e.next=6,this.cloudClient.actions.dispatch({command:"training",action:"stopAll",message:{}});case 6:case"end":return e.stop()}},e,this)}))}}}}]),e}();exports.Neurosity=q,q.credentialWithLink=S.credentialWithLink,q.createUser=k.createUser,q.SERVER_TIMESTAMP=S.SERVER_TIMESTAMP;var B=function(e){function r(){var e,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return l(this,r),e=t(this,n(r).call(this,i)),console.log("The Notion class is deprecated and will be removed in the next version of the SDK. Please use the Neurosity class instead. e.g. new Notion() => new Neurosity()"),e}return i(r,q),r}();exports.Notion=B;
|
|
663
663
|
},{"rxjs":"Zr8e","rxjs/operators":"v3iE","fast-deep-equal":"jIGR","./api/index":"LXvB","./types/streaming":"rekm","./utils/subscription":"yLLB","./types/status":"Ttuy","./utils/errors":"WDyG","./utils/platform":"wAkn","./utils/hapticEffects":"lLai","./utils/oauth":"xIH5","./api/https/createOAuthURL":"MDrB","./api/https/getOAuthToken":"nfg4","./utils/is-node":"vsps","./utils/metrics":"DCuD","./api/bluetooth":"TICO","./api/bluetooth/types":"iwtf"}],"QCba":[function(require,module,exports) {
|
|
664
664
|
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&("get"in o?t.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),t=this&&this.__exportStar||function(t,r){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(r,i)||e(r,t,i)};Object.defineProperty(exports,"__esModule",{value:!0}),t(require("./Neurosity"),exports),t(require("./api/bluetooth"),exports);
|
|
665
665
|
},{"./Neurosity":"BZP9","./api/bluetooth":"TICO"}]},{},["QCba"], null)
|