@neurosity/sdk 6.0.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/browser/neurosity.iife.js +44 -113
- package/dist/browser/neurosity.js +8 -14
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/{Notion.d.ts → Neurosity.d.ts} +0 -0
- package/dist/cjs/{Notion.js → Neurosity.js} +0 -47
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +1 -0
- package/dist/cjs/api/bluetooth/BluetoothClient.js +3 -0
- package/dist/cjs/api/bluetooth/BluetoothTransport.d.ts +1 -0
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.d.ts +5 -0
- package/dist/cjs/api/bluetooth/react-native/ReactNativeTransport.js +23 -3
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.d.ts +8 -1
- package/dist/cjs/api/bluetooth/web/WebBluetoothTransport.js +16 -2
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +1 -2
- package/dist/electron/index.js +8 -14
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/{Notion.d.ts → Neurosity.d.ts} +0 -0
- package/dist/esm/{Notion.js → Neurosity.js} +1 -48
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +1 -0
- package/dist/esm/api/bluetooth/BluetoothClient.js +3 -0
- package/dist/esm/api/bluetooth/BluetoothTransport.d.ts +1 -0
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.d.ts +5 -0
- package/dist/esm/api/bluetooth/react-native/ReactNativeTransport.js +23 -3
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.d.ts +8 -1
- package/dist/esm/api/bluetooth/web/WebBluetoothTransport.js +16 -2
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +1 -2
- package/dist/esm/neurosity.mjs +45 -112
- package/dist/examples/neurosity.iife.js +44 -113
- package/dist/examples/neurosity.js +8 -14
- package/dist/examples/neurosity.mjs +45 -112
- package/package.json +1 -1
- package/dist/cjs/skills/NotionOnDevice.d.ts +0 -7
- package/dist/cjs/skills/NotionOnDevice.js +0 -25
- package/dist/cjs/skills/createSkill.d.ts +0 -7
- package/dist/cjs/skills/createSkill.js +0 -40
- package/dist/cjs/skills/index.d.ts +0 -2
- package/dist/cjs/skills/index.js +0 -18
- package/dist/esm/skills/NotionOnDevice.d.ts +0 -7
- package/dist/esm/skills/NotionOnDevice.js +0 -21
- package/dist/esm/skills/createSkill.d.ts +0 -7
- package/dist/esm/skills/createSkill.js +0 -36
- package/dist/esm/skills/index.d.ts +0 -2
- package/dist/esm/skills/index.js +0 -2
|
@@ -647,26 +647,20 @@ var r=require("./compare"),e=function(e,o,u){return r(e,o,u)>=0};module.exports=
|
|
|
647
647
|
},{"./compare":"skdn"}],"rH2Y":[function(require,module,exports) {
|
|
648
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;
|
|
649
649
|
},{"semver/functions/gte":"A2P2"}],"ouKb":[function(require,module,exports) {
|
|
650
|
-
"use strict";function e(e){return n(e)||r(e)||t()}function t(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function r(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)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}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 r=[],n=!0,i=!1,c=void 0;try{for(var a,o=e[Symbol.iterator]();!(n=(a=o.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(s){i=!0,c=s}finally{try{n||null==o.return||o.return()}finally{if(i)throw c}}return r}}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 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&&u(e.prototype,t),r&&u(e,r),e}var h=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,c){function a(e){try{s(n.next(e))}catch(t){c(t)}}function o(e){try{s(n.throw(e))}catch(t){c(t)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(a,o)}s((n=n.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"),N=require("rxjs/operators"),E=require("rxjs/operators"),w=require("./isWebBluetoothSupported"),O=require("../utils/create6DigitPin"),y=require("../utils/stitch"),x=require("../utils/encoding"),C=require("../types"),T=require("../constants"),k=require("../constants"),R=require("../utils/osHasBluetoothSupport"),L=function(){function t(){var e=this;if(s(this,t),this.type=C.TRANSPORT_TYPE.WEB,this.characteristicsByName={},this.connection$=new g.BehaviorSubject(C.BLUETOOTH_CONNECTION.DISCONNECTED),this.pendingActions$=new g.BehaviorSubject([]),this.logs$=new g.ReplaySubject(10),this.onDisconnected$=this._onDisconnected().pipe((0,E.share)()),this.connectionStream$=this.connection$.asObservable().pipe((0,b.filter)(function(e){return!!e}),(0,N.distinctUntilChanged)(),(0,N.shareReplay)(1)),!(0,w.isWebBluetoothSupported)()){throw this.addLog("Web Bluetooth is not supported"),new Error("Web Bluetooth is not supported")}this.connection$.asObservable().subscribe(function(t){e.addLog("connection status is ".concat(t))}),this.onDisconnected$.subscribe(function(){e.connection$.next(C.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(0,g.merge)(e,this.onDisconnected$.pipe((0,b.switchMap)(function(){return e}))).pipe((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 r,n,c,a,o,s,u;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=e.deviceNickname,!this.isConnected()){t.next=4;break}return this.addLog("Auto connect: ".concat(n," 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!==(r=null==o?void 0:o.message)&&void 0!==r?r: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===n})){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(n," 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(C.BLUETOOTH_CONNECTION.SCANNING)}),(0,b.switchMap)(function(e){return A(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:"addLog",value:function(e){this.logs$.next(e)}},{key:"isConnected",value:function(){return this.connection$.getValue()===C.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 r;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 r=t.sent,t.next=6,this.getServerServiceAndCharacteristics(r);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 r(){var n,i,c;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,this.addLog("Requesting Bluetooth Device..."),n=p.BLUETOOTH_DEVICE_NAME_PREFIXES.map(function(e){return{namePrefix:e}}),i=t?[{name:t}]:n,r.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=r.sent,r.abrupt("return",c);case 10:return r.prev=10,r.t0=r.catch(0),r.abrupt("return",Promise.reject(r.t0));case 13:case"end":return r.stop()}},r,this,[[0,10]])}))}},{key:"getServerServiceAndCharacteristics",value:function(e){return h(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,this.device=e,this.connection$.getValue()===C.BLUETOOTH_CONNECTION.CONNECTING||this.connection$.next(C.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:r=t.sent,this.addLog("Got characteristics"),this.characteristicsByName=Object.fromEntries(r.map(function(e){return[k.CHARACTERISTIC_UUIDS_TO_NAMES[e.uuid],e]})),this.connection$.next(C.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===C.BLUETOOTH_CONNECTION.CONNECTED?_(e.device,"gattserverdisconnected"):m.NEVER}))}},{key:"disconnect",value:function(){var e,t;return h(this,void 0,void 0,regeneratorRuntime.mark(function r(){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.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 r.stop()}},r,this)}))}},{key:"getCharacteristicByName",value:function(e){var t;return h(this,void 0,void 0,regeneratorRuntime.mark(function r(){return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",null===(t=this.characteristicsByName)||void 0===t?void 0:t[e]);case 1:case"end":return r.stop()}},r,this)}))}},{key:"subscribeToCharacteristic",value:function(e){var t=this,r=e.characteristicName,n=e.manageNotifications,i=void 0===n||n,c=(0,g.defer)(function(){return t.getCharacteristicByName(r)}).pipe((0,b.switchMap)(function(e){return h(t,void 0,void 0,regeneratorRuntime.mark(function t(){var n;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(r," characteristic")),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),this.addLog("Attemped to stop notifications for ".concat(r," characteristic: ").concat(null!==(n=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==n?n: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 _(e,"characteristicvaluechanged",function(){return h(t,void 0,void 0,regeneratorRuntime.mark(function t(){var n;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(r," characteristic")),t.next=10;break;case 7:t.prev=7,t.t0=t.catch(1),this.addLog("Attemped to stop notifications for ".concat(r," characteristic: ").concat(null!==(n=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==n?n:t.t0));case 10:case"end":return t.stop()}},t,this,[[1,7]])}))})}),(0,b.map)(function(e){var n=e.target.value,i=(0,x.decode)(t.type,n);return t.addLog("Received chunk with buffer size of ".concat(n.byteLength," and decoded size ").concat(i.length," for ").concat(r," characteristic: \n").concat(i)),i}),(0,y.stitchChunks)({delimiter:f.BLUETOOTH_CHUNK_DELIMITER}),(0,b.map)(function(e){var n;try{return JSON.parse(e)}catch(i){return t.addLog("Failed to parse JSON for ".concat(r," characteristic. Falling back to unparsed string. ").concat(null!==(n=null==i?void 0:i.message)&&void 0!==n?n:i)),e}}));return this.connection$.pipe((0,b.switchMap)(function(e){return e===C.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 r(){var n,i,c,a,o;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,this.addLog("Reading characteristic: ".concat(e)),r.next=4,this.getCharacteristicByName(e);case 4:if(n=r.sent){r.next=8;break}return this.addLog("Did not fund ".concat(e," characteristic")),r.abrupt("return",Promise.reject("Did not find characteristic by the name: ".concat(e)));case 8:return r.next=10,n.readValue();case 10:return i=r.sent,c=i,a=(0,x.decode)(this.type,c),o=t?JSON.parse(a):a,this.addLog("Received read data from ".concat(e," characteristic: \n").concat(o)),r.abrupt("return",o);case 18:return r.prev=18,r.t0=r.catch(0),r.abrupt("return",Promise.reject("Error reading characteristic: ".concat(r.t0.message)));case 21:case"end":return r.stop()}},r,this,[[0,18]])}))}},{key:"writeCharacteristic",value:function(e,t){return h(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.addLog("Writing characteristic: ".concat(e)),r.next=3,this.getCharacteristicByName(e);case 3:if(n=r.sent){r.next=7;break}return this.addLog("Did not fund ".concat(e," characteristic")),r.abrupt("return",Promise.reject("Did not find characteristic by the name: ".concat(e)));case 7:return i=(0,x.encode)(this.type,t),r.next=10,n.writeValueWithResponse(i);case 10:case"end":return r.stop()}},r,this)}))}},{key:"_addPendingAction",value:function(t){var r=this.pendingActions$.getValue();this.pendingActions$.next([].concat(e(r),[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 r,n,i,c=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:n=!1,i=this.connection$.asObservable().pipe((0,b.switchMap)(function(e){return e===C.BLUETOOTH_CONNECTION.CONNECTED?(0,g.defer)(function(){return c.getCharacteristicByName("actions")}).pipe((0,b.switchMap)(function(e){return r=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)||n){t.next=12;break}return n=!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!==(i=null===t.t0||void 0===t.t0?void 0:t.t0.message)&&void 0!==i?i:t.t0));case 12:if(a||!n){t.next=23;break}return n=!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!==(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,r=e.action;return h(this,void 0,void 0,regeneratorRuntime.mark(function e(){var n,i,c,a,o=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.responseRequired,i=void 0!==n&&n,c=r.responseTimeout,a=void 0===c?T.DEFAULT_ACTION_RESPONSE_TIMEOUT:c,e.abrupt("return",new Promise(function(e,n){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(){n("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},r)),this.addLog("Dispatched action with id ".concat(o)),i&&a?(this._addPendingAction(o),u=(0,g.timer)(a).subscribe(function(){d._removePendingAction(o),n("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,E.take)(1)).subscribe(function(t){u.unsubscribe(),d._removePendingAction(o),e(t)}),this.writeCharacteristic(t,s).catch(function(e){d._removePendingAction(o),n(e.message)})):this.writeCharacteristic(t,s).then(function(){e(null)}).catch(function(e){n(e.message)});case 9:case"end":return c.stop()}},c,this)}))}));case 2:case"end":return e.stop()}},e)}))}}]),t}();function _(e,t,r){var n=this;return(0,m.fromEventPattern)(function(r){e.addEventListener(t,r)},function(i){return h(n,void 0,void 0,regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(!r){n.next=3;break}return n.next=3,r();case 3:e.removeEventListener(t,i);case 4:case"end":return n.stop()}},n)}))})}function A(e){return new m.Observable(function(t){var r=new AbortController,n=r.signal,i=e.addEventListener("advertisementreceived",function(e){r.abort(),t.next(e),t.complete()},{once:!0});try{e.watchAdvertisements({signal:n})}catch(c){t.error(c)}return function(){r.abort(),e.removeEventListener("advertisementreceived",i)}})}exports.WebBluetoothTransport=L;
|
|
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=_;
|
|
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"),N=require("../utils/encoding"),b=require("../types"),O=require("../constants"),T=require("../constants"),C=require("../constants"),w=require("../constants"),y=require("../utils/osHasBluetoothSupport"),R=function(){function t(e){var n=this;a(this,t),this.type=b.TRANSPORT_TYPE.REACT_NATIVE,this.characteristicsByName={},this.connection$=new l.BehaviorSubject(b.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));var r=e.BleManager,i=e.bleManagerEmitter,c=e.platform;if(!r){var o="React Native option: BleManager not provided.";throw this.addLog(o),new Error(o)}if(!i){var s="React Native option: bleManagerEmitter not provided.";throw this.addLog(s),new Error(s)}if(!c){var u="React Native option: platform not provided.";throw this.addLog(u),new Error(u)}this.BleManager=r,this.bleManagerEmitter=i,this.platform=c,this.bleEvents={stopScan$:this._fromEvent("BleManagerStopScan"),discoverPeripheral$:this._fromEvent("BleManagerDiscoverPeripheral"),connectPeripheral$:this._fromEvent("BleManagerConnectPeripheral"),disconnectPeripheral$:this._fromEvent("BleManagerDisconnectPeripheral"),didUpdateValueForCharacteristic$:this._fromEvent("BleManagerDidUpdateValueForCharacteristic")},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(b.BLUETOOTH_CONNECTION.DISCONNECTED)})}return o(t,[{key:"addLog",value:function(e){this.logs$.next(e)}},{key:"isConnected",value:function(){return this.connection$.getValue()===b.BLUETOOTH_CONNECTION.CONNECTED}},{key:"_autoConnect",value:function(e){var t=this,n=this.onDisconnected$.pipe((0,p.switchMap)(function(){return e}));return(0,l.merge)(e,n).pipe((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:"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=this,a=null!==(t=null==e?void 0:e.seconds)&&void 0!==t?t:10,c=null!==(n=null==e?void 0:e.once)&&void 0!==n&&n,o=[u.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING],s={},d=new v.Observable(function(e){var t;try{r.BleManager.scan(o,a,!0,s).then(function(){r.addLog("BleManger scanning ".concat(c?"once":"indefintely")),e.next()})}catch(n){r.addLog("BleManger scanning ".concat(c?"once":"indefintely"," failed. ").concat(null!==(t=null==n?void 0:n.message)&&void 0!==t?t:n)),e.error(n)}return function(){r.BleManager.stopScan()}});return(c?d:(0,l.timer)(0,1e4).pipe((0,p.switchMap)(function(){return d}))).pipe((0,p.tap)(function(){r.connection$.next(b.BLUETOOTH_CONNECTION.SCANNING)}),(0,p.takeUntil)(this.onDisconnected$),(0,p.switchMap)(function(){return r.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,a,c,o,s,u,d,h,l=null!==(c=null!==(a=null===(n=null==t?void 0:t.advertising)||void 0===n?void 0:n.localName)&&void 0!==a?a:t.name)&&void 0!==c?c:"",v=null===(h=null===(d=(0,N.decode)(r.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;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(b.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("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[T.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=23;break}return this.addLog("Setting Android MTU to ".concat(C.ANDROID_MAX_MTU)),n.next=23,this.BleManager.requestMTU(e.id,C.ANDROID_MAX_MTU);case 23:this.addLog("Successfully connected to peripheral ".concat(e.id)),this.connection$.next(b.BLUETOOTH_CONNECTION.CONNECTED),t(),n.next=31;break;case 28:n.prev=28,n.t0=n.catch(0),r(n.t0);case 31:case"end":return n.stop()}},n,this,[[0,28]])}))}));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===b.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,N.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("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,N.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("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("Did not find characteristic matching ".concat(e)));case 4:return o=(0,N.encode)(this.type,t),n.next=7,this.BleManager.write(i,a,c,o,w.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===b.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("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.message)})):this.writeCharacteristic(t,s).then(function(){e(null)}).catch(function(e){r(e.message)});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 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"),T=require("../constants"),w=require("../constants"),_=require("../utils/osHasBluetoothSupport"),y={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({},y),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,_.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=this,a=null!==(t=null==e?void 0:e.seconds)&&void 0!==t?t:10,c=null!==(n=null==e?void 0:e.once)&&void 0!==n&&n,o=[u.BLUETOOTH_PRIMARY_SERVICE_UUID_STRING],s={},d=new v.Observable(function(e){var t;try{r.BleManager.scan(o,a,!0,s).then(function(){r.addLog("BleManger scanning ".concat(c?"once":"indefintely")),e.next()})}catch(n){r.addLog("BleManger scanning ".concat(c?"once":"indefintely"," failed. ").concat(null!==(t=null==n?void 0:n.message)&&void 0!==t?t:n)),e.error(n)}return function(){r.BleManager.stopScan()}});return(c?d:(0,l.timer)(0,1e4).pipe((0,p.switchMap)(function(){return d}))).pipe((0,p.tap)(function(){r.connection$.next(N.BLUETOOTH_CONNECTION.SCANNING)}),(0,p.takeUntil)(this.onDisconnected$),(0,p.switchMap)(function(){return r.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,a,c,o,s,u,d,h,l=null!==(c=null!==(a=null===(n=null==t?void 0:t.advertising)||void 0===n?void 0:n.localName)&&void 0!==a?a:t.name)&&void 0!==c?c:"",v=null===(h=null===(d=(0,b.decode)(r.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;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("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=23;break}return this.addLog("Setting Android MTU to ".concat(T.ANDROID_MAX_MTU)),n.next=23,this.BleManager.requestMTU(e.id,T.ANDROID_MAX_MTU);case 23:this.addLog("Successfully connected to peripheral ".concat(e.id)),this.connection$.next(N.BLUETOOTH_CONNECTION.CONNECTED),t(),n.next=31;break;case 28:n.prev=28,n.t0=n.catch(0),r(n.t0);case 31:case"end":return n.stop()}},n,this,[[0,28]])}))}));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("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("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("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,w.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,_.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("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.message)})):this.writeCharacteristic(t,s).then(function(){e(null)}).catch(function(e){r(e.message)});case 4:case"end":return a.stop()}},a,this)}))}));case 2:case"end":return e.stop()}},e)}))}}]),t}();exports.ReactNativeTransport=R;
|
|
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"),w=require("./utils/osHasBluetoothSupport"),b=function(){function e(t){var r=this;i(this,e),this.selectedDevice$=new c.ReplaySubject(1),this.isAuthenticated$=new c.ReplaySubject(1);var n=null!=t?t:{},s=n.transport,a=n.selectedDevice$,o=n.createBluetoothToken;if(!s)throw new Error("No bluetooth transport provided.");this.transport=s,a&&a.subscribe(this.selectedDevice$),this.transport._autoConnect(this.selectedDevice$).subscribe({error:function(t){var e;r.transport.addLog("Auto connect: error -> ".concat(null!==(e=null==t?void 0:t.message)&&void 0!==e?e:t))}}),"function"==typeof o?(this.transport.addLog("Auto authentication enabled"),this._autoAuthenticate(o).subscribe()):this.transport.addLog("Auto authentication not enabled"),this.transport._autoToggleActionNotifications(this.selectedDevice$),this._focus$=this._subscribeWhileAuthenticated("focus"),this._calm$=this._subscribeWhileAuthenticated("calm"),this._accelerometer$=this._subscribeWhileAuthenticated("accelerometer"),this._brainwavesRaw$=this._subscribeWhileAuthenticated("raw"),this._brainwavesRawUnfiltered$=this._subscribeWhileAuthenticated("rawUnfiltered"),this._brainwavesPSD$=this._subscribeWhileAuthenticated("psd"),this._brainwavesPowerByBand$=this._subscribeWhileAuthenticated("powerByBand"),this._signalQuality$=this._subscribeWhileAuthenticated("signalQuality"),this._status$=this._subscribeWhileAuthenticated("status"),this._settings$=this._subscribeWhileAuthenticated("settings"),this._wifiNearbyNetworks$=this._subscribeWhileAuthenticated("wifiNearbyNetworks"),this._wifiConnections$=this._subscribeWhileAuthenticated("wifiConnections")}return a(e,[{key:"_autoAuthenticate",value:function(e){var r=this,n=(0,u.timer)(0,36e5).pipe((0,h.tap)(function(){r.transport.addLog("Auto authentication in progress...")}));return this.selectedDevice$.pipe((0,h.switchMap)(function(i){return(0,w.osHasBluetoothSupport)(i)?r.connection().pipe((0,h.switchMap)(function(t){return t===v.BLUETOOTH_CONNECTION.CONNECTED?n:c.EMPTY}),(0,h.switchMap)(function(){return o(r,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.isAuthenticated();case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}),(0,h.tap)(function(n){var i=t(n,1)[0];return o(r,void 0,void 0,regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i){t.next=8;break}return t.next=3,e();case 3:return r=t.sent,t.next=6,this.authenticate(r);case 6:t.next=9;break;case 8:this.transport.addLog("Already authenticated");case 9:case"end":return t.stop()}},t,this)}))})):c.EMPTY}))}},{key:"_hasBluetoothSupport",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function t(){var e;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,(0,u.firstValueFrom)(this.selectedDevice$);case 2:return e=t.sent,t.abrupt("return",(0,w.osHasBluetoothSupport)(e));case 4:case"end":return t.stop()}},t,this)}))}},{key:"authenticate",value:function(e){return o(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,s,a;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._hasBluetoothSupport();case 2:if(r.sent){r.next=7;break}return n="authenticate method: The OS version does not support Bluetooth.",this.transport.addLog(n),r.abrupt("return",Promise.reject(n));case 7:return r.next=9,this.transport.writeCharacteristic("auth",e);case 9:return r.next=11,this.isAuthenticated();case 11:return i=r.sent,s=t(i,1),a=s[0],this.transport.addLog("Authentication ".concat(a?"succeeded":"failed")),this.isAuthenticated$.next(a),r.abrupt("return",i);case 16:case"end":return r.stop()}},r,this)}))}},{key:"isAuthenticated",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r,n,i,s;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.transport.readCharacteristic("auth",!0);case 2:return r=e.sent,n=t(r,2),i=n[0],s=n[1],this.isAuthenticated$.next(i),e.abrupt("return",[i,s]);case 8:case"end":return e.stop()}},e,this)}))}},{key:"scan",value:function(t){if(this.transport instanceof f.ReactNativeTransport)return this.transport.scan(t);if(this.transport instanceof d.WebBluetoothTransport)throw new Error("scan method is compatibly with the React Native transport only");throw new Error("unknown transport")}},{key:"connect",value:function(t){return this.transport instanceof f.ReactNativeTransport?this.transport.connect(t):this.transport instanceof d.WebBluetoothTransport?t?this.transport.connect(t):this.transport.connect():void 0}},{key:"disconnect",value:function(){return this.transport.disconnect()}},{key:"connection",value:function(){return this.transport.connection()}},{key:"logs",value:function(){return this.transport.logs$.asObservable()}},{key:"getDeviceId",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function t(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.transport.readCharacteristic("deviceId"));case 1:case"end":return t.stop()}},t,this)}))}},{key:"_withAuthentication",value:function(t){return o(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._hasBluetoothSupport();case 2:if(e.sent){e.next=7;break}return r="The OS version does not support Bluetooth.",this.transport.addLog(r),e.abrupt("return",Promise.reject(r));case 7:return e.next=9,(0,u.firstValueFrom)(this.isAuthenticated$);case 9:if(e.sent){e.next=14;break}return"Authentication required.",this.transport.addLog("Authentication required."),e.abrupt("return",Promise.reject("Authentication required."));case 14:return e.next=16,t();case 16:return e.abrupt("return",e.sent);case 17:case"end":return e.stop()}},e,this)}))}},{key:"_subscribeWhileAuthenticated",value:function(t){var e=this;return this.selectedDevice$.pipe((0,h.switchMap)(function(r){return(0,w.osHasBluetoothSupport)(r)?e.isAuthenticated$.pipe((0,p.distinctUntilChanged)(),(0,h.switchMap)(function(r){return r?e.transport.subscribeToCharacteristic({characteristicName:t}):c.EMPTY})):c.EMPTY}),(0,h.share)())}},{key:"focus",value:function(){return this._focus$}},{key:"calm",value:function(){return this._calm$}},{key:"accelerometer",value:function(){return this._accelerometer$}},{key:"brainwaves",value:function(t){var e=this;switch(t){default:case"raw":return(0,u.defer)(function(){return e.getInfo()}).pipe((0,h.switchMap)(function(t){return e._brainwavesRaw$.pipe((0,l.csvBufferToEpoch)(t))}));case"rawUnfiltered":return(0,u.defer)(function(){return e.getInfo()}).pipe((0,h.switchMap)(function(t){return e._brainwavesRawUnfiltered$.pipe((0,l.csvBufferToEpoch)(t))}));case"psd":return this._brainwavesPSD$;case"powerByBand":return this._brainwavesPowerByBand$}}},{key:"signalQuality",value:function(){return this._signalQuality$}},{key:"addMarker",value:function(t){return o(this,void 0,void 0,regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.dispatchAction({action:"marker",command:"add",message:{timestamp:Date.now(),label:t}});case 2:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return o(this,void 0,void 0,regeneratorRuntime.mark(function t(){var e=this;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this._withAuthentication(function(){return(0,u.firstValueFrom)(e.transport.subscribeToCharacteristic({characteristicName:"deviceInfo"}))});case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"status",value:function(){return this._status$}},{key:"dispatchAction",value:function(t){return o(this,void 0,void 0,regeneratorRuntime.mark(function e(){var r=this;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._withAuthentication(function(){return r.transport.dispatchAction({characteristicName:"actions",action:t})});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"settings",value:function(){return this._settings$}},{key:"haptics",value:function(t){return this.dispatchAction({action:"haptics",command:"queue",responseRequired:!0,responseTimeout:4e3,message:{effects:t}})}},{key:"wifi",get:function(){var t=this;return{nearbyNetworks:function(){return t._wifiNearbyNetworks$},connections:function(){return t._wifiConnections$},connect:function(e,r){return e?t.dispatchAction({action:"wifi",command:"connect",responseRequired:!0,responseTimeout:12e4,message:{ssid:e,password:null!=r?r:null}}):Promise.reject("Missing ssid")},forgetConnection:function(e){return e?t.dispatchAction({action:"wifi",command:"forget-connection",responseRequired:!0,responseTimeout:15e3,message:{ssid:e}}):Promise.reject("Missing ssid")},reset:function(){return t.dispatchAction({action:"wifi",command:"reset",responseRequired:!0,responseTimeout:3e4,message:{respondOnSuccess:!0}})},speedTest:function(){return t.dispatchAction({action:"wifi",command:"speed-test",responseRequired:!0,responseTimeout:6e4})}}}}]),e}();exports.BluetoothClient=b;
|
|
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;
|
|
659
659
|
},{"rxjs":"Zr8e","rxjs/operators":"v3iE","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/csvBufferToEpoch":"WTrV","./types":"iwtf","./utils/osHasBluetoothSupport":"rH2Y"}],"TICO":[function(require,module,exports) {
|
|
660
660
|
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),t=this&&this.__exportStar||function(t,r){for(var o in t)"default"===o||Object.prototype.hasOwnProperty.call(r,o)||e(r,t,o)};Object.defineProperty(exports,"__esModule",{value:!0}),t(require("./BluetoothClient"),exports),t(require("./web/WebBluetoothTransport"),exports),t(require("./react-native/ReactNativeTransport"),exports),t(require("./utils/osHasBluetoothSupport"),exports);
|
|
661
|
-
},{"./BluetoothClient":"fihV","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/osHasBluetoothSupport":"rH2Y"}],"
|
|
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,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function c(e,t){return l(e)||a(e,t)||s()}function s(){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 r=[],n=!0,i=!1,o=void 0;try{for(var u,c=e[Symbol.iterator]();!(n=(u=c.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(s){i=!0,o=s}finally{try{n||null==c.return||c.return()}finally{if(i)throw o}}return r}}function l(e){if(Array.isArray(e))return e}function d(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 f(e,t,r){return t&&h(e.prototype,t),r&&h(e,r),e}var m=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]}),v=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),p=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)&&m(t,e,r);return v(t,e),t},b=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function u(e){try{s(n.next(e))}catch(t){o(t)}}function c(e){try{s(n.throw(e))}catch(t){o(t)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,c)}s((n=n.apply(e,t||[])).next())})},g=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 C=require("rxjs"),y=require("rxjs"),w=require("rxjs/operators"),k=g(require("fast-deep-equal")),O=require("./api/index"),S=require("./api/index"),x=require("./types/streaming"),M=require("./utils/subscription"),_=require("./types/status"),E=p(require("./utils/errors")),T=p(require("./utils/platform")),A=p(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:x.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]:{};d(this,e),this.streamingMode$=new y.ReplaySubject(1);var r=t.streamingMode,n=t.bluetoothTransport;this.options=Object.freeze(Object.assign(Object.assign({},U),t)),this.cloudClient=new O.CloudClient(this.options),n&&(this.bluetoothClient=new j.BluetoothClient({selectedDevice$:this.onDeviceChange(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:n})),this._initStreamingMode(r,!!n)}return f(e,[{key:"_initStreamingMode",value:function(e,t){var r=[x.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,x.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),n=!Object.values(x.STREAMING_MODE).includes(e),i=r&&!t;this.isMissingBluetoothTransport=i,!e||n||i?this.streamingMode$.next(x.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,w.switchMap)(function(r){return e.isMissingBluetoothTransport?e.cloudClient.status().pipe((0,w.map)(function(e){var n=e.state;return{connected:t(n),streamingMode:r,activeMode:x.STREAMING_TYPE.WIFI}})):e.onDeviceChange().pipe((0,w.switchMap)(function(n){return n?(0,C.combineLatest)({wifiStatus:e.cloudClient.status(),bluetoothConnection:(null==e?void 0:e.bluetoothClient)?e.bluetoothClient.connection():(0,C.of)(L.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe((0,w.map)(function(e){var n=e.wifiStatus,i=e.bluetoothConnection===L.BLUETOOTH_CONNECTION.CONNECTED;switch(r){default:case x.STREAMING_MODE.WIFI_ONLY:return{connected:t(n.state),streamingMode:r,activeMode:x.STREAMING_TYPE.WIFI};case x.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:t(n.state)||!i?t(n.state):i,streamingMode:r,activeMode:t(n.state)||!i?x.STREAMING_TYPE.WIFI:x.STREAMING_TYPE.BLUETOOTH};case x.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!i||t(n.state),streamingMode:r,activeMode:i?x.STREAMING_TYPE.BLUETOOTH:x.STREAMING_TYPE.WIFI}}}),(0,w.distinctUntilChanged)(function(e,t){return(0,k.default)(e,t)})):y.EMPTY}))}))}},{key:"_withStreamingModeObservable",value:function(e){var t=e.wifi,r=e.bluetooth;return this.streamingState().pipe((0,w.switchMap)(function(e){switch(e.activeMode){case x.STREAMING_TYPE.WIFI:return t();case x.STREAMING_TYPE.BLUETOOTH:return r();default:return t()}}))}},{key:"_withStreamingModePromise",value:function(e){return b(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,y.firstValueFrom)(this.streamingState());case 3:i=t.sent,o=i.activeMode,t.t0=o,t.next=t.t0===x.STREAMING_TYPE.WIFI?8:t.t0===x.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 b(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 b(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=c((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=c((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=c((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=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onUserDevicesChange"),2),t=e[0],r=e[1];return t?(0,C.throwError)(function(){return r}):this.cloudClient.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.cloudClient.onUserClaimsChange()}},{key:"getDevices",value:function(){return b(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 b(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=c(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 b(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=c(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 b(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=c(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=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onDeviceChange"),2),t=e[0],r=e[1];return t?(0,C.throwError)(function(){return r}):this.cloudClient.onDeviceChange()}},{key:"disconnect",value:function(){return b(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 b(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n,i,o,u=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=c(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 u.cloudClient.dispatchAction(e)},bluetooth:function(){return u.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 b(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 b(this,void 0,void 0,regeneratorRuntime.mark(function r(){var n,i,o,u,c,s,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(c=e[u],7,!(c.length>7)){r.next=30;break}return r.abrupt("return",Promise.reject(E.exceededMaxItems(7)));case 30:o[u]=c,r.next=22;break;case 33:return s={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}},r.next=36,this._withStreamingModePromise({wifi:function(){return a.cloudClient.dispatchAction(s)},bluetooth:function(){return a.bluetoothClient.dispatchAction(s)}});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=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,C.throwError)(function(){return i}):this.onDeviceChange().pipe((0,w.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,M.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.accelerometer()}}):(0,C.throwError)(function(){return E.metricNotSupportedByModel(t,n)})}))}},{key:"brainwaves",value:function(e){var t=this,r=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"brainwaves"),2),n=r[0],i=r[1];return n?(0,C.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=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"calm"),2),r=t[0],n=t[1];return r?(0,C.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=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,C.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,P.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,M.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.signalQuality()}})}},{key:"settings",value:function(){var e=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"settings"),2),t=e[0],r=e[1];return t?(0,C.throwError)(function(){return r}):this.cloudClient.observeNamespace("settings")}},{key:"focus",value:function(){var e=this,t=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"focus"),2),r=t[0],n=t[1];return r?(0,C.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=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"kinesis"),2),r=t[0],n=t[1];return r?(0,C.throwError)(function(){return n}):(0,P.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"kinesis",labels:e?[e]:[],atomic:!1})}},{key:"predictions",value:function(e){var t=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"predictions"),2),r=t[0],n=t[1];return r?(0,C.throwError)(function(){return n}):(0,P.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"predictions",labels:e?[e]:[],atomic:!1})}},{key:"status",value:function(){var e=this,t=c((0,D.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"status"),2),r=t[0],n=t[1];return r?(0,C.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return e.cloudClient.status()},bluetooth:function(){return e.bluetoothClient.status()}})}},{key:"changeSettings",value:function(e){return b(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=c(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:"skill",value:function(e){return b(this,void 0,void 0,regeneratorRuntime.mark(function t(){var r,n=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:return t.next=6,this.cloudClient.skills.get(e);case 6:if(null!==(r=t.sent)){t.next=9;break}return t.abrupt("return",Promise.reject(new Error("".concat(E.prefix,"Access denied for: ").concat(e,". Make sure the skill is installed."))));case 9:return t.abrupt("return",{metric:function(e){var t="skill~".concat(r.id,"~").concat(e),i=new C.Observable(function(r){var i=n.cloudClient.metrics.subscribe({metric:t,labels:[e],atomic:!0}),o=n.cloudClient.metrics.on(i,function(){r.next.apply(r,arguments)});return function(){n.cloudClient.metrics.unsubscribe(i,o)}}).pipe((0,w.map)(function(t){return t[e]}));return Object.defineProperty(i,"next",{value:function(r){n.cloudClient.metrics.next(t,u({},e,r))}}),i}});case 10:case"end":return t.stop()}},t,this)}))}},{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 b(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 b(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 b(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=O.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 d(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
|
-
},{"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"}],"
|
|
664
|
-
"use strict";var
|
|
665
|
-
},{"
|
|
666
|
-
"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,u=void 0;try{for(var o,a=e[Symbol.iterator]();!(n=(o=a.next()).done)&&(r.push(o.value),!t||r.length!==t);n=!0);}catch(c){i=!0,u=c}finally{try{n||null==a.return||a.return()}finally{if(i)throw u}}return r}}function n(e){if(Array.isArray(e))return e}var i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,u){function o(e){try{c(n.next(e))}catch(t){u(t)}}function a(e){try{c(n.throw(e))}catch(t){u(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(o,a)}c((n=n.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.createSkill=void 0;var u=require("./NotionOnDevice");function o(t){var r=this;return{subscribe:function(n){return i(r,void 0,void 0,regeneratorRuntime.mark(function r(){var o,a,c,s,f,p=this;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,(0,u.createNotionOnDevice)(Object.assign({},n));case 2:return o=r.sent,a=e(o,2),c=a[0],s=a[1],f=t(c,s),r.abrupt("return",{unsubscribe:function(){return i(p,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,c.disconnect();case 2:if(!(f&&"then"in f)){e.next=7;break}return e.next=5,f;case 5:"function"==typeof(t=e.sent)&&t();case 7:if(!("function"==typeof f&&"then"in f())){e.next=11;break}return e.next=10,f();case 10:return e.abrupt("return",e.sent);case 11:if("function"!=typeof f){e.next=13;break}return e.abrupt("return",f());case 13:return e.abrupt("return",f);case 14:case"end":return e.stop()}},e)}))}});case 8:case"end":return r.stop()}},r)}))}}}exports.createSkill=o;
|
|
667
|
-
},{"./NotionOnDevice":"DCNc"}],"d8ek":[function(require,module,exports) {
|
|
668
|
-
"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("./createSkill"),exports),t(require("./NotionOnDevice"),exports);
|
|
669
|
-
},{"./createSkill":"T9Vd","./NotionOnDevice":"DCNc"}],"QCba":[function(require,module,exports) {
|
|
670
|
-
"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("./Notion"),exports),t(require("./api/bluetooth"),exports),t(require("./skills"),exports);
|
|
671
|
-
},{"./Notion":"KQ4u","./api/bluetooth":"TICO","./skills":"d8ek"}]},{},["QCba"], null)
|
|
661
|
+
},{"./BluetoothClient":"fihV","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/osHasBluetoothSupport":"rH2Y"}],"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)||s(e,t)||c()}function c(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function s(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,c=e[Symbol.iterator]();!(n=(u=c.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(s){i=!0,o=s}finally{try{n||null==c.return||c.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{s(n.next(e))}catch(t){o(t)}}function c(e){try{s(n.throw(e))}catch(t){o(t)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,c)}s((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.isMissingBluetoothTransport?e.cloudClient.status().pipe((0,y.map)(function(e){var n=e.state;return{connected:t(n),streamingMode:r,activeMode:S.STREAMING_TYPE.WIFI}})):e.onDeviceChange().pipe((0,y.switchMap)(function(n){return n?(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,c=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 c.cloudClient.dispatchAction(e)},bluetooth:function(){return c.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,c,s,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(c=e[u],7,!(c.length>7)){r.next=30;break}return r.abrupt("return",Promise.reject(x.exceededMaxItems(7)));case 30:o[u]=c,r.next=22;break;case 33:return s={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}},r.next=36,this._withStreamingModePromise({wifi:function(){return a.cloudClient.dispatchAction(s)},bluetooth:function(){return a.bluetoothClient.dispatchAction(s)}});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;
|
|
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
|
+
"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
|
+
},{"./Neurosity":"BZP9","./api/bluetooth":"TICO"}]},{},["QCba"], null)
|
|
672
666
|
//# sourceMappingURL=/neurosity.js.map
|