react-native-asleep 1.0.18 → 1.1.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/README.md +69 -304
- package/android/src/main/java/ai/asleep/reactnative/AsleepModule.kt +36 -17
- package/build/Asleep.types.d.ts +42 -0
- package/build/Asleep.types.d.ts.map +1 -1
- package/build/Asleep.types.js.map +1 -1
- package/build/AsleepStore.d.ts +5 -2
- package/build/AsleepStore.d.ts.map +1 -1
- package/build/AsleepStore.js +201 -51
- package/build/AsleepStore.js.map +1 -1
- package/build/index.d.ts +9 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +10 -9
- package/build/index.js.map +1 -1
- package/ios/AsleepModule.swift +60 -4
- package/package.json +1 -1
- package/src/Asleep.types.ts +51 -1
- package/src/AsleepStore.ts +214 -52
- package/src/index.ts +19 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Asleep.types.js","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"","sourcesContent":["export type AsleepConfig = {\n apiKey: string;\n userId?: string;\n baseUrl?: string;\n callbackUrl?: string;\n};\n\nexport type AsleepSetupConfig = {\n apiKey: string;\n baseUrl?: string;\n callbackUrl?: string;\n service?: string;\n enableODA?: boolean;\n};\n\nexport type AsleepReport = {\n timezone: string;\n session: {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime?: string;\n unexpectedEndTime?: string;\n state: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n };\n missingDataRatio: number;\n peculiarities: string[];\n stat?: AsleepStat;\n};\n\nexport type AsleepStat = {\n sleepCycleTime?: number[];\n timeInStableBreath?: number;\n timeInBed?: number;\n unstableBreathRatio?: number;\n sleepCycle?: number;\n timeInSleep?: number;\n breathingIndex?: number;\n deepLatency?: number;\n remLatency?: number;\n timeInSnoring?: number;\n wakeTime?: string;\n longestWaso?: number;\n lightRatio?: number;\n noSnoringRatio?: number;\n snoringCount?: number;\n unstableBreathCount?: number;\n timeInDeep?: number;\n sleepTime?: string;\n sleepCycleCount?: number;\n wakeupLatency?: number;\n breathingPattern?: string;\n timeInRem?: number;\n snoringRatio?: number;\n stableBreathRatio?: number;\n timeInSleepPeriod?: number;\n lightLatency?: number;\n remRatio?: number;\n sleepEfficiency?: number;\n timeInNoSnoring?: number;\n sleepLatency?: number;\n timeInLight?: number;\n sleepIndex?: number;\n sleepRatio?: number;\n timeInUnstableBreath?: number;\n wasoCount?: number;\n wakeRatio?: number;\n deepRatio?: number;\n timeInWake?: number;\n};\n\n// From getReportList() - maps to SDK SleepSession\nexport type AsleepSession = {\n id: string; // mapped from sessionId\n state: string;\n startTime: string; // mapped from sessionStartTime\n endTime?: string; // mapped from sessionEndTime\n createdTimezone: string;\n unexpectedEndTime?: string;\n lastReceivedSeqNum?: number;\n timeInBed?: number;\n};\n\n// From getAverageReport() sleptSessions - maps to SDK SleptSession\nexport type AsleepSleptSession = {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime: string;\n completedTime: string;\n sleepEfficiency: number;\n sleepLatency?: number;\n wakeupLatency?: number;\n lightLatency?: number;\n deepLatency?: number;\n remLatency?: number;\n sleepTime?: string;\n wakeTime?: string;\n timeInWake: number;\n timeInSleepPeriod: number;\n timeInSleep: number;\n timeInBed: number;\n timeInRem?: number;\n timeInLight?: number;\n timeInDeep?: number;\n timeInStableBreath?: number;\n timeInUnstableBreath?: number;\n timeInSnoring?: number;\n timeInNoSnoring?: number;\n wakeRatio: number;\n sleepRatio: number;\n remRatio?: number;\n lightRatio?: number;\n deepRatio?: number;\n stableBreathRatio?: number;\n unstableBreathRatio?: number;\n snoringRatio?: number;\n noSnoringRatio?: number;\n unstableBreathCount?: number;\n breathingPattern?: string;\n breathingIndex?: number;\n sleepCycle?: number;\n sleepCycleCount?: number;\n wasoCount?: number;\n longestWaso?: number;\n snoringCount?: number;\n};\n\n// From getAverageReport() neverSleptSessions - maps to SDK NeverSleptSession\nexport type AsleepNeverSleptSession = {\n id: string;\n startTime: string;\n endTime: string;\n completedTime: string;\n};\n\nexport type AsleepAverageReport = {\n period: {\n timezone: string;\n startDate: string;\n endDate: string;\n };\n peculiarities: string[];\n averageStats?: AsleepStat;\n neverSleptSessions?: AsleepNeverSleptSession[];\n sleptSessions?: AsleepSleptSession[];\n};\n\nexport type AsleepAnalysisResult = {\n id?: string;\n state?: string;\n startTime?: string;\n endTime?: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n};\n\nexport type AudioSessionOption = \"duckOthers\" | \"allowAirPlay\" | \"allowBluetooth\" | \"allowBluetoothA2DP\";\n\nexport type TrackingConfig = {\n android?: {\n notification?: {\n title?: string;\n text?: string;\n icon?: string;\n };\n };\n ios?: {\n /** Additional AVAudioSession options appended to SDK defaults (mixWithOthers, allowBluetoothA2DP, defaultToSpeaker). Options reset on each startTracking() call. */\n audioSessionOptions?: AudioSessionOption[];\n };\n};\n\nexport type AsleepEventType = {\n onTrackingCreated: { sessionId?: string };\n onTrackingUploaded: { sequence: number };\n onTrackingClosed: { sessionId: string };\n onTrackingFailed: {\n error: string;\n code: string;\n message?: string;\n errorCode?: number;\n caseName?: string;\n };\n onTrackingInterrupted: undefined;\n onTrackingResumed: undefined;\n onMicPermissionDenied: undefined;\n onUserJoined: { userId: string };\n onUserJoinFailed: {\n error?: string;\n errorCode?: number;\n detail?: string;\n caseName?: string;\n code?: number;\n };\n onUserDeleted: { userId: string };\n onDebugLog: { message: string };\n onSetupDidComplete: undefined;\n onSetupDidFail: {
|
|
1
|
+
{"version":3,"file":"Asleep.types.js","sourceRoot":"","sources":["../src/Asleep.types.ts"],"names":[],"mappings":"","sourcesContent":["export type AsleepConfig = {\n apiKey: string;\n userId?: string;\n baseUrl?: string;\n callbackUrl?: string;\n};\n\nexport type AsleepSetupConfig = {\n apiKey: string;\n baseUrl?: string;\n callbackUrl?: string;\n service?: string;\n enableODA?: boolean;\n};\n\nexport type AsleepReport = {\n timezone: string;\n session: {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime?: string;\n unexpectedEndTime?: string;\n state: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n };\n missingDataRatio: number;\n peculiarities: string[];\n stat?: AsleepStat;\n};\n\nexport type AsleepStat = {\n sleepCycleTime?: number[];\n timeInStableBreath?: number;\n timeInBed?: number;\n unstableBreathRatio?: number;\n sleepCycle?: number;\n timeInSleep?: number;\n breathingIndex?: number;\n deepLatency?: number;\n remLatency?: number;\n timeInSnoring?: number;\n wakeTime?: string;\n longestWaso?: number;\n lightRatio?: number;\n noSnoringRatio?: number;\n snoringCount?: number;\n unstableBreathCount?: number;\n timeInDeep?: number;\n sleepTime?: string;\n sleepCycleCount?: number;\n wakeupLatency?: number;\n breathingPattern?: string;\n timeInRem?: number;\n snoringRatio?: number;\n stableBreathRatio?: number;\n timeInSleepPeriod?: number;\n lightLatency?: number;\n remRatio?: number;\n sleepEfficiency?: number;\n timeInNoSnoring?: number;\n sleepLatency?: number;\n timeInLight?: number;\n sleepIndex?: number;\n sleepRatio?: number;\n timeInUnstableBreath?: number;\n wasoCount?: number;\n wakeRatio?: number;\n deepRatio?: number;\n timeInWake?: number;\n};\n\n// From getReportList() - maps to SDK SleepSession\nexport type AsleepSession = {\n id: string; // mapped from sessionId\n state: string;\n startTime: string; // mapped from sessionStartTime\n endTime?: string; // mapped from sessionEndTime\n createdTimezone: string;\n unexpectedEndTime?: string;\n lastReceivedSeqNum?: number;\n timeInBed?: number;\n};\n\n// From getAverageReport() sleptSessions - maps to SDK SleptSession\nexport type AsleepSleptSession = {\n id: string;\n createdTimezone: string;\n startTime: string;\n endTime: string;\n completedTime: string;\n sleepEfficiency: number;\n sleepLatency?: number;\n wakeupLatency?: number;\n lightLatency?: number;\n deepLatency?: number;\n remLatency?: number;\n sleepTime?: string;\n wakeTime?: string;\n timeInWake: number;\n timeInSleepPeriod: number;\n timeInSleep: number;\n timeInBed: number;\n timeInRem?: number;\n timeInLight?: number;\n timeInDeep?: number;\n timeInStableBreath?: number;\n timeInUnstableBreath?: number;\n timeInSnoring?: number;\n timeInNoSnoring?: number;\n wakeRatio: number;\n sleepRatio: number;\n remRatio?: number;\n lightRatio?: number;\n deepRatio?: number;\n stableBreathRatio?: number;\n unstableBreathRatio?: number;\n snoringRatio?: number;\n noSnoringRatio?: number;\n unstableBreathCount?: number;\n breathingPattern?: string;\n breathingIndex?: number;\n sleepCycle?: number;\n sleepCycleCount?: number;\n wasoCount?: number;\n longestWaso?: number;\n snoringCount?: number;\n};\n\n// From getAverageReport() neverSleptSessions - maps to SDK NeverSleptSession\nexport type AsleepNeverSleptSession = {\n id: string;\n startTime: string;\n endTime: string;\n completedTime: string;\n};\n\nexport type AsleepAverageReport = {\n period: {\n timezone: string;\n startDate: string;\n endDate: string;\n };\n peculiarities: string[];\n averageStats?: AsleepStat;\n neverSleptSessions?: AsleepNeverSleptSession[];\n sleptSessions?: AsleepSleptSession[];\n};\n\nexport type AsleepAnalysisResult = {\n id?: string;\n state?: string;\n startTime?: string;\n endTime?: string;\n sleepStages?: number[];\n breathStages?: number[];\n snoringStages?: number[];\n};\n\n// iOS resolves requestAnalysis with an ack while the real payload arrives via the\n// onAnalysisResult event. Android resolves with the full AsleepAnalysisResult and also\n// fires the event. Consumers reading the promise return value should narrow on `status`.\nexport type AsleepAnalysisAck = {\n status: \"requested\";\n timestamp: number;\n};\n\nexport type AudioSessionOption = \"duckOthers\" | \"allowAirPlay\" | \"allowBluetooth\" | \"allowBluetoothA2DP\";\n\nexport type TrackingConfig = {\n android?: {\n notification?: {\n title?: string;\n text?: string;\n icon?: string;\n };\n };\n ios?: {\n /** Additional AVAudioSession options appended to SDK defaults (mixWithOthers, allowBluetoothA2DP, defaultToSpeaker). Options reset on each startTracking() call. */\n audioSessionOptions?: AudioSessionOption[];\n };\n};\n\n/**\n * Coarse classification of a tracking-runtime failure (onTrackingFailed),\n * derived from the native error code. The library reports the objective fact;\n * the app decides log severity. Recommended mapping:\n * - \"terminal\" / \"recordingDead\" → error (session or recorder is gone)\n * - \"recoveryRequired\" / \"transient\" → warning (tracking is still alive and a\n * defined recovery path exists)\n * - \"unknown\" → error (unclassified; do not assume it is benign)\n */\nexport type AsleepErrorCategory = \"terminal\" | \"recordingDead\" | \"recoveryRequired\" | \"transient\" | \"unknown\";\n\n/**\n * Structured view of the last onTrackingFailed event, exposed as\n * useAsleep().errorInfo alongside the legacy `error` JSON string. Cleared to\n * null wherever `error` is cleared.\n */\nexport type AsleepErrorInfo = {\n /** Stable string code from the native module (e.g. \"UPLOAD_TRACKING_TERMINATED\"). */\n code: string;\n category: AsleepErrorCategory;\n /**\n * Numeric code documented by the native Asleep SDKs (range 10000-34999):\n * iOS `AsleepError.errorCode.code` (v3.2.0+), Android listener `errorCode`.\n */\n sdkCode?: number;\n message?: string;\n /** iOS: Swift enum case description for cases without an explicit code mapping. */\n caseName?: string;\n};\n\nexport type AsleepEventType = {\n onTrackingCreated: { sessionId?: string };\n onTrackingUploaded: { sequence: number };\n onTrackingClosed: { sessionId: string };\n onTrackingFailed: {\n error: string;\n code: string;\n message?: string;\n /**\n * @deprecated On iOS this is the Swift enum declaration ordinal from\n * NSError bridging, not the documented Asleep error code. Use `sdkCode`.\n */\n errorCode?: number;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n caseName?: string;\n };\n onTrackingInterrupted: undefined;\n onTrackingResumed: undefined;\n onMicPermissionDenied: undefined;\n onUserJoined: { userId: string };\n onUserJoinFailed: {\n error?: string;\n errorCode?: number;\n detail?: string;\n caseName?: string;\n code?: number;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n };\n onUserDeleted: { userId: string };\n onDebugLog: { message: string };\n onSetupDidComplete: undefined;\n onSetupDidFail: {\n error: string;\n /** Numeric code documented by the native Asleep SDKs (both platforms). */\n sdkCode?: number;\n };\n onSetupInProgress: { progress: number };\n onAnalysisResult: AsleepAnalysisResult;\n};\n"]}
|
package/build/AsleepStore.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { AsleepConfig, AsleepSetupConfig, AsleepEventType, AsleepReport, AsleepSession, AsleepAverageReport, AsleepAnalysisResult, TrackingConfig } from "./Asleep.types";
|
|
1
|
+
import { AsleepConfig, AsleepSetupConfig, AsleepErrorInfo, AsleepEventType, AsleepReport, AsleepSession, AsleepAverageReport, AsleepAnalysisResult, AsleepAnalysisAck, TrackingConfig } from "./Asleep.types";
|
|
2
2
|
export interface AsleepState {
|
|
3
3
|
didClose: boolean;
|
|
4
4
|
isTracking: boolean;
|
|
5
5
|
isTrackingPaused: boolean;
|
|
6
|
+
isRecoveryRequired: boolean;
|
|
6
7
|
error: string | null;
|
|
8
|
+
errorInfo: AsleepErrorInfo | null;
|
|
7
9
|
userId: string | null;
|
|
8
10
|
sessionId: string | null;
|
|
9
11
|
showDebugLog: boolean;
|
|
@@ -30,6 +32,7 @@ export interface AsleepState {
|
|
|
30
32
|
requestBatteryOptimizationExemption: () => Promise<boolean>;
|
|
31
33
|
startTracking: (config?: TrackingConfig) => Promise<void>;
|
|
32
34
|
stopTracking: () => Promise<void>;
|
|
35
|
+
resumeTracking: () => Promise<void>;
|
|
33
36
|
getReport: (sessionId: string) => Promise<AsleepReport | null>;
|
|
34
37
|
getReportList: (fromDate: string, toDate: string) => Promise<AsleepSession[]>;
|
|
35
38
|
getAverageReport: (fromDate: string, toDate: string) => Promise<AsleepAverageReport | null>;
|
|
@@ -39,7 +42,7 @@ export interface AsleepState {
|
|
|
39
42
|
setCustomNotification: (title: string, text: string) => Promise<void>;
|
|
40
43
|
enableLog: (print: boolean) => void;
|
|
41
44
|
clearError: () => void;
|
|
42
|
-
requestAnalysis: () => Promise<AsleepAnalysisResult | null>;
|
|
45
|
+
requestAnalysis: () => Promise<AsleepAnalysisResult | AsleepAnalysisAck | null>;
|
|
43
46
|
addEventListener: <K extends keyof AsleepEventType>(eventType: K, listener: (data: AsleepEventType[K]) => void) => () => void;
|
|
44
47
|
getTrackingDurationMinutes: () => number;
|
|
45
48
|
setError: (error: string | null) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AsleepStore.d.ts","sourceRoot":"","sources":["../src/AsleepStore.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EACZ,iBAAiB,
|
|
1
|
+
{"version":3,"file":"AsleepStore.d.ts","sourceRoot":"","sources":["../src/AsleepStore.ts"],"names":[],"mappings":"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"}
|
package/build/AsleepStore.js
CHANGED
|
@@ -21,6 +21,42 @@ const TERMINAL_TRACKING_ERROR_CODES = new Set([
|
|
|
21
21
|
"UPLOAD_TRACKING_TERMINATED", // iOS 403/429 closeSessionSilently; Android errorCode 23499
|
|
22
22
|
"INTERRUPTION_RECOVERY_FAILED", // iOS 3 failed auto-resume attempts (3.2.0+)
|
|
23
23
|
]);
|
|
24
|
+
// iOS SDK 3.2.0 stops the recorder without closing the native session when
|
|
25
|
+
// audio engine initialization fails. The session must be stopped and restarted.
|
|
26
|
+
const RECORDING_DEAD_ERROR_CODES = new Set(["AUDIO_INITIALIZATION_FAILED"]);
|
|
27
|
+
// iOS SDK 3.2.0 reports this when the audio engine cannot restart in the
|
|
28
|
+
// background. The consumer must call resumeTracking() after returning foreground.
|
|
29
|
+
const RECOVERY_REQUIRED_ERROR_CODES = new Set(["CANNOT_ACTIVATE_IN_BACKGROUND"]);
|
|
30
|
+
// Numeric-code twin of TERMINAL_TRACKING_ERROR_CODES, matched against the
|
|
31
|
+
// `sdkCode` payload field. Android SDK 3.2.x AsleepCore.onErrorCodeReceived
|
|
32
|
+
// tears the session down and dual-fires onFail + onFinish for exactly these
|
|
33
|
+
// codes (the native module suppresses the duplicate onFinish), so JS must
|
|
34
|
+
// clear tracking state here or isTracking stays stuck true.
|
|
35
|
+
// Must stay in sync with the Kotlin TERMINAL_TRACKING_ERROR_CODES companion
|
|
36
|
+
// set in android/src/main/java/ai/asleep/reactnative/AsleepModule.kt.
|
|
37
|
+
const TERMINAL_TRACKING_SDK_CODES = new Set([
|
|
38
|
+
11003, // ERR_AUDIO
|
|
39
|
+
22000,
|
|
40
|
+
22401,
|
|
41
|
+
22409,
|
|
42
|
+
22422,
|
|
43
|
+
22500, // ERR_CREATE_*
|
|
44
|
+
23499, // ERR_UPLOAD_TRACKING_TERMINATED
|
|
45
|
+
24000,
|
|
46
|
+
24400,
|
|
47
|
+
24401,
|
|
48
|
+
24403,
|
|
49
|
+
24404,
|
|
50
|
+
24500, // ERR_CLOSE_*
|
|
51
|
+
]);
|
|
52
|
+
// Upload failures the native session survives: absent from the AsleepCore
|
|
53
|
+
// terminal set above, so the Android SDK 3.2.x keeps the session open and later
|
|
54
|
+
// uploads continue (UploadDataTask retries 5xx internally before reporting).
|
|
55
|
+
// Deliberately small — only codes verifiable in upstream sources.
|
|
56
|
+
const TRANSIENT_TRACKING_SDK_CODES = new Set([
|
|
57
|
+
23000, // ERR_UPLOAD_FAILED
|
|
58
|
+
23500, // ERR_UPLOAD_SERVER_ERROR
|
|
59
|
+
]);
|
|
24
60
|
const convertKeysToCamelCase = (obj) => {
|
|
25
61
|
if (Array.isArray(obj)) {
|
|
26
62
|
return obj.map(convertKeysToCamelCase);
|
|
@@ -39,7 +75,9 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
39
75
|
didClose: false,
|
|
40
76
|
isTracking: AsleepModule.isTracking ? AsleepModule.isTracking() : false,
|
|
41
77
|
isTrackingPaused: false,
|
|
78
|
+
isRecoveryRequired: false,
|
|
42
79
|
error: null,
|
|
80
|
+
errorInfo: null,
|
|
43
81
|
userId: null,
|
|
44
82
|
sessionId: null,
|
|
45
83
|
showDebugLog: false,
|
|
@@ -70,7 +108,7 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
70
108
|
throw new Error("Cannot execute setup while tracking is in progress.");
|
|
71
109
|
}
|
|
72
110
|
addLog("[setup] Start");
|
|
73
|
-
set({ isSetupInProgress: true, error: null });
|
|
111
|
+
set({ isSetupInProgress: true, error: null, errorInfo: null });
|
|
74
112
|
await AsleepModule.setup(config.apiKey, config.baseUrl, config.callbackUrl, config.service, config.enableODA);
|
|
75
113
|
// Store ODA enabled state. Clearing `error` on success keeps the
|
|
76
114
|
// reactive `useAsleep().error` field aligned with the actual SDK status
|
|
@@ -81,11 +119,12 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
81
119
|
isSetupInProgress: false,
|
|
82
120
|
isSetupComplete: true,
|
|
83
121
|
error: null,
|
|
122
|
+
errorInfo: null,
|
|
84
123
|
});
|
|
85
124
|
addLog(`[setup] Success - ODA enabled: ${config.enableODA || false}`);
|
|
86
125
|
}
|
|
87
126
|
catch (error) {
|
|
88
|
-
set({ error: error.message, isSetupInProgress: false });
|
|
127
|
+
set({ error: error.message, errorInfo: null, isSetupInProgress: false });
|
|
89
128
|
throw error;
|
|
90
129
|
}
|
|
91
130
|
},
|
|
@@ -94,12 +133,12 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
94
133
|
const { addLog } = get();
|
|
95
134
|
addLog("[initAsleepConfig] Start");
|
|
96
135
|
const result = await AsleepModule.initAsleepConfig(config.apiKey, config.userId, config.baseUrl, config.callbackUrl);
|
|
97
|
-
set({ isInitialized: true, error: null });
|
|
136
|
+
set({ isInitialized: true, error: null, errorInfo: null });
|
|
98
137
|
addLog("[initAsleepConfig] Success");
|
|
99
138
|
return result;
|
|
100
139
|
}
|
|
101
140
|
catch (error) {
|
|
102
|
-
set({ error: error.message });
|
|
141
|
+
set({ error: error.message, errorInfo: null });
|
|
103
142
|
throw error;
|
|
104
143
|
}
|
|
105
144
|
},
|
|
@@ -130,7 +169,7 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
130
169
|
};
|
|
131
170
|
}
|
|
132
171
|
catch (error) {
|
|
133
|
-
set({ error: error.message });
|
|
172
|
+
set({ error: error.message, errorInfo: null });
|
|
134
173
|
throw error;
|
|
135
174
|
}
|
|
136
175
|
},
|
|
@@ -197,6 +236,10 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
197
236
|
* @throws Error if prerequisites are not met or tracking is already in progress
|
|
198
237
|
*/
|
|
199
238
|
startTracking: async (config) => {
|
|
239
|
+
// Snapshot so the catch can tell a verdict published DURING this call
|
|
240
|
+
// (Android fires classified onTrackingFailed before rejecting the same
|
|
241
|
+
// promise) apart from a stale one left by an earlier failure.
|
|
242
|
+
const errorInfoBefore = get().errorInfo;
|
|
200
243
|
try {
|
|
201
244
|
const { requestRequiredPermissions, addLog, isODAEnabled, isSetupInProgress, hasCheckedStatus } = get();
|
|
202
245
|
// Enforce that checkAndRestoreTracking must be called first
|
|
@@ -246,8 +289,10 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
246
289
|
didClose: false,
|
|
247
290
|
isTracking: true,
|
|
248
291
|
isAnalyzing: false,
|
|
292
|
+
isRecoveryRequired: false,
|
|
249
293
|
trackingStartTime: new Date(),
|
|
250
294
|
error: null,
|
|
295
|
+
errorInfo: null,
|
|
251
296
|
});
|
|
252
297
|
await AsleepModule.startTracking(config);
|
|
253
298
|
if (isODAEnabled) {
|
|
@@ -259,8 +304,14 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
259
304
|
addLog("[startTracking] Success");
|
|
260
305
|
}
|
|
261
306
|
catch (error) {
|
|
307
|
+
// Preserve only a verdict that arrived during this call — the raw
|
|
308
|
+
// rejection message carries strictly less information than the
|
|
309
|
+
// numeric-code verdict. Reference inequality against the snapshot
|
|
310
|
+
// excludes stale verdicts, so guard failures still write the new error.
|
|
311
|
+
const nowInfo = get().errorInfo;
|
|
312
|
+
const classified = nowInfo !== null && nowInfo !== errorInfoBefore;
|
|
262
313
|
set({
|
|
263
|
-
error: error.message,
|
|
314
|
+
...(classified ? {} : { error: error.message, errorInfo: null }),
|
|
264
315
|
isTracking: false,
|
|
265
316
|
isAnalyzing: false,
|
|
266
317
|
trackingStartTime: null,
|
|
@@ -269,6 +320,8 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
269
320
|
}
|
|
270
321
|
},
|
|
271
322
|
stopTracking: async () => {
|
|
323
|
+
// Same dual-signal race as startTracking; see the snapshot rationale there.
|
|
324
|
+
const errorInfoBefore = get().errorInfo;
|
|
272
325
|
try {
|
|
273
326
|
const { addLog } = get();
|
|
274
327
|
addLog("[stopTracking] Start");
|
|
@@ -278,16 +331,29 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
278
331
|
...(result ? { sessionId: result } : {}),
|
|
279
332
|
isTracking: false,
|
|
280
333
|
isAnalyzing: false,
|
|
334
|
+
isRecoveryRequired: false,
|
|
281
335
|
trackingStartTime: null,
|
|
282
336
|
error: null,
|
|
337
|
+
errorInfo: null,
|
|
283
338
|
});
|
|
284
339
|
addLog(`[stopTracking] Success - result: ${result}`);
|
|
285
340
|
}
|
|
286
341
|
catch (error) {
|
|
287
|
-
|
|
342
|
+
const nowInfo = get().errorInfo;
|
|
343
|
+
if (nowInfo === null || nowInfo === errorInfoBefore)
|
|
344
|
+
set({ error: error.message, errorInfo: null });
|
|
288
345
|
throw error;
|
|
289
346
|
}
|
|
290
347
|
},
|
|
348
|
+
resumeTracking: async () => {
|
|
349
|
+
if (Platform.OS !== "ios") {
|
|
350
|
+
throw Object.assign(new Error("resumeTracking is only supported on iOS."), {
|
|
351
|
+
name: "AsleepPlatformError",
|
|
352
|
+
code: "UNSUPPORTED_PLATFORM",
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
await AsleepModule.resumeTracking();
|
|
356
|
+
},
|
|
291
357
|
getReport: async (sessionId) => {
|
|
292
358
|
// Snapshot the error before the await so we only clear it on success
|
|
293
359
|
// if no concurrent failure (e.g. onTrackingFailed firing during the
|
|
@@ -303,7 +369,7 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
303
369
|
// notification, and so we never clobber an unrelated tracking error
|
|
304
370
|
// that arrived during the await.
|
|
305
371
|
if (get().error !== null && get().error === errorBefore)
|
|
306
|
-
set({ error: null });
|
|
372
|
+
set({ error: null, errorInfo: null });
|
|
307
373
|
// Ensure the report has the expected AsleepReport structure
|
|
308
374
|
// Handle cases where native modules might return data in different formats
|
|
309
375
|
if (convertedReport && !convertedReport.session && convertedReport.sessionId) {
|
|
@@ -336,7 +402,7 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
336
402
|
// observing `useAsleep().error` directly.
|
|
337
403
|
if (typeof __DEV__ !== "undefined" && __DEV__)
|
|
338
404
|
console.warn("[Asleep] getReport failed:", error);
|
|
339
|
-
set({ error: error.message });
|
|
405
|
+
set({ error: error.message, errorInfo: null });
|
|
340
406
|
return null;
|
|
341
407
|
}
|
|
342
408
|
},
|
|
@@ -362,13 +428,13 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
362
428
|
});
|
|
363
429
|
addLog("[getReportList] Success");
|
|
364
430
|
if (get().error !== null && get().error === errorBefore)
|
|
365
|
-
set({ error: null });
|
|
431
|
+
set({ error: null, errorInfo: null });
|
|
366
432
|
return convertedList;
|
|
367
433
|
}
|
|
368
434
|
catch (error) {
|
|
369
435
|
if (typeof __DEV__ !== "undefined" && __DEV__)
|
|
370
436
|
console.warn("[Asleep] getReportList failed:", error);
|
|
371
|
-
set({ error: error.message });
|
|
437
|
+
set({ error: error.message, errorInfo: null });
|
|
372
438
|
return [];
|
|
373
439
|
}
|
|
374
440
|
},
|
|
@@ -380,10 +446,10 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
380
446
|
await AsleepModule.deleteSession(sessionId);
|
|
381
447
|
addLog("[deleteSession] Success");
|
|
382
448
|
if (get().error !== null && get().error === errorBefore)
|
|
383
|
-
set({ error: null });
|
|
449
|
+
set({ error: null, errorInfo: null });
|
|
384
450
|
}
|
|
385
451
|
catch (error) {
|
|
386
|
-
set({ error: error.message });
|
|
452
|
+
set({ error: error.message, errorInfo: null });
|
|
387
453
|
throw error;
|
|
388
454
|
}
|
|
389
455
|
},
|
|
@@ -396,13 +462,13 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
396
462
|
const convertedReport = convertKeysToCamelCase(averageReport);
|
|
397
463
|
addLog("[getAverageReport] Success");
|
|
398
464
|
if (get().error !== null && get().error === errorBefore)
|
|
399
|
-
set({ error: null });
|
|
465
|
+
set({ error: null, errorInfo: null });
|
|
400
466
|
return convertedReport;
|
|
401
467
|
}
|
|
402
468
|
catch (error) {
|
|
403
469
|
if (typeof __DEV__ !== "undefined" && __DEV__)
|
|
404
470
|
console.warn("[Asleep] getAverageReport failed:", error);
|
|
405
|
-
set({ error: error.message });
|
|
471
|
+
set({ error: error.message, errorInfo: null });
|
|
406
472
|
return null;
|
|
407
473
|
}
|
|
408
474
|
},
|
|
@@ -443,40 +509,34 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
443
509
|
// iOS uses native implementation
|
|
444
510
|
return AsleepModule.requestRequiredPermissions();
|
|
445
511
|
},
|
|
446
|
-
setCustomNotification: async (
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
else {
|
|
451
|
-
if (typeof __DEV__ !== "undefined" && __DEV__)
|
|
452
|
-
console.warn("[Asleep] setCustomNotification is not supported on this platform");
|
|
453
|
-
}
|
|
512
|
+
setCustomNotification: async (_title, _text) => {
|
|
513
|
+
// Native method removed; notification config now flows through startTracking options.
|
|
514
|
+
if (typeof __DEV__ !== "undefined" && __DEV__)
|
|
515
|
+
console.warn("[Asleep] setCustomNotification is deprecated and a no-op; pass `{ android: { notification: { title, text, icon } } }` to startTracking() instead");
|
|
454
516
|
},
|
|
455
517
|
enableLog: (print) => {
|
|
518
|
+
if (Platform.OS === "ios")
|
|
519
|
+
AsleepModule.enableLog(print);
|
|
456
520
|
set({ showDebugLog: print });
|
|
457
521
|
},
|
|
458
522
|
requestAnalysis: async () => {
|
|
459
523
|
try {
|
|
460
|
-
const { addLog } = get();
|
|
524
|
+
const { addLog, showDebugLog } = get();
|
|
461
525
|
addLog("[requestAnalysis] Start");
|
|
462
|
-
set({ isAnalyzing: true, error: null });
|
|
526
|
+
set({ isAnalyzing: true, error: null, errorInfo: null });
|
|
463
527
|
const result = await AsleepModule.requestAnalysis();
|
|
464
528
|
const convertedResult = convertKeysToCamelCase(result);
|
|
465
|
-
//
|
|
466
|
-
// Android
|
|
467
|
-
// iOS
|
|
468
|
-
if (
|
|
469
|
-
|
|
470
|
-
set({ analysisResult: convertedResult, isAnalyzing: false });
|
|
471
|
-
}
|
|
472
|
-
// For iOS, isAnalyzing will be set to false when onAnalysisResult event fires
|
|
473
|
-
addLog(`[requestAnalysis] Request sent - ${JSON.stringify(convertedResult)}`);
|
|
529
|
+
// analysisResult and isAnalyzing are owned by the onAnalysisResult event handler on both
|
|
530
|
+
// platforms. Android resolves the promise with the full session AND fires the event;
|
|
531
|
+
// iOS resolves with an ack only. Writing state here would double-update on Android.
|
|
532
|
+
if (showDebugLog)
|
|
533
|
+
addLog(`[requestAnalysis] Request sent - ${JSON.stringify(convertedResult)}`);
|
|
474
534
|
return convertedResult;
|
|
475
535
|
}
|
|
476
536
|
catch (error) {
|
|
477
537
|
if (typeof __DEV__ !== "undefined" && __DEV__)
|
|
478
538
|
console.warn("[Asleep] requestAnalysis failed:", error);
|
|
479
|
-
set({ error: error.message, isAnalyzing: false });
|
|
539
|
+
set({ error: error.message, errorInfo: null, isAnalyzing: false });
|
|
480
540
|
return null;
|
|
481
541
|
}
|
|
482
542
|
},
|
|
@@ -491,8 +551,10 @@ export const useAsleepStore = create()(subscribeWithSelector((set, get) => ({
|
|
|
491
551
|
return Math.floor((Date.now() - trackingStartTime.getTime()) / (1000 * 60));
|
|
492
552
|
},
|
|
493
553
|
// internal actions
|
|
494
|
-
setError
|
|
495
|
-
|
|
554
|
+
// setError takes a raw string, so any structured classification is stale;
|
|
555
|
+
// reset errorInfo rather than let a previous event's category linger.
|
|
556
|
+
setError: (error) => set({ error, errorInfo: null }),
|
|
557
|
+
clearError: () => set({ error: null, errorInfo: null }),
|
|
496
558
|
setUserId: (userId) => set({ userId }),
|
|
497
559
|
setSessionId: (sessionId) => set({ sessionId }),
|
|
498
560
|
setIsTracking: (isTracking) => set({ isTracking }),
|
|
@@ -554,7 +616,9 @@ export const initializeAsleepListeners = () => {
|
|
|
554
616
|
// Connected: iOS didFailUserJoin, Android onFail (AsleepConfigListener)
|
|
555
617
|
onUserJoinFailed: (error) => {
|
|
556
618
|
const errorString = JSON.stringify(error);
|
|
557
|
-
|
|
619
|
+
// Not a tracking-runtime failure; errorInfo stays reserved for
|
|
620
|
+
// onTrackingFailed classification.
|
|
621
|
+
useAsleepStore.setState({ error: errorString, errorInfo: null });
|
|
558
622
|
addLog(`[onUserJoinFailed] error: ${errorString}`);
|
|
559
623
|
},
|
|
560
624
|
// Connected: iOS userDidDelete, Android NOT IMPLEMENTED
|
|
@@ -577,6 +641,11 @@ export const initializeAsleepListeners = () => {
|
|
|
577
641
|
// requestAnalysis() flips isAnalyzing internally; no separate setter
|
|
578
642
|
// needed before invoking it (avoids a duplicate subscriber notification).
|
|
579
643
|
const state = useAsleepStore.getState();
|
|
644
|
+
// A completed upload is the only positive proof that recording actually came
|
|
645
|
+
// back — didResume fires before the engine restart is even attempted, so it
|
|
646
|
+
// cannot be trusted to clear this.
|
|
647
|
+
if (state.isRecoveryRequired)
|
|
648
|
+
useAsleepStore.setState({ isRecoveryRequired: false });
|
|
580
649
|
const triggerAnalysis = () => state.requestAnalysis().catch((error) => {
|
|
581
650
|
addLog(`[onTrackingUploaded] Auto analysis failed: ${error.message}`);
|
|
582
651
|
state.setIsAnalyzing(false);
|
|
@@ -596,21 +665,91 @@ export const initializeAsleepListeners = () => {
|
|
|
596
665
|
sessionId: data.sessionId,
|
|
597
666
|
isTracking: false,
|
|
598
667
|
isAnalyzing: false,
|
|
668
|
+
isRecoveryRequired: false,
|
|
599
669
|
didClose: true,
|
|
600
670
|
trackingStartTime: null,
|
|
601
671
|
});
|
|
602
672
|
addLog(`[onTrackingClosed] sessionId: ${data.sessionId}`);
|
|
603
673
|
},
|
|
604
674
|
// Connected: iOS didFail, Android onFail (AsleepTrackingListener)
|
|
605
|
-
//
|
|
606
|
-
//
|
|
607
|
-
//
|
|
675
|
+
// Four state buckets, each writing tracking state in the same setState as the
|
|
676
|
+
// error so subscribers see one event: terminal (native session already gone),
|
|
677
|
+
// recording-dead (recorder torn down but session still open — clearing
|
|
678
|
+
// isTracking is what unblocks a restart), recovery-required (resumeTracking()
|
|
679
|
+
// in foreground can revive it), and everything else (error only).
|
|
680
|
+
// The two dead-session buckets must also clear isRecoveryRequired: iOS retries
|
|
681
|
+
// cannotActivateInBackground and then gives up with interruptionRecoveryFailed,
|
|
682
|
+
// and no upload will ever arrive to clear the flag on that path.
|
|
683
|
+
// The bucket verdict is also published as errorInfo.category (with the
|
|
684
|
+
// else-bucket split into "transient" vs "unknown") so consumers can gate
|
|
685
|
+
// log severity on data instead of re-deriving code lists themselves.
|
|
608
686
|
onTrackingFailed: (error) => {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
687
|
+
// The explicit iOS string buckets must win before the numeric terminal
|
|
688
|
+
// fallback: the numeric set encodes Android teardown semantics, and iOS
|
|
689
|
+
// reuses 11003 (.audioInitializationFailed -> .audio) for a failure whose
|
|
690
|
+
// session is still open. The numeric fallback still matters on iOS for
|
|
691
|
+
// start/stop failures that arrive as UNKNOWN_ERROR + 22xxx/24xxx and must
|
|
692
|
+
// clear the optimistically-set isTracking.
|
|
693
|
+
const recordingDead = !!(error && RECORDING_DEAD_ERROR_CODES.has(error.code));
|
|
694
|
+
const recoveryRequired = !!(error && RECOVERY_REQUIRED_ERROR_CODES.has(error.code));
|
|
695
|
+
const terminal = !!(error &&
|
|
696
|
+
!recordingDead &&
|
|
697
|
+
!recoveryRequired &&
|
|
698
|
+
(TERMINAL_TRACKING_ERROR_CODES.has(error.code) || TERMINAL_TRACKING_SDK_CODES.has(error.sdkCode)));
|
|
699
|
+
const transient = !!(error && TRANSIENT_TRACKING_SDK_CODES.has(error.sdkCode));
|
|
700
|
+
let category;
|
|
701
|
+
if (recordingDead)
|
|
702
|
+
category = "recordingDead";
|
|
703
|
+
else if (recoveryRequired)
|
|
704
|
+
category = "recoveryRequired";
|
|
705
|
+
else if (terminal)
|
|
706
|
+
category = "terminal";
|
|
707
|
+
else if (transient)
|
|
708
|
+
category = "transient";
|
|
709
|
+
else
|
|
710
|
+
category = "unknown";
|
|
711
|
+
// Category rides along in the stringified error too, so consumers still
|
|
712
|
+
// parsing the legacy string see the same verdict as errorInfo readers.
|
|
713
|
+
const errorString = JSON.stringify(error ? { ...error, category } : error);
|
|
714
|
+
const errorInfo = error
|
|
715
|
+
? {
|
|
716
|
+
code: typeof error.code === "string" ? error.code : "UNKNOWN_ERROR",
|
|
717
|
+
category,
|
|
718
|
+
...(typeof error.sdkCode === "number" ? { sdkCode: error.sdkCode } : {}),
|
|
719
|
+
...(typeof error.message === "string" ? { message: error.message } : {}),
|
|
720
|
+
...(typeof error.caseName === "string" ? { caseName: error.caseName } : {}),
|
|
721
|
+
}
|
|
722
|
+
: null;
|
|
723
|
+
let nextState;
|
|
724
|
+
if (terminal) {
|
|
725
|
+
nextState = {
|
|
726
|
+
error: errorString,
|
|
727
|
+
errorInfo,
|
|
728
|
+
isTracking: false,
|
|
729
|
+
isAnalyzing: false,
|
|
730
|
+
isRecoveryRequired: false,
|
|
731
|
+
didClose: true,
|
|
732
|
+
trackingStartTime: null,
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
else if (recordingDead) {
|
|
736
|
+
nextState = {
|
|
737
|
+
error: errorString,
|
|
738
|
+
errorInfo,
|
|
739
|
+
isTracking: false,
|
|
740
|
+
isAnalyzing: false,
|
|
741
|
+
isRecoveryRequired: false,
|
|
742
|
+
didClose: false,
|
|
743
|
+
trackingStartTime: null,
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
else if (recoveryRequired) {
|
|
747
|
+
nextState = { error: errorString, errorInfo, isTracking: true, isRecoveryRequired: true };
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
nextState = { error: errorString, errorInfo };
|
|
751
|
+
}
|
|
752
|
+
useAsleepStore.setState(nextState);
|
|
614
753
|
addLog(`[onTrackingError] error: ${errorString}`);
|
|
615
754
|
},
|
|
616
755
|
// Connected: iOS didInterrupt, Android NOT IMPLEMENTED
|
|
@@ -623,16 +762,18 @@ export const initializeAsleepListeners = () => {
|
|
|
623
762
|
// retry) reach this handler without a preceding didInterrupt, and the stale error
|
|
624
763
|
// should still be cleared. Only the paused-state mutation is gated, to dedup the
|
|
625
764
|
// iOS 3.2.1+ double fire from handleRecovering -> handleResumed.
|
|
765
|
+
// isRecoveryRequired, not isTrackingPaused, is authoritative when recording is
|
|
766
|
+
// dead because didResume fires before the engine restart is attempted.
|
|
626
767
|
onTrackingResumed: () => {
|
|
627
768
|
const wasPaused = useAsleepStore.getState().isTrackingPaused;
|
|
628
|
-
useAsleepStore.setState(wasPaused ? { error: null, isTrackingPaused: false } : { error: null });
|
|
769
|
+
useAsleepStore.setState(wasPaused ? { error: null, errorInfo: null, isTrackingPaused: false } : { error: null, errorInfo: null });
|
|
629
770
|
addLog(wasPaused ? `[onTrackingResumed]` : `[onTrackingResumed] (no prior pause; error cleared)`);
|
|
630
771
|
},
|
|
631
772
|
// Connected: iOS micPermissionWasDenied, Android NOT IMPLEMENTED
|
|
632
773
|
onMicPermissionDenied: () => {
|
|
633
774
|
addLog(`[onMicPermissionDenied]`);
|
|
634
775
|
},
|
|
635
|
-
// Connected: iOS
|
|
776
|
+
// Connected: iOS AsleepLogger callbacks, Android sendEvent called directly
|
|
636
777
|
onDebugLog: (data) => {
|
|
637
778
|
addLog(`[onDebugLog] message: ${data.message}`);
|
|
638
779
|
},
|
|
@@ -644,7 +785,12 @@ export const initializeAsleepListeners = () => {
|
|
|
644
785
|
// Connected: iOS setupDidFail, Android onFail (AsleepSetupListener)
|
|
645
786
|
onSetupDidFail: (data) => {
|
|
646
787
|
const errorString = JSON.stringify(data);
|
|
647
|
-
useAsleepStore.setState({
|
|
788
|
+
useAsleepStore.setState({
|
|
789
|
+
error: errorString,
|
|
790
|
+
errorInfo: null,
|
|
791
|
+
isSetupInProgress: false,
|
|
792
|
+
isSetupComplete: false,
|
|
793
|
+
});
|
|
648
794
|
addLog(`[onSetupDidFail] error: ${errorString}`);
|
|
649
795
|
},
|
|
650
796
|
// Connected: iOS setupInProgress, Android onProgress (AsleepSetupListener)
|
|
@@ -653,9 +799,13 @@ export const initializeAsleepListeners = () => {
|
|
|
653
799
|
addLog(`[onSetupInProgress] progress: ${data.progress}%`);
|
|
654
800
|
},
|
|
655
801
|
// Connected: iOS analyzing (session), Android onSleepDataReceived (AsleepSleepDataListener)
|
|
802
|
+
// Android serializes snake_case; normalize so both platforms match AsleepAnalysisResult.
|
|
656
803
|
onAnalysisResult: (data) => {
|
|
657
|
-
|
|
658
|
-
|
|
804
|
+
const normalized = convertKeysToCamelCase(data);
|
|
805
|
+
useAsleepStore.setState({ analysisResult: normalized, isAnalyzing: false });
|
|
806
|
+
if (useAsleepStore.getState().showDebugLog) {
|
|
807
|
+
addLog(`[onAnalysisResult] ${JSON.stringify(normalized)}`);
|
|
808
|
+
}
|
|
659
809
|
},
|
|
660
810
|
};
|
|
661
811
|
// register all event listeners
|