react-native-asleep 0.0.5 → 0.0.8

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.
@@ -4,7 +4,6 @@ import ai.asleep.asleepsdk.Asleep
4
4
  import ai.asleep.asleepsdk.data.AsleepConfig
5
5
  import ai.asleep.asleepsdk.data.Report
6
6
  import ai.asleep.asleepsdk.data.SleepSession
7
- import ai.asleep.reactnative.service.AsleepService
8
7
  import ai.asleep.asleepsdk.tracking.Reports
9
8
  import ai.asleep.asleepsdk.tracking.SleepTrackingManager
10
9
  import com.google.gson.Gson
@@ -37,10 +36,6 @@ import android.app.Application
37
36
  import kotlinx.coroutines.*
38
37
  import kotlin.coroutines.resume
39
38
  import kotlin.coroutines.resumeWithException
40
- import ai.asleep.reactnative.IAsleepService
41
- import ai.asleep.reactnative.IListener
42
- import ai.asleep.reactnative.data.ErrorCode
43
- import ai.asleep.reactnative.utils.PreferenceHelper
44
39
  import android.os.DeadObjectException
45
40
  import android.util.Log
46
41
 
@@ -56,9 +51,11 @@ class AsleepModule : Module() {
56
51
  val sequence: LiveData<Int?> get() = _sequence
57
52
 
58
53
  private var _reportManager: Reports? = null
59
-
60
- private var asleepService: IAsleepService? = null
61
- private var isBound = false
54
+
55
+ // Added variables to replace PreferenceHelper
56
+ private var isTracking = false
57
+ private var savedApiKey: String? = null
58
+ private var savedUserId: String? = null
62
59
 
63
60
  val trackingState: LiveData<TrackingState> get() = _trackingState
64
61
  private var _trackingState = MutableLiveData(TrackingState.STATE_TRACKING_STOPPED)
@@ -67,124 +64,67 @@ class AsleepModule : Module() {
67
64
  companion object {
68
65
  public const val MICROPHONE_PERMISSION_REQUEST_CODE = 1001
69
66
  }
67
+
70
68
 
69
+ override fun definition() = ModuleDefinition {
70
+ Name("Asleep")
71
71
 
72
- private val listener = object : IListener.Stub() {
73
- override fun onUserIdReceived(userId: String) {
74
- sendEvent("onDebugLog", mapOf("message" to "onUserIdReceived: $userId"))
75
- sendEvent("onUserJoined", mapOf("userId" to userId))
76
- }
77
-
78
- override fun onSessionIdReceived(sessionId: String) {
79
- sendEvent("onDebugLog", mapOf("message" to "onSessionIdReceived: $sessionId"))
80
- sendEvent("onTrackingClosed", mapOf("sessionId" to sessionId))
81
- _sessionId.postValue(sessionId)
82
- _trackingState.postValue(TrackingState.STATE_TRACKING_STARTED)
83
-
84
- }
85
-
86
- override fun onSequenceReceived(sequence: Int) {
87
- sendEvent("onDebugLog", mapOf("message" to "onSequenceReceived: $sequence"))
88
- sendEvent("onTrackingUploaded", mapOf("sequence" to sequence))
89
- _sequence.postValue(sequence)
90
- }
91
-
92
- override fun onErrorCodeReceived(errorCode: ErrorCode) {
93
- sendEvent("onDebugLog", mapOf("message" to "onErrorCodeReceived: ${errorCode.code}"))
94
- sendEvent("onTrackingFailed", mapOf("errorCode" to errorCode.code))
95
- }
96
-
97
- override fun onStopTrackingReceived(sessionId: String) {
98
- sendEvent("onDebugLog", mapOf("message" to "onStopTrackingReceived: $sessionId"))
99
- sendEvent("onTrackingClosed", mapOf("sessionId" to sessionId))
100
- _sessionId.postValue(sessionId)
101
- _trackingState.postValue(TrackingState.STATE_TRACKING_STOPPED)
102
- }
103
- }
104
-
105
- private val connection = object : ServiceConnection {
106
- override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
107
- try {
108
- asleepService = IAsleepService.Stub.asInterface(service)
109
- asleepService?.registerListener(listener)
110
- isBound = true
111
- } catch (e: Exception) {
112
- Log.e("AsleepModule", "Service connection failed", e)
113
- }
114
- }
72
+ Events("onTrackingCreated", "onTrackingUploaded", "onTrackingClosed", "onTrackingFailed",
73
+ "onTrackingInterrupted", "onTrackingResumed", "onMicPermissionDenied",
74
+ "onUserJoined", "onUserJoinFailed", "onUserDeleted", "onDebugLog",
75
+ "onSetupDidComplete", "onSetupDidFail", "onSetupInProgress")
115
76
 
116
- override fun onServiceDisconnected(name: ComponentName?) {
77
+ AsyncFunction("setup") { apiKey: String, baseUrl: String?, callbackUrl: String?, service: String?, enableODA: Boolean?, promise: Promise ->
117
78
  try {
118
- if (isBound) {
119
- asleepService?.unregisterListener(listener)
120
- asleepService = null
121
- isBound = false
122
-
123
- appContext.currentActivity?.let { activity ->
124
- if (!activity.isFinishing) {
125
- sendEvent("onServiceDisconnected", mapOf("message" to "Service disconnected"))
79
+ val context = appContext.reactContext!!.applicationContext as Application
80
+
81
+ Asleep.setup(
82
+ context = context,
83
+ apiKey = apiKey,
84
+ baseUrl = baseUrl,
85
+ callbackUrl = callbackUrl,
86
+ service = service ?: "SleepTracking",
87
+ enableODA = enableODA,
88
+ asleepSetupListener = object : Asleep.AsleepSetupListener {
89
+ override fun onComplete() {
90
+ sendEvent("onSetupDidComplete", emptyMap<String, Any>())
91
+ sendEvent("onDebugLog", mapOf("message" to "Setup completed"))
92
+ promise.resolve("Setup completed")
93
+ }
94
+
95
+ override fun onProgress(progress: Int) {
96
+ sendEvent("onSetupInProgress", mapOf("progress" to progress))
97
+ sendEvent("onDebugLog", mapOf("message" to "Setup progress: $progress%"))
98
+ }
99
+
100
+ override fun onFail(errorCode: Int, detail: String) {
101
+ sendEvent("onSetupDidFail", mapOf("error" to detail))
102
+ sendEvent("onDebugLog", mapOf("message" to "Setup failed: $errorCode - $detail"))
103
+ promise.reject("SETUP_FAILED", "Setup failed: $errorCode - $detail", null)
126
104
  }
127
105
  }
128
- }
106
+ )
129
107
  } catch (e: Exception) {
130
- Log.e("AsleepModule", "Service disconnection error", e)
131
- }
132
- }
133
- }
134
-
135
-
136
- fun bindService() {
137
- try {
138
- if (!isBound) {
139
- val intent = Intent(appContext.reactContext, AsleepService::class.java)
140
- appContext.reactContext?.bindService(intent, connection, Context.BIND_AUTO_CREATE)
141
- }
142
- } catch (e: Exception) {
143
- Log.e("AsleepModule", "bindService failed", e)
144
- }
145
- }
146
-
147
- fun unbindService() {
148
- try {
149
- if (isBound) {
150
- appContext.reactContext?.unbindService(connection)
151
- asleepService = null
152
- isBound = false
108
+ sendEvent("onDebugLog", mapOf("message" to "Setup failed: ${e.message}"))
109
+ promise.reject("UNEXPECTED_ERROR", "Setup failed: ${e.message}", e)
153
110
  }
154
- } catch (e: Exception) {
155
- Log.e("AsleepModule", "unbindService failed", e)
156
111
  }
157
- }
158
-
159
- override fun definition() = ModuleDefinition {
160
- Name("Asleep")
161
-
162
- Events("onTrackingCreated", "onTrackingUploaded", "onTrackingClosed", "onTrackingFailed", "onUserJoined", "onUserJoinFailed", "onDebugLog")
163
112
 
164
113
  AsyncFunction("initAsleepConfig") { apiKey: String, userId: String?, baseUrl: String?, callbackUrl: String?, promise: Promise ->
165
114
  try {
166
115
  val context = appContext.reactContext!!.applicationContext as Application
167
- val isTracking = PreferenceHelper.isTracking(context)
168
- val savedApiKey = PreferenceHelper.getApiKey(context)
169
- val savedUserId = PreferenceHelper.getUserId(context)
170
116
 
171
-
172
117
  if (isTracking && savedApiKey == apiKey && savedUserId == userId) {
173
-
174
- if (AsleepService.isAsleepServiceRunning(context)) {
175
-
176
- bindService()
177
- promise.resolve("Service reconnected")
178
- sendEvent("onDebugLog", mapOf("message" to "Service reconnected"))
179
- return@AsyncFunction
180
- }
118
+ promise.resolve(mapOf("userId" to (savedUserId ?: "")))
119
+ sendEvent("onDebugLog", mapOf("message" to "Service reconnected"))
120
+ return@AsyncFunction
181
121
  }
182
122
 
183
-
184
- PreferenceHelper.putApiKey(context, apiKey)
123
+ // Store API key in memory instead of preferences
124
+ savedApiKey = apiKey
185
125
 
186
126
  Asleep.initAsleepConfig(
187
- context = appContext.reactContext!!.applicationContext as Application,
127
+ context = context,
188
128
  apiKey = apiKey,
189
129
  userId = userId,
190
130
  baseUrl = baseUrl,
@@ -193,11 +133,15 @@ class AsleepModule : Module() {
193
133
  object : Asleep.AsleepConfigListener {
194
134
  override fun onSuccess(userId: String?, asleepConfig: AsleepConfig?) {
195
135
  if (userId != null) {
196
- PreferenceHelper.putUserId(appContext.reactContext!!.applicationContext as Application, userId)
136
+ sendEvent("onDebugLog", mapOf("message" to "UserId is not null"))
137
+ // Store userId in memory instead of preferences
138
+ savedUserId = userId
139
+ sendEvent("onUserJoined", mapOf("userId" to userId))
197
140
  }
198
141
  _asleepConfig = asleepConfig
199
142
 
200
143
  if (_asleepConfig != null) {
144
+ sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not null"))
201
145
  _reportManager = Asleep.createReports(_asleepConfig)
202
146
  } else {
203
147
  sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is null"))
@@ -205,18 +149,21 @@ class AsleepModule : Module() {
205
149
  return
206
150
  }
207
151
 
208
- bindService()
152
+ sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not null"))
209
153
 
210
- promise.resolve("Initialization successful")
154
+ // Return userId in the response instead of just a success message
155
+ promise.resolve(mapOf("userId" to (userId ?: "")))
211
156
  try {
212
- sendEvent("onDebugLog", mapOf("message" to "Initialization successful"))
157
+ sendEvent("onDebugLog", mapOf("message" to "Initialization successful with userId: $userId"))
213
158
  } catch (e: Exception) {
159
+ sendEvent("onDebugLog", mapOf("message" to "Error sending debug log: ${e.message}"))
214
160
  println("Error sending debug log: ${e.message}")
215
161
  }
216
162
  }
217
163
 
218
164
  override fun onFail(errorCode: Int, detail: String) {
219
165
  sendEvent("onDebugLog", mapOf("message" to "Initialization failed: $errorCode - $detail"))
166
+ sendEvent("onUserJoinFailed", mapOf("errorCode" to errorCode, "detail" to detail))
220
167
  promise.reject("INITIALIZATION_FAILED", "Initialization failed: $errorCode - $detail", null)
221
168
  }
222
169
  }
@@ -229,46 +176,86 @@ class AsleepModule : Module() {
229
176
  }
230
177
 
231
178
  AsyncFunction("startTracking") { promise: Promise ->
232
- val activity = appContext.currentActivity
233
- val context = appContext.reactContext!!.applicationContext as Application
234
- PreferenceHelper.putIsTracking(context, true)
235
- if (activity != null) {
236
- val intent = Intent(activity, AsleepService::class.java)
237
- intent.action = AsleepService.ACTION_START_TRACKING
238
-
239
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
240
- activity.startForegroundService(intent)
179
+ try {
180
+ val audioPermission = ContextCompat.checkSelfPermission(appContext.reactContext!!, Manifest.permission.RECORD_AUDIO)
181
+ val fgsPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
182
+ ContextCompat.checkSelfPermission(appContext.reactContext!!, Manifest.permission.FOREGROUND_SERVICE_MICROPHONE)
241
183
  } else {
242
- activity.startService(intent)
184
+ sendEvent("onDebugLog", mapOf("message" to "Requesting permissions"))
185
+ PackageManager.PERMISSION_GRANTED
243
186
  }
244
- promise.resolve("Tracking started")
245
- } else {
246
- promise.reject("ACTIVITY_NOT_FOUND", "Activity not found", null)
187
+ if (audioPermission != PackageManager.PERMISSION_GRANTED || fgsPermission != PackageManager.PERMISSION_GRANTED) {
188
+ ActivityCompat.requestPermissions(
189
+ appContext.currentActivity!!,
190
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
191
+ sendEvent("onDebugLog", mapOf("message" to "Requesting permissions"))
192
+ arrayOf(Manifest.permission.RECORD_AUDIO, Manifest.permission.FOREGROUND_SERVICE_MICROPHONE)
193
+ } else {
194
+ sendEvent("onDebugLog", mapOf("message" to "Requesting permissions"))
195
+ arrayOf(Manifest.permission.RECORD_AUDIO)
196
+ },
197
+ MICROPHONE_PERMISSION_REQUEST_CODE
198
+ )
199
+ }
200
+
201
+
202
+
203
+
204
+ val context = appContext.reactContext!!.applicationContext as Application
205
+ sendEvent("onDebugLog", mapOf("message" to "Starting tracking"))
206
+ if (_asleepConfig == null) {
207
+ sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is not initialized"))
208
+ promise.reject("UNINITIALIZED_CONFIG", "AsleepConfig is not initialized", null)
209
+ return@AsyncFunction
210
+ } else {
211
+ sendEvent("onDebugLog", mapOf("message" to "AsleepConfig is initialized"))
212
+ }
213
+
214
+ sendEvent("onDebugLog", mapOf("message" to "Starting tracking!"))
215
+
216
+ Asleep.beginSleepTracking(
217
+ asleepConfig = _asleepConfig!!,
218
+ asleepTrackingListener = object : Asleep.AsleepTrackingListener {
219
+ override fun onFail(errorCode: Int, detail: String) {
220
+ sendEvent("onDebugLog", mapOf("message" to "Sleep tracking failed: $errorCode - $detail"))
221
+ promise.reject("TRACKING_FAILED", "Sleep tracking failed: $errorCode - $detail", null)
222
+ }
223
+
224
+ override fun onFinish(sessionId: String?) {
225
+ isTracking = false
226
+ sendEvent("onTrackingClosed", mapOf("sessionId" to (sessionId ?: "")))
227
+ sendEvent("onDebugLog", mapOf("message" to "Sleep tracking finished: $sessionId"))
228
+ }
229
+
230
+ override fun onPerform(sequence: Int) {
231
+ sendEvent("onTrackingUploaded", mapOf("sequence" to sequence))
232
+ sendEvent("onDebugLog", mapOf("message" to "Sleep tracking performing: $sequence"))
233
+ }
234
+
235
+ override fun onStart(sessionId: String) {
236
+ isTracking = true
237
+ sendEvent("onTrackingCreated", mapOf("sessionId" to sessionId))
238
+ sendEvent("onDebugLog", mapOf("message" to "Sleep tracking started: $sessionId"))
239
+ promise.resolve(mapOf("sessionId" to sessionId))
240
+ }
241
+ }
242
+ )
243
+
244
+ sendEvent("onDebugLog", mapOf("message" to "Tracking started"))
245
+ } catch (e: Exception) {
246
+ sendEvent("onDebugLog", mapOf("message" to "Failed to start tracking: ${e.message}"))
247
+ promise.reject("UNEXPECTED_ERROR", "Failed to start tracking: ${e.message}", e)
247
248
  }
248
249
  }
249
250
 
250
251
  Function("isTracking") {
251
- val context = appContext.reactContext!!.applicationContext as Application
252
- return@Function PreferenceHelper.isTracking(context)
252
+ return@Function isTracking
253
253
  }
254
254
 
255
255
  AsyncFunction("stopTracking") { promise: Promise ->
256
- val activity = appContext.currentActivity
257
- val context = appContext.reactContext!!.applicationContext as Application
258
- PreferenceHelper.putIsTracking(context, false)
259
- if (activity != null) {
260
- val intent = Intent(activity, AsleepService::class.java)
261
- intent.action = AsleepService.ACTION_STOP_TRACKING
262
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
263
- activity.startForegroundService(intent)
264
- } else {
265
- activity.startService(intent)
266
- }
267
- promise.resolve("Tracking stopped")
268
- } else {
269
- promise.reject("ACTIVITY_NOT_FOUND", "Activity not found", null)
270
- }
271
-
256
+ Asleep.endSleepTracking()
257
+ isTracking = false
258
+ promise.resolve("Tracking stopped")
272
259
  }
273
260
 
274
261
  AsyncFunction("getReport") { sessionId: String, promise: Promise ->
@@ -352,18 +339,6 @@ class AsleepModule : Module() {
352
339
  }
353
340
  }
354
341
  }
355
-
356
- AsyncFunction("setCustomNotification") { title: String, text: String, promise: Promise ->
357
- try {
358
- val context = appContext.reactContext!!.applicationContext as Application
359
- PreferenceHelper.putNotificationTitle(context, title)
360
- PreferenceHelper.putNotificationText(context, text)
361
- promise.resolve(null)
362
- } catch (e: Exception) {
363
- promise.reject("NOTIFICATION_ERROR", "Failed to set custom notification: ${e.message}", e)
364
- }
365
- }
366
-
367
342
  }
368
343
 
369
344
  private fun <T> T.serializeToMap(): Map<String, Any> {
@@ -4,6 +4,13 @@ export type AsleepConfig = {
4
4
  baseUrl?: string;
5
5
  callbackUrl?: string;
6
6
  };
7
+ export type AsleepSetupConfig = {
8
+ apiKey: string;
9
+ baseUrl?: string;
10
+ callbackUrl?: string;
11
+ service?: string;
12
+ enableODA?: boolean;
13
+ };
7
14
  export type AsleepReport = {
8
15
  timezone: string;
9
16
  session: {
@@ -69,7 +76,9 @@ export type AsleepSession = {
69
76
  timeInBed?: number;
70
77
  };
71
78
  export type AsleepEventType = {
72
- onTrackingCreated: undefined;
79
+ onTrackingCreated: {
80
+ sessionId?: string;
81
+ };
73
82
  onTrackingUploaded: {
74
83
  sequence: number;
75
84
  };
@@ -86,5 +95,12 @@ export type AsleepEventType = {
86
95
  onDebugLog: {
87
96
  message: string;
88
97
  };
98
+ onSetupDidComplete: undefined;
99
+ onSetupDidFail: {
100
+ error: string;
101
+ };
102
+ onSetupInProgress: {
103
+ progress: number;
104
+ };
89
105
  };
90
106
  //# sourceMappingURL=Asleep.types.d.ts.map
@@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AE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,iBAAiB,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;CACzC,CAAC"}
@@ -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 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\nexport type AsleepSession = {\n sessionId: string;\n state: string;\n sessionStartTime: string;\n sessionEndTime?: string;\n timeInBed?: number;\n};\n\nexport type AsleepEventType = {\n onTrackingCreated: undefined;\n onTrackingUploaded: { sequence: number };\n onTrackingClosed: { sessionId: string };\n onTrackingFailed: undefined;\n onTrackingInterrupted: undefined;\n onTrackingResumed: undefined;\n onMicPermissionDenied: undefined;\n onUserJoined: undefined;\n onUserJoinFailed: undefined;\n onUserDeleted: undefined;\n onDebugLog: { message: string };\n};\n"]}
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\nexport type AsleepSession = {\n sessionId: string;\n state: string;\n sessionStartTime: string;\n sessionEndTime?: string;\n timeInBed?: number;\n};\n\nexport type AsleepEventType = {\n onTrackingCreated: { sessionId?: string };\n onTrackingUploaded: { sequence: number };\n onTrackingClosed: { sessionId: string };\n onTrackingFailed: undefined;\n onTrackingInterrupted: undefined;\n onTrackingResumed: undefined;\n onMicPermissionDenied: undefined;\n onUserJoined: undefined;\n onUserJoinFailed: undefined;\n onUserDeleted: undefined;\n onDebugLog: { message: string };\n onSetupDidComplete: undefined;\n onSetupDidFail: { error: string };\n onSetupInProgress: { progress: number };\n};\n"]}
@@ -0,0 +1,37 @@
1
+ import { AsleepConfig, AsleepSetupConfig, AsleepEventType, AsleepReport, AsleepSession } from "./Asleep.types";
2
+ export interface AsleepState {
3
+ didClose: boolean;
4
+ isTracking: boolean;
5
+ error: string | null;
6
+ userId: string | null;
7
+ sessionId: string | null;
8
+ showDebugLog: boolean;
9
+ log: string;
10
+ setup: (config: AsleepSetupConfig) => Promise<void>;
11
+ initAsleepConfig: (config: AsleepConfig) => Promise<void>;
12
+ startTracking: () => Promise<void>;
13
+ stopTracking: () => Promise<void>;
14
+ getReport: (sessionId: string) => Promise<AsleepReport | null>;
15
+ getReportList: (fromDate: string, toDate: string) => Promise<AsleepSession[]>;
16
+ requestMicrophonePermission: () => Promise<boolean>;
17
+ setCustomNotification: (title: string, text: string) => Promise<void>;
18
+ enableLog: (print: boolean) => void;
19
+ addEventListener: <K extends keyof AsleepEventType>(eventType: K, listener: (data: AsleepEventType[K]) => void) => () => void;
20
+ setError: (error: string | null) => void;
21
+ setUserId: (userId: string | null) => void;
22
+ setSessionId: (sessionId: string | null) => void;
23
+ setIsTracking: (isTracking: boolean) => void;
24
+ setDidClose: (didClose: boolean) => void;
25
+ addLog: (log: string) => void;
26
+ }
27
+ export declare const useAsleepStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<AsleepState>, "subscribe"> & {
28
+ subscribe: {
29
+ (listener: (selectedState: AsleepState, previousSelectedState: AsleepState) => void): () => void;
30
+ <U>(selector: (state: AsleepState) => U, listener: (selectedState: U, previousSelectedState: U) => void, options?: {
31
+ equalityFn?: ((a: U, b: U) => boolean) | undefined;
32
+ fireImmediately?: boolean;
33
+ } | undefined): () => void;
34
+ };
35
+ }>;
36
+ export declare const initializeAsleepListeners: () => () => void;
37
+ //# sourceMappingURL=AsleepStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AsleepStore.d.ts","sourceRoot":"","sources":["../src/AsleepStore.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,aAAa,EACd,MAAM,gBAAgB,CAAC;AAKxB,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IAGZ,KAAK,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,gBAAgB,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,YAAY,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC/D,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAC9E,2BAA2B,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IACpD,qBAAqB,EAAE,CAAC,KAAK,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