@neurosity/sdk 6.5.0 → 6.5.2
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 +731 -884
- package/dist/browser/neurosity.js +11 -11
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/Neurosity.js +5 -1
- package/dist/cjs/utils/heartbeat.js +14 -4
- package/dist/electron/index.js +2 -2
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/Neurosity.js +6 -2
- package/dist/esm/neurosity.mjs +731 -884
- package/dist/esm/utils/heartbeat.js +14 -4
- package/dist/examples/neurosity.iife.js +731 -884
- package/dist/examples/neurosity.js +11 -11
- package/dist/examples/neurosity.mjs +731 -884
- package/package.json +2 -2
|
@@ -4,10 +4,11 @@ import { withLatestFrom, distinctUntilChanged } from "rxjs/operators";
|
|
|
4
4
|
import isEqual from "fast-deep-equal";
|
|
5
5
|
import { STATUS } from "../types/status";
|
|
6
6
|
const HEARTBEAT_UPDATE_INTERVAL = 30000; // 30 seconds - set by the OS
|
|
7
|
-
const
|
|
7
|
+
const LOST_LOCAL_HEARTBEAT_AFTER = HEARTBEAT_UPDATE_INTERVAL * 2.5; // 75 seconds
|
|
8
|
+
const LOST_REMOTE_HEARTBEAT_AFTER = 8.64e7; // 24 hours
|
|
8
9
|
export function heartbeatAwareStatus(status$) {
|
|
9
10
|
const lastLocalHeartbeat$ = status$.pipe(map(({ lastHeartbeat }) => lastHeartbeat), distinctUntilChanged(), map(() => Date.now()));
|
|
10
|
-
const lostHeartbeat$ = lastLocalHeartbeat$.pipe(switchMap(() => timer(
|
|
11
|
+
const lostHeartbeat$ = lastLocalHeartbeat$.pipe(switchMap(() => timer(LOST_LOCAL_HEARTBEAT_AFTER)), map(() => null), startWith(null));
|
|
11
12
|
return combineLatest({
|
|
12
13
|
status: status$,
|
|
13
14
|
lostHeartbeat: lostHeartbeat$ // @important - do not remove, adeed for state synchronization, value not used
|
|
@@ -28,6 +29,15 @@ export function deviceHasLostHeartbeat(status, lastLocalHeartbeat) {
|
|
|
28
29
|
// implementation that used the server timestamp had bug where SDK clients
|
|
29
30
|
// running on hardware with drifted/out-of-sync clocks (cough cough Android)
|
|
30
31
|
// would override the state to offline when the heartbeat was active.
|
|
31
|
-
const
|
|
32
|
-
|
|
32
|
+
const lostLocalHeartbeat = Date.now() - lastLocalHeartbeat > LOST_LOCAL_HEARTBEAT_AFTER;
|
|
33
|
+
if (lostLocalHeartbeat) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
// Addresses devices with wrongful "online" state. This rarely happens, the
|
|
37
|
+
// OS would have to crash without updating the state to "offline".
|
|
38
|
+
const lostRemoteHeartbeat = Date.now() - status.lastHeartbeat > LOST_REMOTE_HEARTBEAT_AFTER;
|
|
39
|
+
if (lostRemoteHeartbeat) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
33
43
|
}
|