@neurosity/sdk 6.5.0 → 6.5.1

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.
@@ -42939,10 +42939,11 @@ var Neurosity = (function (exports) {
42939
42939
  })(SLEEP_MODE_REASON || (SLEEP_MODE_REASON = {}));
42940
42940
 
42941
42941
  const HEARTBEAT_UPDATE_INTERVAL = 30000; // 30 seconds - set by the OS
42942
- const LOST_HEARTBEAT_AFTER = HEARTBEAT_UPDATE_INTERVAL * 2.5; // 75 seconds
42942
+ const LOST_LOCAL_HEARTBEAT_AFTER = HEARTBEAT_UPDATE_INTERVAL * 2.5; // 75 seconds
42943
+ const LOST_REMOTE_HEARTBEAT_AFTER = 8.64e7; // 24 hours
42943
42944
  function heartbeatAwareStatus(status$) {
42944
42945
  const lastLocalHeartbeat$ = status$.pipe(map(({ lastHeartbeat }) => lastHeartbeat), distinctUntilChanged(), map(() => Date.now()));
42945
- const lostHeartbeat$ = lastLocalHeartbeat$.pipe(switchMap(() => timer(LOST_HEARTBEAT_AFTER)), map(() => null), startWith(null));
42946
+ const lostHeartbeat$ = lastLocalHeartbeat$.pipe(switchMap(() => timer(LOST_LOCAL_HEARTBEAT_AFTER)), map(() => null), startWith(null));
42946
42947
  return combineLatest({
42947
42948
  status: status$,
42948
42949
  lostHeartbeat: lostHeartbeat$ // @important - do not remove, adeed for state synchronization, value not used
@@ -42963,8 +42964,17 @@ var Neurosity = (function (exports) {
42963
42964
  // implementation that used the server timestamp had bug where SDK clients
42964
42965
  // running on hardware with drifted/out-of-sync clocks (cough cough Android)
42965
42966
  // would override the state to offline when the heartbeat was active.
42966
- const lostHeartbeat = Date.now() - lastLocalHeartbeat > LOST_HEARTBEAT_AFTER;
42967
- return lostHeartbeat;
42967
+ const lostLocalHeartbeat = Date.now() - lastLocalHeartbeat > LOST_LOCAL_HEARTBEAT_AFTER;
42968
+ if (lostLocalHeartbeat) {
42969
+ return true;
42970
+ }
42971
+ // Addresses devices with wrongful "online" state. This rarely happens, the
42972
+ // OS would have to crash without updating the state to "offline".
42973
+ const lostRemoteHeartbeat = Date.now() - status.lastHeartbeat > LOST_REMOTE_HEARTBEAT_AFTER;
42974
+ if (lostRemoteHeartbeat) {
42975
+ return true;
42976
+ }
42977
+ return false;
42968
42978
  }
42969
42979
 
42970
42980
  function filterInternalKeys() {
@@ -50117,7 +50127,11 @@ var Neurosity = (function (exports) {
50117
50127
  osHasBluetoothSupport: this._osHasBluetoothSupport()
50118
50128
  }).pipe(switchMap(({ selectedDevice, osHasBluetoothSupport: osHasBluetoothSupport$$1 }) => {
50119
50129
  if (!selectedDevice) {
50120
- return EMPTY;
50130
+ return of({
50131
+ connected: false,
50132
+ streamingMode,
50133
+ activeMode: STREAMING_TYPE.WIFI
50134
+ });
50121
50135
  }
50122
50136
  const isUnableToUseBluetooth = this.isMissingBluetoothTransport || !osHasBluetoothSupport$$1;
50123
50137
  if (isUnableToUseBluetooth) {
@@ -520,7 +520,7 @@ var r=Array.isArray;function n(n){if(r(n))return t(n);var e=null,u="string"==typ
520
520
  },{}],"Ttuy":[function(require,module,exports) {
521
521
  "use strict";var t,e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.SLEEP_MODE_REASON=exports.STATUS=void 0,function(t){t.ONLINE="online",t.OFFLINE="offline",t.UPDATING="updating",t.BOOTING="booting",t.SHUTTING_OFF="shuttingOff"}(t=exports.STATUS||(exports.STATUS={})),function(t){t.UPDATING="updating",t.CHARGING="charging"}(e=exports.SLEEP_MODE_REASON||(exports.SLEEP_MODE_REASON={}));
522
522
  },{}],"ImaE":[function(require,module,exports) {
523
- "use strict";function t(t,n){return i(t)||a(t,n)||r(t,n)||e()}function e(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function r(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function a(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,a,i,u,o=[],s=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(o.push(n.value),o.length!==e);s=!0);}catch(c){l=!0,a=c}finally{try{if(!s&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(l)throw a}}return o}}function i(t){if(Array.isArray(t))return t}var u=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.deviceHasLostHeartbeat=exports.heartbeatAwareStatus=void 0;var o=require("rxjs"),s=require("rxjs/operators"),l=require("rxjs/operators"),c=u(require("fast-deep-equal")),f=require("../types/status"),p=3e4,b=2.5*p;function d(e){var r=e.pipe((0,s.map)(function(t){return t.lastHeartbeat}),(0,l.distinctUntilChanged)(),(0,s.map)(function(){return Date.now()})),n=r.pipe((0,s.switchMap)(function(){return(0,o.timer)(b)}),(0,s.map)(function(){return null}),(0,s.startWith)(null));return(0,o.combineLatest)({status:e,lostHeartbeat:n}).pipe((0,l.withLatestFrom)(r),(0,s.map)(function(e){var r=t(e,2),n=r[0].status,a=r[1];return a&&y(n,a)?Object.assign(Object.assign({},n),{state:f.STATUS.OFFLINE}):n}),(0,l.distinctUntilChanged)(function(t,e){return(0,c.default)(t,e)}))}function y(t,e){return"lastHeartbeat"in t&&Date.now()-e>b}exports.heartbeatAwareStatus=d,exports.deviceHasLostHeartbeat=y;
523
+ "use strict";function t(t,n){return i(t)||a(t,n)||r(t,n)||e()}function e(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function r(t,e){if(t){if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(t,e):void 0}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function a(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,a,i,u,o=[],s=!0,l=!1;try{if(i=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=i.call(r)).done)&&(o.push(n.value),o.length!==e);s=!0);}catch(c){l=!0,a=c}finally{try{if(!s&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(l)throw a}}return o}}function i(t){if(Array.isArray(t))return t}var u=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.deviceHasLostHeartbeat=exports.heartbeatAwareStatus=void 0;var o=require("rxjs"),s=require("rxjs/operators"),l=require("rxjs/operators"),c=u(require("fast-deep-equal")),f=require("../types/status"),p=3e4,b=2.5*p,d=864e5;function y(e){var r=e.pipe((0,s.map)(function(t){return t.lastHeartbeat}),(0,l.distinctUntilChanged)(),(0,s.map)(function(){return Date.now()})),n=r.pipe((0,s.switchMap)(function(){return(0,o.timer)(b)}),(0,s.map)(function(){return null}),(0,s.startWith)(null));return(0,o.combineLatest)({status:e,lostHeartbeat:n}).pipe((0,l.withLatestFrom)(r),(0,s.map)(function(e){var r=t(e,2),n=r[0].status,a=r[1];return a&&h(n,a)?Object.assign(Object.assign({},n),{state:f.STATUS.OFFLINE}):n}),(0,l.distinctUntilChanged)(function(t,e){return(0,c.default)(t,e)}))}function h(t,e){return"lastHeartbeat"in t&&(Date.now()-e>b||!!(Date.now()-t.lastHeartbeat>d))}exports.heartbeatAwareStatus=y,exports.deviceHasLostHeartbeat=h;
524
524
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE","fast-deep-equal":"jIGR","../types/status":"Ttuy"}],"qny3":[function(require,module,exports) {
525
525
  "use strict";function r(r,n){return i(r)||o(r,n)||e(r,n)||t()}function t(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function e(r,t){if(r){if("string"==typeof r)return n(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?n(r,t):void 0}}function n(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function o(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,i,u,a=[],l=!0,c=!1;try{if(i=(e=e.call(r)).next,0===t){if(Object(e)!==e)return;l=!1}else for(;!(l=(n=i.call(e)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(f){c=!0,o=f}finally{try{if(!l&&null!=e.return&&(u=e.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}function i(r){if(Array.isArray(r))return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.filterInternalKeys=void 0;var u=require("rxjs"),a=require("rxjs/operators");function l(){return(0,u.pipe)((0,a.map)(function(t){return t?Object.entries(t).reduce(function(t,e){var n=r(e,2),o=n[0],i=n[1];return o.startsWith("__")||(t[o]=i),t},{}):t}))}exports.filterInternalKeys=l;
526
526
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE"}],"LXvB":[function(require,module,exports) {
@@ -675,7 +675,7 @@ var r=require("./compare"),e=function(e,o,u){return r(e,o,u)>=0};module.exports=
675
675
  "use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),t=this&&this.__exportStar||function(t,r){for(var o in t)"default"===o||Object.prototype.hasOwnProperty.call(r,o)||e(r,t,o)};Object.defineProperty(exports,"__esModule",{value:!0}),t(require("./BluetoothClient"),exports),t(require("./web/WebBluetoothTransport"),exports),t(require("./react-native/ReactNativeTransport"),exports),t(require("./utils/osHasBluetoothSupport"),exports),t(require("./types/index"),exports);
676
676
  },{"./BluetoothClient":"fihV","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/osHasBluetoothSupport":"rH2Y","./types/index":"iwtf"}],"BZP9":[function(require,module,exports) {
677
677
  var define;
678
- var e;function t(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}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&r(e,t)}function r(e,t){return(r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function n(e){var t=u();return function(){var r,n=c(e);if(t){var o=c(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return i(this,r)}}function i(e,t){if(t&&("object"===a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return o(e)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e){return(a="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})(e)}function s(e,t){return p(e)||d(e,t)||h(e,t)||l()}function l(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(e,t){if(e){if("string"==typeof e)return f(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,t):void 0}}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,u,c=[],a=!0,s=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;a=!1}else for(;!(a=(n=o.call(r)).done)&&(c.push(n.value),c.length!==t);a=!0);}catch(l){s=!0,i=l}finally{try{if(!a&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(s)throw i}}return c}}function p(e){if(Array.isArray(e))return e}function v(){"use strict";v=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(A){s=function(e,t,r){return e[t]=r}}function l(e,t,r,i){var o=t&&t.prototype instanceof d?t:d,u=Object.create(o.prototype),c=new _(i||[]);return n(u,"_invoke",{value:S(e,r,c)}),u}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(A){return{type:"throw",arg:A}}}e.wrap=l;var f={};function d(){}function p(){}function m(){}var y={};s(y,o,function(){return this});var b=Object.getPrototypeOf,g=b&&b(b(M([])));g&&g!==t&&r.call(g,o)&&(y=g);var w=m.prototype=d.prototype=Object.create(y);function C(e){["next","throw","return"].forEach(function(t){s(e,t,function(e){return this._invoke(t,e)})})}function O(e,t){var i;n(this,"_invoke",{value:function(n,o){function u(){return new t(function(i,u){!function n(i,o,u,c){var s=h(e[i],e,o);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==a(f)&&r.call(f,"__await")?t.resolve(f.__await).then(function(e){n("next",e,u,c)},function(e){n("throw",e,u,c)}):t.resolve(f).then(function(e){l.value=e,u(l)},function(e){return n("throw",e,u,c)})}c(s.arg)}(n,o,i,u)})}return i=i?i.then(u,u):u()}})}function S(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return T()}for(r.method=i,r.arg=o;;){var u=r.delegate;if(u){var c=x(u,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var a=h(e,t,r);if("normal"===a.type){if(n=r.done?"completed":"suspendedYield",a.arg===f)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n="completed",r.method="throw",r.arg=a.arg)}}}function x(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,f;var o=i.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,f):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function k(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function M(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:T}}function T(){return{value:void 0,done:!0}}return p.prototype=m,n(w,"constructor",{value:m,configurable:!0}),n(m,"constructor",{value:p,configurable:!0}),p.displayName=s(m,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,s(e,c,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},C(O.prototype),s(O.prototype,u,function(){return this}),e.AsyncIterator=O,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new O(l(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then(function(e){return e.done?e.value:u.next()})},C(w),s(w,c,"Generator"),s(w,o,function(){return this}),s(w,"toString",function(){return"[object Generator]"}),e.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=M,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return u.type="throw",u.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var c=r.call(o,"catchLoc"),a=r.call(o,"finallyLoc");if(c&&a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=e,u.arg=t,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(u)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),f},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),E(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;E(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:M(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function y(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,g(n.key),n)}}function b(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function g(e){var t=w(e,"string");return"symbol"===a(t)?t:String(t)}function w(e,t){if("object"!==a(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var C=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]}),O=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),S=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)&&C(t,e,r);return O(t,e),t},x=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function u(e){try{a(n.next(e))}catch(t){o(t)}}function c(e){try{a(n.throw(e))}catch(t){o(t)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,c)}a((n=n.apply(e,t||[])).next())})},k=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 E=require("rxjs"),_=require("rxjs"),M=require("rxjs/operators"),T=require("rxjs/operators"),A=k(require("fast-deep-equal")),D=require("./api/index"),N=require("./api/index"),j=require("./types/streaming"),I=require("./utils/subscription"),P=require("./types/status"),F=S(require("./utils/errors")),L=S(require("./utils/platform")),R=S(require("./utils/hapticEffects")),B=require("./utils/oauth"),U=require("./utils/oauth"),G=require("./api/https/createOAuthURL"),q=require("./api/https/getOAuthToken"),H=require("./utils/is-node"),W=require("./utils/metrics"),Y=require("./api/bluetooth"),V=require("./api/bluetooth/types"),$={timesync:!1,autoSelectDevice:!0,streamingMode:j.STREAMING_MODE.WIFI_ONLY,emulator:!1,emulatorHost:"localhost",emulatorAuthPort:9099,emulatorDatabasePort:9e3,emulatorFunctionsPort:5001,emulatorFirestorePort:8080,emulatorOptions:{}},K=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m(this,e),this.streamingMode$=new _.ReplaySubject(1);var r=t.streamingMode,n=t.bluetoothTransport;this.options=Object.freeze(Object.assign(Object.assign({},$),t)),this.cloudClient=new D.CloudClient(this.options),n&&(this.bluetoothClient=new Y.BluetoothClient({selectedDevice$:this.onDeviceChange(),osHasBluetoothSupport$:this._osHasBluetoothSupport(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:n})),this._initStreamingMode(r,!!n)}return b(e,[{key:"_initStreamingMode",value:function(e,t){var r=[j.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,j.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),n=!Object.values(j.STREAMING_MODE).includes(e),i=r&&!t;this.isMissingBluetoothTransport=i,!e||n||i?this.streamingMode$.next(j.STREAMING_MODE.WIFI_ONLY):this.streamingMode$.next(e)}},{key:"_osHasBluetoothSupport",value:function(){return(0,E.combineLatest)({selectedDevice:this.onDeviceChange(),osVersion:this.osVersion().pipe((0,M.startWith)(null))}).pipe((0,M.map)(function(e){var t=e.selectedDevice,r=e.osVersion;return(0,Y.osHasBluetoothSupport)(t,r)}))}},{key:"streamingState",value:function(){var e=this,t=function(e){return[P.STATUS.ONLINE,P.STATUS.UPDATING].includes(e)};return this.streamingMode$.pipe((0,M.switchMap)(function(r){return(0,E.combineLatest)({selectedDevice:e.onDeviceChange(),osHasBluetoothSupport:e._osHasBluetoothSupport()}).pipe((0,M.switchMap)(function(n){var i=n.selectedDevice,o=n.osHasBluetoothSupport;return i?e.isMissingBluetoothTransport||!o?e.cloudClient.status().pipe((0,M.map)(function(e){var n=e.state;return{connected:t(n),streamingMode:r,activeMode:j.STREAMING_TYPE.WIFI}})):(0,E.combineLatest)({wifiStatus:e.cloudClient.status(),bluetoothConnection:(null==e?void 0:e.bluetoothClient)?e.bluetoothClient.connection():(0,E.of)(V.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe((0,M.map)(function(e){var n=e.wifiStatus,i=e.bluetoothConnection===V.BLUETOOTH_CONNECTION.CONNECTED;switch(r){default:case j.STREAMING_MODE.WIFI_ONLY:return{connected:t(n.state),streamingMode:r,activeMode:j.STREAMING_TYPE.WIFI};case j.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:t(n.state)||!i?t(n.state):i,streamingMode:r,activeMode:t(n.state)||!i?j.STREAMING_TYPE.WIFI:j.STREAMING_TYPE.BLUETOOTH};case j.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!i||t(n.state),streamingMode:r,activeMode:i?j.STREAMING_TYPE.BLUETOOTH:j.STREAMING_TYPE.WIFI}}}),(0,T.distinctUntilChanged)(function(e,t){return(0,A.default)(e,t)})):_.EMPTY}))}))}},{key:"_withStreamingModeObservable",value:function(e){var t=e.wifi,r=e.bluetooth;return this.streamingState().pipe((0,M.switchMap)(function(e){switch(e.activeMode){case j.STREAMING_TYPE.WIFI:return t();case j.STREAMING_TYPE.BLUETOOTH:return r();default:return t()}}))}},{key:"_withStreamingModePromise",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.wifi,n=e.bluetooth,t.next=3,(0,_.firstValueFrom)(this.streamingState());case 3:i=t.sent,o=i.activeMode,t.t0=o,t.next=t.t0===j.STREAMING_TYPE.WIFI?8:t.t0===j.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:"bluetooth",get:function(){return null==this?void 0:this.bluetoothClient}},{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 x(this,void 0,void 0,v().mark(function t(){return v().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 x(this,void 0,void 0,v().mark(function e(){return v().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=s((0,B.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=s((0,B.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=s((0,B.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=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onUserDevicesChange"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.cloudClient.onUserClaimsChange()}},{key:"getDevices",value:function(){return x(this,void 0,void 0,v().mark(function e(){return v().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 x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"selectDevice"),n=s(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 x(this,void 0,void 0,v().mark(function e(){var t,r,n,i;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getSelectedDevice"),r=s(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 x(this,void 0,void 0,v().mark(function e(){var t,r,n,i,o=this;return v().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(F.mustSelectDevice));case 4:if(t=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getInfo"),r=s(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=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onDeviceChange"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.onDeviceChange()}},{key:"disconnect",value:function(){return x(this,void 0,void 0,v().mark(function e(){var t=this;return v().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 x(this,void 0,void 0,v().mark(function t(){var r,n,i,o,u=this;return v().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(F.mustSelectDevice));case 4:if(r=(0,U.validateOAuthScopeForAction)(this.cloudClient.userClaims,e),n=s(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 x(this,void 0,void 0,v().mark(function t(){var r=this;return v().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 F.mustSelectDevice;case 4:if(e){t.next=6;break}throw new Error("".concat(F.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 x(this,void 0,void 0,v().mark(function r(){var n,i,o,u,c,a,s=this;return v().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(F.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,L.supportsHaptics(i)){r.next=20;break}return r.abrupt("return",Promise.reject(F.metricNotSupportedByModel(n,i)));case 20:o=L.getPlatformHapticMotors(i),r.t3=v().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(F.locationNotFound(u,i)));case 26:if(c=e[u],7,!(c.length>7)){r.next=30;break}return r.abrupt("return",Promise.reject(F.exceededMaxItems(7)));case 30:o[u]=c,r.next=22;break;case 33:return a={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}},r.next=36,this._withStreamingModePromise({wifi:function(){return s.cloudClient.dispatchAction(a)},bluetooth:function(){return s.bluetoothClient.dispatchAction(a)}});case 36:return r.abrupt("return",r.sent);case 37:case"end":return r.stop()}},r,this)}))}},{key:"getHapticEffects",value:function(){return R}},{key:"accelerometer",value:function(){var e=this,t="accelerometer",r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this.onDeviceChange().pipe((0,M.switchMap)(function(r){var n=(null==r?void 0:r.modelVersion)||L.MODEL_VERSION_1;return L.supportsAccel(n)?e._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,I.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.accelerometer()}}):(0,E.throwError)(function(){return F.metricNotSupportedByModel(t,n)})}))}},{key:"brainwaves",value:function(e){var t=this,r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"brainwaves"),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,W.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=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"calm"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,W.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=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,I.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.signalQuality()}})}},{key:"settings",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"settings"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.observeNamespace("settings")}},{key:"osVersion",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"osVersion"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.osVersion()}},{key:"focus",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"focus"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["focus"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.focus()}})}},{key:"kinesis",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"kinesis"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):(0,W.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"kinesis",labels:e?[e]:[],atomic:!1})}},{key:"predictions",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"predictions"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):(0,W.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"predictions",labels:e?[e]:[],atomic:!1})}},{key:"status",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"status"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return e.cloudClient.status()},bluetooth:function(){return e.bluetoothClient.status()}})}},{key:"changeSettings",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().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(F.mustSelectDevice));case 4:if(r=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"changeSettings"),n=s(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:"training",get:function(){var e=this;return{record:function(t){return x(e,void 0,void 0,v().mark(function e(){var r,n;return v().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 F.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 x(e,void 0,void 0,v().mark(function e(){return v().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 F.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 x(e,void 0,void 0,v().mark(function e(){return v().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 F.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)}))}}}},{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 H.isNode?(0,G.createOAuthURL)(e,this.options):Promise.reject(new Error("".concat(F.prefix,"the createOAuthURL method must be used on the server side (node.js) for security reasons.")))}},{key:"getOAuthToken",value:function(e){return H.isNode?(0,q.getOAuthToken)(e,this.options):Promise.reject(new Error("".concat(F.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)}}]),e}();exports.Neurosity=K,K.credentialWithLink=N.credentialWithLink,K.createUser=D.createUser,K.SERVER_TIMESTAMP=N.SERVER_TIMESTAMP;var Q=function(e){t(i,K);var r=n(i);function i(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return m(this,i),e=r.call(this,t),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 b(i)}();exports.Notion=Q;
678
+ var e;function t(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}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&r(e,t)}function r(e,t){return(r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function n(e){var t=u();return function(){var r,n=c(e);if(t){var o=c(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return i(this,r)}}function i(e,t){if(t&&("object"===a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return o(e)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e){return(a="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})(e)}function s(e,t){return p(e)||d(e,t)||h(e,t)||l()}function l(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function h(e,t){if(e){if("string"==typeof e)return f(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,t):void 0}}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,u,c=[],a=!0,s=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;a=!1}else for(;!(a=(n=o.call(r)).done)&&(c.push(n.value),c.length!==t);a=!0);}catch(l){s=!0,i=l}finally{try{if(!a&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(s)throw i}}return c}}function p(e){if(Array.isArray(e))return e}function v(){"use strict";v=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(A){s=function(e,t,r){return e[t]=r}}function l(e,t,r,i){var o=t&&t.prototype instanceof d?t:d,u=Object.create(o.prototype),c=new _(i||[]);return n(u,"_invoke",{value:S(e,r,c)}),u}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(A){return{type:"throw",arg:A}}}e.wrap=l;var f={};function d(){}function p(){}function m(){}var y={};s(y,o,function(){return this});var b=Object.getPrototypeOf,g=b&&b(b(M([])));g&&g!==t&&r.call(g,o)&&(y=g);var w=m.prototype=d.prototype=Object.create(y);function C(e){["next","throw","return"].forEach(function(t){s(e,t,function(e){return this._invoke(t,e)})})}function O(e,t){var i;n(this,"_invoke",{value:function(n,o){function u(){return new t(function(i,u){!function n(i,o,u,c){var s=h(e[i],e,o);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==a(f)&&r.call(f,"__await")?t.resolve(f.__await).then(function(e){n("next",e,u,c)},function(e){n("throw",e,u,c)}):t.resolve(f).then(function(e){l.value=e,u(l)},function(e){return n("throw",e,u,c)})}c(s.arg)}(n,o,i,u)})}return i=i?i.then(u,u):u()}})}function S(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return T()}for(r.method=i,r.arg=o;;){var u=r.delegate;if(u){var c=x(u,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var a=h(e,t,r);if("normal"===a.type){if(n=r.done?"completed":"suspendedYield",a.arg===f)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n="completed",r.method="throw",r.arg=a.arg)}}}function x(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,f;var o=i.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,f):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function k(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function M(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:T}}function T(){return{value:void 0,done:!0}}return p.prototype=m,n(w,"constructor",{value:m,configurable:!0}),n(m,"constructor",{value:p,configurable:!0}),p.displayName=s(m,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,s(e,c,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},C(O.prototype),s(O.prototype,u,function(){return this}),e.AsyncIterator=O,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new O(l(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then(function(e){return e.done?e.value:u.next()})},C(w),s(w,c,"Generator"),s(w,o,function(){return this}),s(w,"toString",function(){return"[object Generator]"}),e.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=M,_.prototype={constructor:_,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return u.type="throw",u.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var c=r.call(o,"catchLoc"),a=r.call(o,"finallyLoc");if(c&&a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=e,u.arg=t,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(u)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),f},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),E(r),f}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;E(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:M(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function y(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,g(n.key),n)}}function b(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function g(e){var t=w(e,"string");return"symbol"===a(t)?t:String(t)}function w(e,t){if("object"!==a(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var C=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]}),O=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),S=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)&&C(t,e,r);return O(t,e),t},x=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function u(e){try{a(n.next(e))}catch(t){o(t)}}function c(e){try{a(n.throw(e))}catch(t){o(t)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,c)}a((n=n.apply(e,t||[])).next())})},k=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 E=require("rxjs"),_=require("rxjs"),M=require("rxjs/operators"),T=require("rxjs/operators"),A=k(require("fast-deep-equal")),D=require("./api/index"),N=require("./api/index"),I=require("./types/streaming"),j=require("./utils/subscription"),P=require("./types/status"),F=S(require("./utils/errors")),L=S(require("./utils/platform")),R=S(require("./utils/hapticEffects")),B=require("./utils/oauth"),U=require("./utils/oauth"),G=require("./api/https/createOAuthURL"),q=require("./api/https/getOAuthToken"),H=require("./utils/is-node"),W=require("./utils/metrics"),Y=require("./api/bluetooth"),V=require("./api/bluetooth/types"),$={timesync:!1,autoSelectDevice:!0,streamingMode:I.STREAMING_MODE.WIFI_ONLY,emulator:!1,emulatorHost:"localhost",emulatorAuthPort:9099,emulatorDatabasePort:9e3,emulatorFunctionsPort:5001,emulatorFirestorePort:8080,emulatorOptions:{}},K=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m(this,e),this.streamingMode$=new _.ReplaySubject(1);var r=t.streamingMode,n=t.bluetoothTransport;this.options=Object.freeze(Object.assign(Object.assign({},$),t)),this.cloudClient=new D.CloudClient(this.options),n&&(this.bluetoothClient=new Y.BluetoothClient({selectedDevice$:this.onDeviceChange(),osHasBluetoothSupport$:this._osHasBluetoothSupport(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:n})),this._initStreamingMode(r,!!n)}return b(e,[{key:"_initStreamingMode",value:function(e,t){var r=[I.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,I.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),n=!Object.values(I.STREAMING_MODE).includes(e),i=r&&!t;this.isMissingBluetoothTransport=i,!e||n||i?this.streamingMode$.next(I.STREAMING_MODE.WIFI_ONLY):this.streamingMode$.next(e)}},{key:"_osHasBluetoothSupport",value:function(){return(0,E.combineLatest)({selectedDevice:this.onDeviceChange(),osVersion:this.osVersion().pipe((0,M.startWith)(null))}).pipe((0,M.map)(function(e){var t=e.selectedDevice,r=e.osVersion;return(0,Y.osHasBluetoothSupport)(t,r)}))}},{key:"streamingState",value:function(){var e=this,t=function(e){return[P.STATUS.ONLINE,P.STATUS.UPDATING].includes(e)};return this.streamingMode$.pipe((0,M.switchMap)(function(r){return(0,E.combineLatest)({selectedDevice:e.onDeviceChange(),osHasBluetoothSupport:e._osHasBluetoothSupport()}).pipe((0,M.switchMap)(function(n){var i=n.selectedDevice,o=n.osHasBluetoothSupport;return i?e.isMissingBluetoothTransport||!o?e.cloudClient.status().pipe((0,M.map)(function(e){var n=e.state;return{connected:t(n),streamingMode:r,activeMode:I.STREAMING_TYPE.WIFI}})):(0,E.combineLatest)({wifiStatus:e.cloudClient.status(),bluetoothConnection:(null==e?void 0:e.bluetoothClient)?e.bluetoothClient.connection():(0,E.of)(V.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe((0,M.map)(function(e){var n=e.wifiStatus,i=e.bluetoothConnection===V.BLUETOOTH_CONNECTION.CONNECTED;switch(r){default:case I.STREAMING_MODE.WIFI_ONLY:return{connected:t(n.state),streamingMode:r,activeMode:I.STREAMING_TYPE.WIFI};case I.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:t(n.state)||!i?t(n.state):i,streamingMode:r,activeMode:t(n.state)||!i?I.STREAMING_TYPE.WIFI:I.STREAMING_TYPE.BLUETOOTH};case I.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!i||t(n.state),streamingMode:r,activeMode:i?I.STREAMING_TYPE.BLUETOOTH:I.STREAMING_TYPE.WIFI}}}),(0,T.distinctUntilChanged)(function(e,t){return(0,A.default)(e,t)})):(0,E.of)({connected:!1,streamingMode:r,activeMode:I.STREAMING_TYPE.WIFI})}))}))}},{key:"_withStreamingModeObservable",value:function(e){var t=e.wifi,r=e.bluetooth;return this.streamingState().pipe((0,M.switchMap)(function(e){switch(e.activeMode){case I.STREAMING_TYPE.WIFI:return t();case I.STREAMING_TYPE.BLUETOOTH:return r();default:return t()}}))}},{key:"_withStreamingModePromise",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.wifi,n=e.bluetooth,t.next=3,(0,_.firstValueFrom)(this.streamingState());case 3:i=t.sent,o=i.activeMode,t.t0=o,t.next=t.t0===I.STREAMING_TYPE.WIFI?8:t.t0===I.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:"bluetooth",get:function(){return null==this?void 0:this.bluetoothClient}},{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 x(this,void 0,void 0,v().mark(function t(){return v().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 x(this,void 0,void 0,v().mark(function e(){return v().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=s((0,B.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=s((0,B.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=s((0,B.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=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onUserDevicesChange"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.cloudClient.onUserClaimsChange()}},{key:"getDevices",value:function(){return x(this,void 0,void 0,v().mark(function e(){return v().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 x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"selectDevice"),n=s(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 x(this,void 0,void 0,v().mark(function e(){var t,r,n,i;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getSelectedDevice"),r=s(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 x(this,void 0,void 0,v().mark(function e(){var t,r,n,i,o=this;return v().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(F.mustSelectDevice));case 4:if(t=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getInfo"),r=s(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=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onDeviceChange"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.onDeviceChange()}},{key:"disconnect",value:function(){return x(this,void 0,void 0,v().mark(function e(){var t=this;return v().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 x(this,void 0,void 0,v().mark(function t(){var r,n,i,o,u=this;return v().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(F.mustSelectDevice));case 4:if(r=(0,U.validateOAuthScopeForAction)(this.cloudClient.userClaims,e),n=s(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 x(this,void 0,void 0,v().mark(function t(){var r=this;return v().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 F.mustSelectDevice;case 4:if(e){t.next=6;break}throw new Error("".concat(F.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 x(this,void 0,void 0,v().mark(function r(){var n,i,o,u,c,a,s=this;return v().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(F.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,L.supportsHaptics(i)){r.next=20;break}return r.abrupt("return",Promise.reject(F.metricNotSupportedByModel(n,i)));case 20:o=L.getPlatformHapticMotors(i),r.t3=v().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(F.locationNotFound(u,i)));case 26:if(c=e[u],7,!(c.length>7)){r.next=30;break}return r.abrupt("return",Promise.reject(F.exceededMaxItems(7)));case 30:o[u]=c,r.next=22;break;case 33:return a={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}},r.next=36,this._withStreamingModePromise({wifi:function(){return s.cloudClient.dispatchAction(a)},bluetooth:function(){return s.bluetoothClient.dispatchAction(a)}});case 36:return r.abrupt("return",r.sent);case 37:case"end":return r.stop()}},r,this)}))}},{key:"getHapticEffects",value:function(){return R}},{key:"accelerometer",value:function(){var e=this,t="accelerometer",r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this.onDeviceChange().pipe((0,M.switchMap)(function(r){var n=(null==r?void 0:r.modelVersion)||L.MODEL_VERSION_1;return L.supportsAccel(n)?e._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,j.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.accelerometer()}}):(0,E.throwError)(function(){return F.metricNotSupportedByModel(t,n)})}))}},{key:"brainwaves",value:function(e){var t=this,r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"brainwaves"),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,W.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=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"calm"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,W.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=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,j.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.signalQuality()}})}},{key:"settings",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"settings"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.observeNamespace("settings")}},{key:"osVersion",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"osVersion"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.osVersion()}},{key:"focus",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"focus"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["focus"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.focus()}})}},{key:"kinesis",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"kinesis"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):(0,W.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"kinesis",labels:e?[e]:[],atomic:!1})}},{key:"predictions",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"predictions"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):(0,W.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"predictions",labels:e?[e]:[],atomic:!1})}},{key:"status",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"status"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return e.cloudClient.status()},bluetooth:function(){return e.bluetoothClient.status()}})}},{key:"changeSettings",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().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(F.mustSelectDevice));case 4:if(r=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"changeSettings"),n=s(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:"training",get:function(){var e=this;return{record:function(t){return x(e,void 0,void 0,v().mark(function e(){var r,n;return v().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 F.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 x(e,void 0,void 0,v().mark(function e(){return v().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 F.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 x(e,void 0,void 0,v().mark(function e(){return v().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 F.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)}))}}}},{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 H.isNode?(0,G.createOAuthURL)(e,this.options):Promise.reject(new Error("".concat(F.prefix,"the createOAuthURL method must be used on the server side (node.js) for security reasons.")))}},{key:"getOAuthToken",value:function(e){return H.isNode?(0,q.getOAuthToken)(e,this.options):Promise.reject(new Error("".concat(F.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)}}]),e}();exports.Neurosity=K,K.credentialWithLink=N.credentialWithLink,K.createUser=D.createUser,K.SERVER_TIMESTAMP=N.SERVER_TIMESTAMP;var Q=function(e){t(i,K);var r=n(i);function i(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return m(this,i),e=r.call(this,t),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 b(i)}();exports.Notion=Q;
679
679
  },{"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) {
680
680
  "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);
681
681
  },{"./Neurosity":"BZP9","./api/bluetooth":"TICO"}]},{},["QCba"], null)