@neurosity/sdk 6.0.0-next.12 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/neurosity.iife.js +33 -13
- package/dist/browser/neurosity.js +1 -1
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/api/bluetooth/BluetoothClient.d.ts +12 -0
- package/dist/cjs/api/bluetooth/BluetoothClient.js +33 -13
- package/dist/electron/index.js +1 -1
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/api/bluetooth/BluetoothClient.d.ts +12 -0
- package/dist/esm/api/bluetooth/BluetoothClient.js +34 -14
- package/dist/esm/neurosity.mjs +33 -13
- package/dist/examples/neurosity.iife.js +33 -13
- package/dist/examples/neurosity.js +1 -1
- package/dist/examples/neurosity.mjs +33 -13
- package/package.json +1 -1
|
@@ -23,6 +23,18 @@ export declare class BluetoothClient {
|
|
|
23
23
|
deviceInfo: DeviceInfo;
|
|
24
24
|
selectedDevice$: ReplaySubject<DeviceInfo>;
|
|
25
25
|
isAuthenticated$: ReplaySubject<boolean>;
|
|
26
|
+
_focus$: Observable<any>;
|
|
27
|
+
_calm$: Observable<any>;
|
|
28
|
+
_accelerometer$: Observable<any>;
|
|
29
|
+
_brainwavesRaw$: Observable<any>;
|
|
30
|
+
_brainwavesRawUnfiltered$: Observable<any>;
|
|
31
|
+
_brainwavesPSD$: Observable<any>;
|
|
32
|
+
_brainwavesPowerByBand$: Observable<any>;
|
|
33
|
+
_signalQuality$: Observable<any>;
|
|
34
|
+
_status$: Observable<any>;
|
|
35
|
+
_settings$: Observable<any>;
|
|
36
|
+
_wifiNearbyNetworks$: Observable<any>;
|
|
37
|
+
_wifiConnections$: Observable<any>;
|
|
26
38
|
constructor(options: Options);
|
|
27
39
|
_autoAuthenticate(createBluetoothToken: CreateBluetoothToken): Observable<IsAuthenticatedResponse>;
|
|
28
40
|
_hasBluetoothSupport(): Promise<boolean>;
|
|
@@ -49,6 +49,23 @@ class BluetoothClient {
|
|
|
49
49
|
}
|
|
50
50
|
// Auto manage action notifications
|
|
51
51
|
this.transport._autoToggleActionNotifications(this.selectedDevice$);
|
|
52
|
+
// Multicast metrics (share)
|
|
53
|
+
this._focus$ = this._subscribeWhileAuthenticated("focus");
|
|
54
|
+
this._calm$ = this._subscribeWhileAuthenticated("calm");
|
|
55
|
+
this._accelerometer$ = this._subscribeWhileAuthenticated("accelerometer");
|
|
56
|
+
this._brainwavesRaw$ = this._subscribeWhileAuthenticated("raw");
|
|
57
|
+
this._brainwavesRawUnfiltered$ =
|
|
58
|
+
this._subscribeWhileAuthenticated("rawUnfiltered");
|
|
59
|
+
this._brainwavesPSD$ = this._subscribeWhileAuthenticated("psd");
|
|
60
|
+
this._brainwavesPowerByBand$ =
|
|
61
|
+
this._subscribeWhileAuthenticated("powerByBand");
|
|
62
|
+
this._signalQuality$ = this._subscribeWhileAuthenticated("signalQuality");
|
|
63
|
+
this._status$ = this._subscribeWhileAuthenticated("status");
|
|
64
|
+
this._settings$ = this._subscribeWhileAuthenticated("settings");
|
|
65
|
+
this._wifiNearbyNetworks$ =
|
|
66
|
+
this._subscribeWhileAuthenticated("wifiNearbyNetworks");
|
|
67
|
+
this._wifiConnections$ =
|
|
68
|
+
this._subscribeWhileAuthenticated("wifiConnections");
|
|
52
69
|
}
|
|
53
70
|
_autoAuthenticate(createBluetoothToken) {
|
|
54
71
|
const REAUTHENTICATE_INTERVAL = 3600000; // 1 hour
|
|
@@ -159,28 +176,32 @@ class BluetoothClient {
|
|
|
159
176
|
? this.transport.subscribeToCharacteristic({
|
|
160
177
|
characteristicName
|
|
161
178
|
})
|
|
162
|
-
: rxjs_2.EMPTY))));
|
|
179
|
+
: rxjs_2.EMPTY))), (0, operators_1.share)());
|
|
163
180
|
}
|
|
164
181
|
focus() {
|
|
165
|
-
return this.
|
|
182
|
+
return this._focus$;
|
|
166
183
|
}
|
|
167
184
|
calm() {
|
|
168
|
-
return this.
|
|
185
|
+
return this._calm$;
|
|
169
186
|
}
|
|
170
187
|
accelerometer() {
|
|
171
|
-
return this.
|
|
188
|
+
return this._accelerometer$;
|
|
172
189
|
}
|
|
173
190
|
brainwaves(label) {
|
|
174
191
|
switch (label) {
|
|
192
|
+
default:
|
|
175
193
|
case "raw":
|
|
194
|
+
return (0, rxjs_1.defer)(() => this.getInfo()).pipe((0, operators_1.switchMap)((deviceInfo) => this._brainwavesRaw$.pipe((0, csvBufferToEpoch_1.csvBufferToEpoch)(deviceInfo))));
|
|
176
195
|
case "rawUnfiltered":
|
|
177
|
-
return (0, rxjs_1.defer)(() => this.getInfo()).pipe((0, operators_1.switchMap)((deviceInfo) => this.
|
|
178
|
-
|
|
179
|
-
return this.
|
|
196
|
+
return (0, rxjs_1.defer)(() => this.getInfo()).pipe((0, operators_1.switchMap)((deviceInfo) => this._brainwavesRawUnfiltered$.pipe((0, csvBufferToEpoch_1.csvBufferToEpoch)(deviceInfo))));
|
|
197
|
+
case "psd":
|
|
198
|
+
return this._brainwavesPSD$;
|
|
199
|
+
case "powerByBand":
|
|
200
|
+
return this._brainwavesPowerByBand$;
|
|
180
201
|
}
|
|
181
202
|
}
|
|
182
203
|
signalQuality() {
|
|
183
|
-
return this.
|
|
204
|
+
return this._signalQuality$;
|
|
184
205
|
}
|
|
185
206
|
addMarker(label) {
|
|
186
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -201,9 +222,8 @@ class BluetoothClient {
|
|
|
201
222
|
})));
|
|
202
223
|
});
|
|
203
224
|
}
|
|
204
|
-
// Tested
|
|
205
225
|
status() {
|
|
206
|
-
return this.
|
|
226
|
+
return this._status$;
|
|
207
227
|
}
|
|
208
228
|
dispatchAction(action) {
|
|
209
229
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -214,7 +234,7 @@ class BluetoothClient {
|
|
|
214
234
|
});
|
|
215
235
|
}
|
|
216
236
|
settings() {
|
|
217
|
-
return this.
|
|
237
|
+
return this._settings$;
|
|
218
238
|
}
|
|
219
239
|
haptics(effects) {
|
|
220
240
|
const metric = "haptics";
|
|
@@ -229,8 +249,8 @@ class BluetoothClient {
|
|
|
229
249
|
}
|
|
230
250
|
get wifi() {
|
|
231
251
|
return {
|
|
232
|
-
nearbyNetworks: () => this.
|
|
233
|
-
connections: () => this.
|
|
252
|
+
nearbyNetworks: () => this._wifiNearbyNetworks$,
|
|
253
|
+
connections: () => this._wifiConnections$,
|
|
234
254
|
connect: (ssid, password) => {
|
|
235
255
|
if (!ssid) {
|
|
236
256
|
return Promise.reject(`Missing ssid`);
|
package/dist/electron/index.js
CHANGED
|
@@ -75,7 +75,7 @@ process.env.HMR_PORT=0;process.env.HMR_HOSTNAME="localhost";parcelRequire=functi
|
|
|
75
75
|
},{}],"WTrV":[function(require,module,exports) {
|
|
76
76
|
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.csvBufferToSamples=exports.csvBufferToEpoch=void 0;const e=require("rxjs"),r=require("rxjs/operators"),a=require("../../../utils/pipes"),s=16,t=256;function o(r){var o;return(null==r?void 0:r.samplingRate)||console.warn(`Didn't receive a sampling rate, defaulting to ${t}`),(0,e.pipe)(n(),(0,a.epoch)({duration:s,interval:s,samplingRate:null!==(o=null==r?void 0:r.samplingRate)&&void 0!==o?o:t}),(0,a.addInfo)({channelNames:r.channelNames,samplingRate:r.samplingRate}))}function n(){return(0,e.pipe)((0,r.mergeMap)(r=>(0,e.from)(r)),(0,r.map)(([e,r,...a])=>({timestamp:e,data:a})))}exports.csvBufferToEpoch=o,exports.csvBufferToSamples=n;
|
|
77
77
|
},{"../../../utils/pipes":"Oj1i"}],"fihV":[function(require,module,exports) {
|
|
78
|
-
"use strict";var t=this&&this.__awaiter||function(t,e,i,s){return new(i||(i=Promise))(function(r,n){function o(t){try{
|
|
78
|
+
"use strict";var t=this&&this.__awaiter||function(t,e,i,s){return new(i||(i=Promise))(function(r,n){function o(t){try{c(s.next(t))}catch(e){n(e)}}function a(t){try{c(s.throw(t))}catch(e){n(e)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(o,a)}c((s=s.apply(t,e||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.BluetoothClient=void 0;const e=require("rxjs"),i=require("rxjs"),s=require("rxjs/operators"),r=require("rxjs/operators"),n=require("./web/WebBluetoothTransport"),o=require("./react-native/ReactNativeTransport"),a=require("./utils/csvBufferToEpoch"),c=require("./types"),h=require("./utils/osHasBluetoothSupport");class u{constructor(t){this.selectedDevice$=new i.ReplaySubject(1),this.isAuthenticated$=new i.ReplaySubject(1);const{transport:e,selectedDevice$:s,createBluetoothToken:r}=null!=t?t:{};if(!e)throw new Error("No bluetooth transport provided.");this.transport=e,s&&s.subscribe(this.selectedDevice$),this.transport._autoConnect(this.selectedDevice$).subscribe({error:t=>{var e;this.transport.addLog(`Auto connect: error -> ${null!==(e=null==t?void 0:t.message)&&void 0!==e?e:t}`)}}),"function"==typeof r?(this.transport.addLog("Auto authentication enabled"),this._autoAuthenticate(r).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")}_autoAuthenticate(r){const n=(0,e.timer)(0,36e5).pipe((0,s.tap)(()=>{this.transport.addLog("Auto authentication in progress...")}));return this.selectedDevice$.pipe((0,s.switchMap)(e=>(0,h.osHasBluetoothSupport)(e)?this.connection().pipe((0,s.switchMap)(t=>t===c.BLUETOOTH_CONNECTION.CONNECTED?n:i.EMPTY),(0,s.switchMap)(()=>t(this,void 0,void 0,function*(){return yield this.isAuthenticated()})),(0,s.tap)(([e])=>t(this,void 0,void 0,function*(){if(e)this.transport.addLog("Already authenticated");else{const t=yield r();yield this.authenticate(t)}}))):i.EMPTY))}_hasBluetoothSupport(){return t(this,void 0,void 0,function*(){const t=yield(0,e.firstValueFrom)(this.selectedDevice$);return(0,h.osHasBluetoothSupport)(t)})}authenticate(e){return t(this,void 0,void 0,function*(){if(!(yield this._hasBluetoothSupport())){const t="authenticate method: The OS version does not support Bluetooth.";return this.transport.addLog(t),Promise.reject(t)}yield this.transport.writeCharacteristic("auth",e);const t=yield this.isAuthenticated(),[i]=t;return this.transport.addLog(`Authentication ${i?"succeeded":"failed"}`),this.isAuthenticated$.next(i),t})}isAuthenticated(){return t(this,void 0,void 0,function*(){const[t,e]=yield this.transport.readCharacteristic("auth",!0);return this.isAuthenticated$.next(t),[t,e]})}scan(t){if(this.transport instanceof o.ReactNativeTransport)return this.transport.scan(t);if(this.transport instanceof n.WebBluetoothTransport)throw new Error("scan method is compatibly with the React Native transport only");throw new Error("unknown transport")}connect(t){return this.transport instanceof o.ReactNativeTransport?this.transport.connect(t):this.transport instanceof n.WebBluetoothTransport?t?this.transport.connect(t):this.transport.connect():void 0}disconnect(){return this.transport.disconnect()}connection(){return this.transport.connection()}logs(){return this.transport.logs$.asObservable()}getDeviceId(){return t(this,void 0,void 0,function*(){return this.transport.readCharacteristic("deviceId")})}_withAuthentication(i){return t(this,void 0,void 0,function*(){if(!(yield this._hasBluetoothSupport())){const t="The OS version does not support Bluetooth.";return this.transport.addLog(t),Promise.reject(t)}if(!(yield(0,e.firstValueFrom)(this.isAuthenticated$))){const t="Authentication required.";return this.transport.addLog(t),Promise.reject(t)}return yield i()})}_subscribeWhileAuthenticated(t){return this.selectedDevice$.pipe((0,s.switchMap)(e=>(0,h.osHasBluetoothSupport)(e)?this.isAuthenticated$.pipe((0,r.distinctUntilChanged)(),(0,s.switchMap)(e=>e?this.transport.subscribeToCharacteristic({characteristicName:t}):i.EMPTY)):i.EMPTY),(0,s.share)())}focus(){return this._focus$}calm(){return this._calm$}accelerometer(){return this._accelerometer$}brainwaves(t){switch(t){default:case"raw":return(0,e.defer)(()=>this.getInfo()).pipe((0,s.switchMap)(t=>this._brainwavesRaw$.pipe((0,a.csvBufferToEpoch)(t))));case"rawUnfiltered":return(0,e.defer)(()=>this.getInfo()).pipe((0,s.switchMap)(t=>this._brainwavesRawUnfiltered$.pipe((0,a.csvBufferToEpoch)(t))));case"psd":return this._brainwavesPSD$;case"powerByBand":return this._brainwavesPowerByBand$}}signalQuality(){return this._signalQuality$}addMarker(e){return t(this,void 0,void 0,function*(){yield this.dispatchAction({action:"marker",command:"add",message:{timestamp:Date.now(),label:e}})})}getInfo(){return t(this,void 0,void 0,function*(){return yield this._withAuthentication(()=>(0,e.firstValueFrom)(this.transport.subscribeToCharacteristic({characteristicName:"deviceInfo"})))})}status(){return this._status$}dispatchAction(e){return t(this,void 0,void 0,function*(){return yield this._withAuthentication(()=>this.transport.dispatchAction({characteristicName:"actions",action:e}))})}settings(){return this._settings$}haptics(t){return this.dispatchAction({action:"haptics",command:"queue",responseRequired:!0,responseTimeout:4e3,message:{effects:t}})}get wifi(){return{nearbyNetworks:()=>this._wifiNearbyNetworks$,connections:()=>this._wifiConnections$,connect:(t,e)=>t?this.dispatchAction({action:"wifi",command:"connect",responseRequired:!0,responseTimeout:12e4,message:{ssid:t,password:null!=e?e:null}}):Promise.reject("Missing ssid"),forgetConnection:t=>t?this.dispatchAction({action:"wifi",command:"forget-connection",responseRequired:!0,responseTimeout:15e3,message:{ssid:t}}):Promise.reject("Missing ssid"),reset:()=>this.dispatchAction({action:"wifi",command:"reset",responseRequired:!0,responseTimeout:3e4,message:{respondOnSuccess:!0}}),speedTest:()=>this.dispatchAction({action:"wifi",command:"speed-test",responseRequired:!0,responseTimeout:6e4})}}}exports.BluetoothClient=u;
|
|
79
79
|
},{"./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/csvBufferToEpoch":"WTrV","./types":"iwtf","./utils/osHasBluetoothSupport":"rH2Y"}],"TICO":[function(require,module,exports) {
|
|
80
80
|
"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);
|
|
81
81
|
},{"./BluetoothClient":"fihV","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/osHasBluetoothSupport":"rH2Y"}],"KQ4u":[function(require,module,exports) {
|