@neurosity/sdk 6.5.4 → 6.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/neurosity.iife.js +23 -26
- package/dist/browser/neurosity.js +2 -2
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/types/streaming.d.ts +0 -3
- package/dist/cjs/types/streaming.js +0 -3
- package/dist/electron/index.js +2 -2
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/neurosity.mjs +1 -4
- package/dist/esm/types/streaming.d.ts +0 -3
- package/dist/esm/types/streaming.js +0 -3
- package/dist/examples/neurosity.iife.js +23 -26
- package/dist/examples/neurosity.js +2 -2
- package/dist/examples/neurosity.mjs +1 -4
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Neurosity"), exports);
|
|
18
18
|
__exportStar(require("./api/bluetooth"), exports);
|
|
19
|
+
__exportStar(require("./types/streaming"), exports);
|
|
@@ -9,9 +9,6 @@ var STREAMING_TYPE;
|
|
|
9
9
|
STREAMING_TYPE["WIFI"] = "wifi";
|
|
10
10
|
STREAMING_TYPE["BLUETOOTH"] = "bluetooth";
|
|
11
11
|
})(STREAMING_TYPE = exports.STREAMING_TYPE || (exports.STREAMING_TYPE = {}));
|
|
12
|
-
/**
|
|
13
|
-
* @hidden
|
|
14
|
-
*/
|
|
15
12
|
var STREAMING_MODE;
|
|
16
13
|
(function (STREAMING_MODE) {
|
|
17
14
|
STREAMING_MODE["WIFI_ONLY"] = "wifi-only";
|
package/dist/electron/index.js
CHANGED
|
@@ -83,6 +83,6 @@ process.env.HMR_PORT=0;process.env.HMR_HOSTNAME="localhost";parcelRequire=functi
|
|
|
83
83
|
},{"./BluetoothClient":"fihV","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/osHasBluetoothSupport":"rH2Y","./types/index":"iwtf"}],"BZP9":[function(require,module,exports) {
|
|
84
84
|
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,i,o){void 0===o&&(o=i);var s=Object.getOwnPropertyDescriptor(t,i);s&&("get"in s?t.__esModule:!s.writable&&!s.configurable)||(s={enumerable:!0,get:function(){return t[i]}}),Object.defineProperty(e,o,s)}:function(e,t,i,o){void 0===o&&(o=i),e[o]=t[i]}),t=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(i){if(i&&i.__esModule)return i;var o={};if(null!=i)for(var s in i)"default"!==s&&Object.prototype.hasOwnProperty.call(i,s)&&e(o,i,s);return t(o,i),o},o=this&&this.__awaiter||function(e,t,i,o){return new(i||(i=Promise))(function(s,r){function n(e){try{u(o.next(e))}catch(t){r(t)}}function c(e){try{u(o.throw(e))}catch(t){r(t)}}function u(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(n,c)}u((o=o.apply(e,t||[])).next())})},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Notion=exports.Neurosity=void 0;const r=require("rxjs"),n=require("rxjs"),c=require("rxjs/operators"),u=require("rxjs/operators"),l=s(require("fast-deep-equal")),a=require("./api/index"),d=require("./api/index"),h=require("./types/streaming"),m=require("./utils/subscription"),p=require("./types/status"),C=i(require("./utils/errors")),v=i(require("./utils/platform")),g=i(require("./utils/hapticEffects")),f=require("./utils/oauth"),S=require("./utils/oauth"),O=require("./api/https/createOAuthURL"),M=require("./api/https/getOAuthToken"),b=require("./utils/is-node"),_=require("./utils/metrics"),E=require("./api/bluetooth"),T=require("./api/bluetooth/types"),A={timesync:!1,autoSelectDevice:!0,streamingMode:h.STREAMING_MODE.WIFI_ONLY,emulator:!1,emulatorHost:"localhost",emulatorAuthPort:9099,emulatorDatabasePort:9e3,emulatorFunctionsPort:5001,emulatorFirestorePort:8080,emulatorOptions:{}};class D{constructor(e={}){this.streamingMode$=new n.ReplaySubject(1);const{streamingMode:t,bluetoothTransport:i}=e;this.options=Object.freeze(Object.assign(Object.assign({},A),e)),this.cloudClient=new a.CloudClient(this.options),i&&(this.bluetoothClient=new E.BluetoothClient({selectedDevice$:this.onDeviceChange(),osHasBluetoothSupport$:this._osHasBluetoothSupport(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:i})),this._initStreamingMode(t,!!i)}_initStreamingMode(e,t){const i=[h.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,h.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),o=!Object.values(h.STREAMING_MODE).includes(e),s=i&&!t;this.isMissingBluetoothTransport=s,!e||o||s?this.streamingMode$.next(h.STREAMING_MODE.WIFI_ONLY):this.streamingMode$.next(e)}_osHasBluetoothSupport(){return(0,r.combineLatest)({selectedDevice:this.onDeviceChange(),osVersion:this.osVersion().pipe((0,c.startWith)(null))}).pipe((0,c.map)(({selectedDevice:e,osVersion:t})=>(0,E.osHasBluetoothSupport)(e,t)))}streamingState(){const e=e=>[p.STATUS.ONLINE,p.STATUS.UPDATING].includes(e);return this.streamingMode$.pipe((0,c.switchMap)(t=>(0,r.combineLatest)({selectedDevice:this.onDeviceChange(),osHasBluetoothSupport:this._osHasBluetoothSupport()}).pipe((0,c.switchMap)(({selectedDevice:i,osHasBluetoothSupport:o})=>{if(!i)return(0,r.of)({connected:!1,streamingMode:t,activeMode:h.STREAMING_TYPE.WIFI});return this.isMissingBluetoothTransport||!o?this.cloudClient.status().pipe((0,c.map)(({state:i})=>({connected:e(i),streamingMode:t,activeMode:h.STREAMING_TYPE.WIFI}))):(0,r.combineLatest)({wifiStatus:this.cloudClient.status(),bluetoothConnection:(null==this?void 0:this.bluetoothClient)?this.bluetoothClient.connection():(0,r.of)(T.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe((0,c.map)(({wifiStatus:i,bluetoothConnection:o})=>{const s=o===T.BLUETOOTH_CONNECTION.CONNECTED;switch(t){default:case h.STREAMING_MODE.WIFI_ONLY:return{connected:e(i.state),streamingMode:t,activeMode:h.STREAMING_TYPE.WIFI};case h.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:e(i.state)||!s?e(i.state):s,streamingMode:t,activeMode:e(i.state)||!s?h.STREAMING_TYPE.WIFI:h.STREAMING_TYPE.BLUETOOTH};case h.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!s||e(i.state),streamingMode:t,activeMode:s?h.STREAMING_TYPE.BLUETOOTH:h.STREAMING_TYPE.WIFI}}}),(0,u.distinctUntilChanged)((e,t)=>(0,l.default)(e,t)))}))))}_withStreamingModeObservable(e){const{wifi:t,bluetooth:i}=e;return this.streamingState().pipe((0,c.switchMap)(({activeMode:e})=>{switch(e){case h.STREAMING_TYPE.WIFI:return t();case h.STREAMING_TYPE.BLUETOOTH:return i();default:return t()}}))}_withStreamingModePromise(e){return o(this,void 0,void 0,function*(){const{wifi:t,bluetooth:i}=e,{activeMode:o}=yield(0,n.firstValueFrom)(this.streamingState());switch(o){case h.STREAMING_TYPE.WIFI:return yield t();case h.STREAMING_TYPE.BLUETOOTH:return yield i();default:return yield t()}})}get bluetooth(){return null==this?void 0:this.bluetoothClient}_getCloudMetricDependencies(){return{options:this.options,cloudClient:this.cloudClient,onDeviceChange:this.onDeviceChange.bind(this),status:this.status.bind(this)}}login(e){return o(this,void 0,void 0,function*(){return yield this.cloudClient.login(e)})}logout(){return o(this,void 0,void 0,function*(){return yield this.cloudClient.logout()})}__getApp(){return this.cloudClient.__getApp()}onAuthStateChanged(){return this.cloudClient.onAuthStateChanged()}addDevice(e){const[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"addDevice");return t?Promise.reject(i):this.cloudClient.addDevice(e)}removeDevice(e){const[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"removeDevice");return t?Promise.reject(i):this.cloudClient.removeDevice(e)}transferDevice(e){const[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"transferDevice");return t?Promise.reject(i):this.cloudClient.transferDevice(e)}onUserDevicesChange(){const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onUserDevicesChange");return e?(0,r.throwError)(()=>t):this.cloudClient.onUserDevicesChange()}onUserClaimsChange(){return this.cloudClient.onUserClaimsChange()}getDevices(){return o(this,void 0,void 0,function*(){return yield this.cloudClient.getDevices()})}selectDevice(e){return o(this,void 0,void 0,function*(){const[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"selectDevice");return t?Promise.reject(i):yield this.cloudClient.selectDevice(e)})}getSelectedDevice(){return o(this,void 0,void 0,function*(){const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getSelectedDevice");return e?Promise.reject(t):yield this.cloudClient.getSelectedDevice()})}getInfo(){return o(this,void 0,void 0,function*(){if(!(yield this.cloudClient.didSelectDevice()))return Promise.reject(C.mustSelectDevice);const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getInfo");return e?Promise.reject(t):yield this._withStreamingModePromise({wifi:()=>this.cloudClient.getInfo(),bluetooth:()=>this.bluetoothClient.getInfo()})})}onDeviceChange(){const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onDeviceChange");return e?(0,r.throwError)(()=>t):this.cloudClient.onDeviceChange()}disconnect(){return o(this,void 0,void 0,function*(){return yield this._withStreamingModePromise({wifi:()=>this.cloudClient.disconnect(),bluetooth:()=>this.bluetoothClient.disconnect()})})}dispatchAction(e){return o(this,void 0,void 0,function*(){if(!(yield this.cloudClient.didSelectDevice()))return Promise.reject(C.mustSelectDevice);const[t,i]=(0,S.validateOAuthScopeForAction)(this.cloudClient.userClaims,e);return t?Promise.reject(i):yield this._withStreamingModePromise({wifi:()=>this.cloudClient.dispatchAction(e),bluetooth:()=>this.bluetoothClient.dispatchAction(e)})})}addMarker(e){return o(this,void 0,void 0,function*(){if(!(yield this.cloudClient.didSelectDevice()))throw C.mustSelectDevice;if(!e)throw new Error(`${C.prefix}A label is required for addMarker`);return yield this._withStreamingModePromise({wifi:()=>this.cloudClient.dispatchAction({command:"marker",action:"add",message:{label:e,timestamp:this.cloudClient.timestamp}}),bluetooth:()=>this.bluetoothClient.addMarker(e)})})}haptics(e){var t;return o(this,void 0,void 0,function*(){if(!(yield this.cloudClient.didSelectDevice()))return Promise.reject(C.mustSelectDevice);const i=null===(t=yield this.getSelectedDevice())||void 0===t?void 0:t.modelVersion;if(!v.supportsHaptics(i))return Promise.reject(C.metricNotSupportedByModel("haptics",i));const o=v.getPlatformHapticMotors(i);for(const t in e){if(!Object.keys(o).includes(t))return Promise.reject(C.locationNotFound(t,i));const s=e[t],r=7;if(s.length>r)return Promise.reject(C.exceededMaxItems(r));o[t]=s}const s={command:"haptics",action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}};return yield this._withStreamingModePromise({wifi:()=>this.cloudClient.dispatchAction(s),bluetooth:()=>this.bluetoothClient.dispatchAction(s)})})}getHapticEffects(){return g}accelerometer(){const e="accelerometer",[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,e);return t?(0,r.throwError)(()=>i):this.onDeviceChange().pipe((0,c.switchMap)(t=>{const i=(null==t?void 0:t.modelVersion)||v.MODEL_VERSION_1;return v.supportsAccel(i)?this._withStreamingModeObservable({wifi:()=>(0,_.getCloudMetric)(this._getCloudMetricDependencies(),{metric:e,labels:(0,m.getLabels)(e),atomic:!0}),bluetooth:()=>this.bluetoothClient.accelerometer()}):(0,r.throwError)(()=>C.metricNotSupportedByModel(e,i))}))}brainwaves(e){const[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"brainwaves");return t?(0,r.throwError)(()=>i):this._withStreamingModeObservable({wifi:()=>(0,_.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"brainwaves",labels:e?[e]:[],atomic:!1}),bluetooth:()=>this.bluetoothClient.brainwaves(e)})}calm(){const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"calm");return e?(0,r.throwError)(()=>t):this._withStreamingModeObservable({wifi:()=>(0,_.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"awareness",labels:["calm"],atomic:!1}),bluetooth:()=>this.bluetoothClient.calm()})}signalQuality(){const e="signalQuality",[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,e);return t?(0,r.throwError)(()=>i):this._withStreamingModeObservable({wifi:()=>(0,_.getCloudMetric)(this._getCloudMetricDependencies(),{metric:e,labels:(0,m.getLabels)(e),atomic:!0}),bluetooth:()=>this.bluetoothClient.signalQuality()})}settings(){const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"settings");return e?(0,r.throwError)(()=>t):this.cloudClient.observeNamespace("settings")}osVersion(){const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"osVersion");return e?(0,r.throwError)(()=>t):this.cloudClient.osVersion()}focus(){const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"focus");return e?(0,r.throwError)(()=>t):this._withStreamingModeObservable({wifi:()=>(0,_.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"awareness",labels:["focus"],atomic:!1}),bluetooth:()=>this.bluetoothClient.focus()})}kinesis(e){const[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"kinesis");return t?(0,r.throwError)(()=>i):(0,_.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"kinesis",labels:e?[e]:[],atomic:!1})}predictions(e){const[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"predictions");return t?(0,r.throwError)(()=>i):(0,_.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"predictions",labels:e?[e]:[],atomic:!1})}status(){const[e,t]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"status");return e?(0,r.throwError)(()=>t):this._withStreamingModeObservable({wifi:()=>this.cloudClient.status(),bluetooth:()=>this.bluetoothClient.status()})}changeSettings(e){return o(this,void 0,void 0,function*(){if(!(yield this.cloudClient.didSelectDevice()))return Promise.reject(C.mustSelectDevice);const[t,i]=(0,f.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"changeSettings");return t?Promise.reject(i):yield this.cloudClient.changeSettings(e)})}get training(){return{record:e=>o(this,void 0,void 0,function*(){if(!(yield this.cloudClient.didSelectDevice()))throw C.mustSelectDevice;const t=this.cloudClient.user&&"uid"in this.cloudClient.user?this.cloudClient.user.uid:null,i=Object.assign(Object.assign({fit:!1,baseline:!1,timestamp:this.cloudClient.timestamp},e),{userId:t});yield this.cloudClient.actions.dispatch({command:"training",action:"record",message:i})}),stop:e=>o(this,void 0,void 0,function*(){if(!(yield this.cloudClient.didSelectDevice()))throw C.mustSelectDevice;yield this.cloudClient.actions.dispatch({command:"training",action:"stop",message:Object.assign({},e)})}),stopAll:()=>o(this,void 0,void 0,function*(){if(!(yield this.cloudClient.didSelectDevice()))throw C.mustSelectDevice;yield this.cloudClient.actions.dispatch({command:"training",action:"stopAll",message:{}})})}}goOffline(){this.cloudClient.goOffline()}goOnline(){this.cloudClient.goOnline()}createAccount(e){return this.cloudClient.createAccount(e)}deleteAccount(){return this.cloudClient.deleteAccount()}createBluetoothToken(){return this.cloudClient.createBluetoothToken()}createCustomToken(){return this.cloudClient.createCustomToken()}getTimesyncOffset(){return this.options.timesync||console.warn("getTimesyncOffset() requires options.timesync to be true."),this.options.timesync?this.cloudClient.getTimesyncOffset():0}createOAuthURL(e){return b.isNode?(0,O.createOAuthURL)(e,this.options):Promise.reject(new Error(`${C.prefix}the createOAuthURL method must be used on the server side (node.js) for security reasons.`))}getOAuthToken(e){return b.isNode?(0,M.getOAuthToken)(e,this.options):Promise.reject(new Error(`${C.prefix}the getOAuthToken method must be used on the server side (node.js) for security reasons.`))}removeOAuthAccess(){return this.cloudClient.removeOAuthAccess()}onUserExperiments(){return this.cloudClient.onUserExperiments()}deleteUserExperiment(e){return this.cloudClient.deleteUserExperiment(e)}}exports.Neurosity=D,D.credentialWithLink=d.credentialWithLink,D.createUser=a.createUser,D.SERVER_TIMESTAMP=d.SERVER_TIMESTAMP;class w extends D{constructor(e={}){super(e),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()")}}exports.Notion=w;
|
|
85
85
|
},{"./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) {
|
|
86
|
-
"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);
|
|
87
|
-
},{"./Neurosity":"BZP9","./api/bluetooth":"TICO"}]},{},["QCba"], null)
|
|
86
|
+
"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),t(require("./types/streaming"),exports);
|
|
87
|
+
},{"./Neurosity":"BZP9","./api/bluetooth":"TICO","./types/streaming":"rekm"}]},{},["QCba"], null)
|
|
88
88
|
//# sourceMappingURL=/index.js.map
|