react-native-audio-api 0.11.0-alpha.4 → 0.11.0-alpha.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.
Files changed (141) hide show
  1. package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +164 -16
  2. package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioPlayer.kt +10 -8
  3. package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioRecorder.kt +10 -8
  4. package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +5 -2
  5. package/android/src/main/java/com/swmansion/audioapi/system/CentralizedForegroundService.kt +128 -0
  6. package/android/src/main/java/com/swmansion/audioapi/system/ForegroundServiceManager.kt +116 -0
  7. package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +115 -107
  8. package/android/src/main/java/com/swmansion/audioapi/system/PermissionRequestListener.kt +2 -1
  9. package/android/src/main/java/com/swmansion/audioapi/system/notification/BaseNotification.kt +47 -0
  10. package/android/src/main/java/com/swmansion/audioapi/system/notification/NotificationRegistry.kt +191 -0
  11. package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotification.kt +669 -0
  12. package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotificationReceiver.kt +33 -0
  13. package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotification.kt +303 -0
  14. package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotificationReceiver.kt +45 -0
  15. package/android/src/main/java/com/swmansion/audioapi/system/notification/SimpleNotification.kt +119 -0
  16. package/common/cpp/audioapi/utils/AudioFileProperties.h +17 -17
  17. package/ios/audioapi/ios/AudioAPIModule.h +2 -2
  18. package/ios/audioapi/ios/AudioAPIModule.mm +108 -18
  19. package/ios/audioapi/ios/core/NativeAudioRecorder.m +8 -1
  20. package/ios/audioapi/ios/system/AudioEngine.mm +2 -2
  21. package/ios/audioapi/ios/system/AudioSessionManager.mm +12 -9
  22. package/ios/audioapi/ios/system/NotificationManager.mm +1 -1
  23. package/ios/audioapi/ios/system/notification/BaseNotification.h +58 -0
  24. package/ios/audioapi/ios/system/notification/NotificationRegistry.h +70 -0
  25. package/ios/audioapi/ios/system/notification/NotificationRegistry.mm +172 -0
  26. package/ios/audioapi/ios/system/notification/PlaybackNotification.h +27 -0
  27. package/ios/audioapi/ios/system/notification/PlaybackNotification.mm +427 -0
  28. package/lib/commonjs/api.js +72 -1
  29. package/lib/commonjs/api.js.map +1 -1
  30. package/lib/commonjs/api.web.js +27 -14
  31. package/lib/commonjs/api.web.js.map +1 -1
  32. package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
  33. package/lib/commonjs/system/AudioManager.js +6 -9
  34. package/lib/commonjs/system/AudioManager.js.map +1 -1
  35. package/lib/commonjs/system/index.js +13 -0
  36. package/lib/commonjs/system/index.js.map +1 -1
  37. package/lib/commonjs/system/notification/PlaybackNotificationManager.js +135 -0
  38. package/lib/commonjs/system/notification/PlaybackNotificationManager.js.map +1 -0
  39. package/lib/commonjs/system/notification/RecordingNotificationManager.js +182 -0
  40. package/lib/commonjs/system/notification/RecordingNotificationManager.js.map +1 -0
  41. package/lib/commonjs/system/notification/SimpleNotificationManager.js +122 -0
  42. package/lib/commonjs/system/notification/SimpleNotificationManager.js.map +1 -0
  43. package/lib/commonjs/system/notification/index.js +45 -0
  44. package/lib/commonjs/system/notification/index.js.map +1 -0
  45. package/lib/commonjs/system/notification/types.js +6 -0
  46. package/lib/commonjs/system/notification/types.js.map +1 -0
  47. package/lib/commonjs/types.js +17 -17
  48. package/lib/commonjs/types.js.map +1 -1
  49. package/lib/commonjs/web-system/index.js +17 -0
  50. package/lib/commonjs/web-system/index.js.map +1 -0
  51. package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js +34 -0
  52. package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js.map +1 -0
  53. package/lib/commonjs/web-system/notification/RecordingNotificationManager.js +34 -0
  54. package/lib/commonjs/web-system/notification/RecordingNotificationManager.js.map +1 -0
  55. package/lib/commonjs/web-system/notification/index.js +21 -0
  56. package/lib/commonjs/web-system/notification/index.js.map +1 -0
  57. package/lib/module/api.js +4 -0
  58. package/lib/module/api.js.map +1 -1
  59. package/lib/module/api.web.js +3 -1
  60. package/lib/module/api.web.js.map +1 -1
  61. package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
  62. package/lib/module/system/AudioManager.js +6 -9
  63. package/lib/module/system/AudioManager.js.map +1 -1
  64. package/lib/module/system/index.js +1 -0
  65. package/lib/module/system/index.js.map +1 -1
  66. package/lib/module/system/notification/PlaybackNotificationManager.js +131 -0
  67. package/lib/module/system/notification/PlaybackNotificationManager.js.map +1 -0
  68. package/lib/module/system/notification/RecordingNotificationManager.js +178 -0
  69. package/lib/module/system/notification/RecordingNotificationManager.js.map +1 -0
  70. package/lib/module/system/notification/SimpleNotificationManager.js +118 -0
  71. package/lib/module/system/notification/SimpleNotificationManager.js.map +1 -0
  72. package/lib/module/system/notification/index.js +7 -0
  73. package/lib/module/system/notification/index.js.map +1 -0
  74. package/lib/module/system/notification/types.js +4 -0
  75. package/lib/module/system/notification/types.js.map +1 -0
  76. package/lib/module/types.js +17 -17
  77. package/lib/module/types.js.map +1 -1
  78. package/lib/module/web-system/index.js +4 -0
  79. package/lib/module/web-system/index.js.map +1 -0
  80. package/lib/module/web-system/notification/PlaybackNotificationManager.js +30 -0
  81. package/lib/module/web-system/notification/PlaybackNotificationManager.js.map +1 -0
  82. package/lib/module/web-system/notification/RecordingNotificationManager.js +30 -0
  83. package/lib/module/web-system/notification/RecordingNotificationManager.js.map +1 -0
  84. package/lib/module/web-system/notification/index.js +5 -0
  85. package/lib/module/web-system/notification/index.js.map +1 -0
  86. package/lib/typescript/api.d.ts +2 -0
  87. package/lib/typescript/api.d.ts.map +1 -1
  88. package/lib/typescript/api.web.d.ts +3 -1
  89. package/lib/typescript/api.web.d.ts.map +1 -1
  90. package/lib/typescript/events/types.d.ts +2 -2
  91. package/lib/typescript/events/types.d.ts.map +1 -1
  92. package/lib/typescript/specs/NativeAudioAPIModule.d.ts +16 -5
  93. package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
  94. package/lib/typescript/system/AudioManager.d.ts +4 -5
  95. package/lib/typescript/system/AudioManager.d.ts.map +1 -1
  96. package/lib/typescript/system/index.d.ts +1 -0
  97. package/lib/typescript/system/index.d.ts.map +1 -1
  98. package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts +22 -0
  99. package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts.map +1 -0
  100. package/lib/typescript/system/notification/RecordingNotificationManager.d.ts +23 -0
  101. package/lib/typescript/system/notification/RecordingNotificationManager.d.ts.map +1 -0
  102. package/lib/typescript/system/notification/SimpleNotificationManager.d.ts +20 -0
  103. package/lib/typescript/system/notification/SimpleNotificationManager.d.ts.map +1 -0
  104. package/lib/typescript/system/notification/index.d.ts +5 -0
  105. package/lib/typescript/system/notification/index.d.ts.map +1 -0
  106. package/lib/typescript/system/notification/types.d.ts +65 -0
  107. package/lib/typescript/system/notification/types.d.ts.map +1 -0
  108. package/lib/typescript/system/types.d.ts +0 -16
  109. package/lib/typescript/system/types.d.ts.map +1 -1
  110. package/lib/typescript/types.d.ts +16 -16
  111. package/lib/typescript/types.d.ts.map +1 -1
  112. package/lib/typescript/web-system/index.d.ts +2 -0
  113. package/lib/typescript/web-system/index.d.ts.map +1 -0
  114. package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts +19 -0
  115. package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts.map +1 -0
  116. package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts +19 -0
  117. package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts.map +1 -0
  118. package/lib/typescript/web-system/notification/index.d.ts +3 -0
  119. package/lib/typescript/web-system/notification/index.d.ts.map +1 -0
  120. package/package.json +1 -1
  121. package/src/api.ts +17 -0
  122. package/src/api.web.ts +7 -2
  123. package/src/events/types.ts +2 -3
  124. package/src/specs/NativeAudioAPIModule.ts +23 -7
  125. package/src/system/AudioManager.ts +10 -23
  126. package/src/system/index.ts +1 -0
  127. package/src/system/notification/PlaybackNotificationManager.ts +193 -0
  128. package/src/system/notification/RecordingNotificationManager.ts +242 -0
  129. package/src/system/notification/SimpleNotificationManager.ts +170 -0
  130. package/src/system/notification/index.ts +4 -0
  131. package/src/system/notification/types.ts +111 -0
  132. package/src/system/types.ts +0 -18
  133. package/src/types.ts +17 -17
  134. package/src/web-system/index.ts +1 -0
  135. package/src/web-system/notification/PlaybackNotificationManager.ts +60 -0
  136. package/src/web-system/notification/RecordingNotificationManager.ts +60 -0
  137. package/src/web-system/notification/index.ts +2 -0
  138. package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +0 -347
  139. package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +0 -273
  140. package/android/src/main/java/com/swmansion/audioapi/system/MediaReceiver.kt +0 -57
  141. package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionCallback.kt +0 -61
@@ -0,0 +1,242 @@
1
+ import { Platform } from 'react-native';
2
+ import { NativeAudioAPIModule } from '../../specs';
3
+ import { AudioEventEmitter, AudioEventSubscription } from '../../events';
4
+ import type {
5
+ NotificationManager,
6
+ RecordingNotificationInfo,
7
+ RecordingControlName,
8
+ RecordingNotificationEventName,
9
+ NotificationEvents,
10
+ } from './types';
11
+
12
+ /// Manager for recording notifications with controls.
13
+ class RecordingNotificationManager
14
+ implements
15
+ NotificationManager<
16
+ RecordingNotificationInfo,
17
+ RecordingNotificationInfo,
18
+ RecordingNotificationEventName
19
+ >
20
+ {
21
+ private notificationKey = 'recording';
22
+ private isRegistered = false;
23
+ private isShown = false;
24
+ private audioEventEmitter: AudioEventEmitter;
25
+ private isIOS = Platform.OS === 'ios';
26
+
27
+ constructor() {
28
+ this.audioEventEmitter = new AudioEventEmitter(global.AudioEventEmitter);
29
+ }
30
+
31
+ /// Register the recording notification (must be called before showing).
32
+ async register(): Promise<void> {
33
+ if (this.isRegistered) {
34
+ console.warn('RecordingNotification is already registered');
35
+ return;
36
+ }
37
+
38
+ // Recording notifications are only supported on Android
39
+ if (this.isIOS) {
40
+ this.isRegistered = true;
41
+ return;
42
+ }
43
+
44
+ if (!NativeAudioAPIModule) {
45
+ throw new Error('NativeAudioAPIModule is not available');
46
+ }
47
+
48
+ const result = await NativeAudioAPIModule.registerNotification(
49
+ 'recording',
50
+ this.notificationKey
51
+ );
52
+
53
+ if (result.error) {
54
+ throw new Error(result.error);
55
+ }
56
+
57
+ this.isRegistered = true;
58
+ }
59
+
60
+ /// Show the notification with initial metadata.
61
+ async show(info: RecordingNotificationInfo): Promise<void> {
62
+ if (!this.isRegistered) {
63
+ throw new Error(
64
+ 'RecordingNotification must be registered before showing. Call register() first.'
65
+ );
66
+ }
67
+
68
+ // Recording notifications are only supported on Android
69
+ if (this.isIOS) {
70
+ this.isShown = true;
71
+ return;
72
+ }
73
+
74
+ if (!NativeAudioAPIModule) {
75
+ throw new Error('NativeAudioAPIModule is not available');
76
+ }
77
+
78
+ const result = await NativeAudioAPIModule.showNotification(
79
+ this.notificationKey,
80
+ info as Record<string, string | number | boolean | undefined>
81
+ );
82
+
83
+ if (result.error) {
84
+ throw new Error(result.error);
85
+ }
86
+
87
+ this.isShown = true;
88
+ }
89
+
90
+ /// Update the notification with new metadata or state.
91
+ async update(info: RecordingNotificationInfo): Promise<void> {
92
+ if (!this.isShown) {
93
+ console.warn('RecordingNotification is not shown. Call show() first.');
94
+ return;
95
+ }
96
+
97
+ // Recording notifications are only supported on Android
98
+ if (this.isIOS) {
99
+ return;
100
+ }
101
+
102
+ if (!NativeAudioAPIModule) {
103
+ throw new Error('NativeAudioAPIModule is not available');
104
+ }
105
+
106
+ const result = await NativeAudioAPIModule.updateNotification(
107
+ this.notificationKey,
108
+ info as Record<string, string | number | boolean | undefined>
109
+ );
110
+
111
+ if (result.error) {
112
+ throw new Error(result.error);
113
+ }
114
+ }
115
+
116
+ /// Hide the notification (can be shown again later).
117
+ async hide(): Promise<void> {
118
+ if (!this.isShown) {
119
+ return;
120
+ }
121
+
122
+ // Recording notifications are only supported on Android
123
+ if (this.isIOS) {
124
+ this.isShown = false;
125
+ return;
126
+ }
127
+
128
+ if (!NativeAudioAPIModule) {
129
+ throw new Error('NativeAudioAPIModule is not available');
130
+ }
131
+
132
+ const result = await NativeAudioAPIModule.hideNotification(
133
+ this.notificationKey
134
+ );
135
+
136
+ if (result.error) {
137
+ throw new Error(result.error);
138
+ }
139
+
140
+ this.isShown = false;
141
+ }
142
+
143
+ /// Unregister the notification (must register again to use).
144
+ async unregister(): Promise<void> {
145
+ if (!this.isRegistered) {
146
+ return;
147
+ }
148
+
149
+ if (this.isShown) {
150
+ await this.hide();
151
+ }
152
+
153
+ // Recording notifications are only supported on Android
154
+ if (this.isIOS) {
155
+ this.isRegistered = false;
156
+ return;
157
+ }
158
+
159
+ if (!NativeAudioAPIModule) {
160
+ throw new Error('NativeAudioAPIModule is not available');
161
+ }
162
+
163
+ const result = await NativeAudioAPIModule.unregisterNotification(
164
+ this.notificationKey
165
+ );
166
+
167
+ if (result.error) {
168
+ throw new Error(result.error);
169
+ }
170
+
171
+ this.isRegistered = false;
172
+ }
173
+
174
+ /// Enable or disable a specific recording control.
175
+ async enableControl(
176
+ control: RecordingControlName,
177
+ enabled: boolean
178
+ ): Promise<void> {
179
+ if (!this.isRegistered) {
180
+ console.warn('RecordingNotification is not registered');
181
+ return;
182
+ }
183
+
184
+ // Recording notifications are only supported on Android
185
+ if (this.isIOS) {
186
+ return;
187
+ }
188
+
189
+ if (!NativeAudioAPIModule) {
190
+ throw new Error('NativeAudioAPIModule is not available');
191
+ }
192
+
193
+ const params = { control, enabled };
194
+ const result = await NativeAudioAPIModule.updateNotification(
195
+ this.notificationKey,
196
+ params as Record<string, string | number | boolean | undefined>
197
+ );
198
+
199
+ if (result.error) {
200
+ throw new Error(result.error);
201
+ }
202
+ }
203
+
204
+ /// Check if the notification is currently active.
205
+ async isActive(): Promise<boolean> {
206
+ // Recording notifications are only supported on Android
207
+ if (this.isIOS) {
208
+ return this.isShown;
209
+ }
210
+
211
+ if (!NativeAudioAPIModule) {
212
+ return false;
213
+ }
214
+
215
+ return await NativeAudioAPIModule.isNotificationActive(
216
+ this.notificationKey
217
+ );
218
+ }
219
+
220
+ /// Add an event listener for notification actions.
221
+ addEventListener<T extends RecordingNotificationEventName>(
222
+ eventName: T,
223
+ callback: (event: NotificationEvents[T]) => void
224
+ ): AudioEventSubscription {
225
+ // Recording notifications are only supported on Android
226
+ if (this.isIOS) {
227
+ // Return a dummy subscription for iOS
228
+ return {
229
+ remove: () => {},
230
+ } as unknown as AudioEventSubscription;
231
+ }
232
+
233
+ return this.audioEventEmitter.addAudioEventListener(eventName, callback);
234
+ }
235
+
236
+ /** Remove an event listener. */
237
+ removeEventListener(subscription: AudioEventSubscription): void {
238
+ subscription.remove();
239
+ }
240
+ }
241
+
242
+ export default new RecordingNotificationManager();
@@ -0,0 +1,170 @@
1
+ import { NativeAudioAPIModule } from '../../specs';
2
+ import { AudioEventEmitter, AudioEventSubscription } from '../../events';
3
+ import type { NotificationManager, SimpleNotificationOptions } from './types';
4
+
5
+ /// Simple notification manager for basic notifications with title and text.
6
+ /// Implements the generic NotificationManager interface.
7
+ // It is only a showcase
8
+ class SimpleNotificationManager
9
+ implements
10
+ NotificationManager<
11
+ SimpleNotificationOptions,
12
+ SimpleNotificationOptions,
13
+ never
14
+ >
15
+ {
16
+ private notificationKey = 'simple';
17
+ private isRegistered = false;
18
+ private isShown = false;
19
+ private audioEventEmitter: AudioEventEmitter;
20
+
21
+ constructor() {
22
+ this.audioEventEmitter = new AudioEventEmitter(global.AudioEventEmitter);
23
+ }
24
+
25
+ /// Register the simple notification (must be called before showing).
26
+ async register(): Promise<void> {
27
+ if (this.isRegistered) {
28
+ console.warn('SimpleNotification is already registered');
29
+ return;
30
+ }
31
+
32
+ if (!NativeAudioAPIModule) {
33
+ throw new Error('NativeAudioAPIModule is not available');
34
+ }
35
+
36
+ const result = await NativeAudioAPIModule.registerNotification(
37
+ 'simple',
38
+ this.notificationKey
39
+ );
40
+
41
+ if (result.error) {
42
+ throw new Error(result.error);
43
+ }
44
+
45
+ this.isRegistered = true;
46
+ }
47
+
48
+ /// Show the notification with initial options.
49
+ async show(options: SimpleNotificationOptions): Promise<void> {
50
+ if (!this.isRegistered) {
51
+ throw new Error(
52
+ 'SimpleNotification must be registered before showing. Call register() first.'
53
+ );
54
+ }
55
+
56
+ if (!NativeAudioAPIModule) {
57
+ throw new Error('NativeAudioAPIModule is not available');
58
+ }
59
+
60
+ const result = await NativeAudioAPIModule.showNotification(
61
+ this.notificationKey,
62
+ options as Record<string, string | number | boolean | undefined>
63
+ );
64
+
65
+ if (result.error) {
66
+ throw new Error(result.error);
67
+ }
68
+
69
+ this.isShown = true;
70
+ }
71
+
72
+ /// Update the notification with new options.
73
+ async update(options: SimpleNotificationOptions): Promise<void> {
74
+ if (!this.isShown) {
75
+ console.warn('SimpleNotification is not shown. Call show() first.');
76
+ return;
77
+ }
78
+
79
+ if (!NativeAudioAPIModule) {
80
+ throw new Error('NativeAudioAPIModule is not available');
81
+ }
82
+
83
+ const result = await NativeAudioAPIModule.updateNotification(
84
+ this.notificationKey,
85
+ options as Record<string, string | number | boolean | undefined>
86
+ );
87
+
88
+ if (result.error) {
89
+ throw new Error(result.error);
90
+ }
91
+ }
92
+
93
+ /// Hide the notification (can be shown again later).
94
+ async hide(): Promise<void> {
95
+ if (!this.isShown) {
96
+ return;
97
+ }
98
+
99
+ if (!NativeAudioAPIModule) {
100
+ throw new Error('NativeAudioAPIModule is not available');
101
+ }
102
+
103
+ const result = await NativeAudioAPIModule.hideNotification(
104
+ this.notificationKey
105
+ );
106
+
107
+ if (result.error) {
108
+ throw new Error(result.error);
109
+ }
110
+
111
+ this.isShown = false;
112
+ }
113
+
114
+ /// Unregister the notification (must register again to use).
115
+ async unregister(): Promise<void> {
116
+ if (!this.isRegistered) {
117
+ return;
118
+ }
119
+
120
+ if (this.isShown) {
121
+ await this.hide();
122
+ }
123
+
124
+ if (!NativeAudioAPIModule) {
125
+ throw new Error('NativeAudioAPIModule is not available');
126
+ }
127
+
128
+ const result = await NativeAudioAPIModule.unregisterNotification(
129
+ this.notificationKey
130
+ );
131
+
132
+ if (result.error) {
133
+ throw new Error(result.error);
134
+ }
135
+
136
+ this.isRegistered = false;
137
+ }
138
+
139
+ /// Check if the notification is currently active.
140
+ async isActive(): Promise<boolean> {
141
+ if (!NativeAudioAPIModule) {
142
+ return false;
143
+ }
144
+
145
+ return await NativeAudioAPIModule.isNotificationActive(
146
+ this.notificationKey
147
+ );
148
+ }
149
+
150
+ /// Add an event listener (SimpleNotification doesn't emit events).
151
+ addEventListener<T extends never>(
152
+ _eventName: T,
153
+ _callback: (event: never) => void
154
+ ): AudioEventSubscription {
155
+ // SimpleNotification doesn't emit events, return a no-op subscription
156
+ console.warn('SimpleNotification does not support event listeners');
157
+ return this.audioEventEmitter.addAudioEventListener(
158
+ // Using a valid event name for the no-op subscription
159
+ 'playbackNotificationPlay',
160
+ () => {}
161
+ );
162
+ }
163
+
164
+ /// Remove an event listener.
165
+ removeEventListener(subscription: AudioEventSubscription): void {
166
+ subscription.remove();
167
+ }
168
+ }
169
+
170
+ export default new SimpleNotificationManager();
@@ -0,0 +1,4 @@
1
+ export { default as PlaybackNotificationManager } from './PlaybackNotificationManager';
2
+ export { default as RecordingNotificationManager } from './RecordingNotificationManager';
3
+ export { default as SimpleNotificationManager } from './SimpleNotificationManager';
4
+ export * from './types';
@@ -0,0 +1,111 @@
1
+ import type { AudioEventSubscription } from '../../events';
2
+ import { EventEmptyType, EventTypeWithValue } from '../../events/types';
3
+
4
+ /// Generic notification manager interface that all notification managers should implement.
5
+ /// Provides a consistent API for managing notification lifecycle and events.
6
+ export interface NotificationManager<
7
+ TShowOptions,
8
+ TUpdateOptions,
9
+ TEventName extends NotificationEventName,
10
+ > {
11
+ /// Register the notification (must be called before showing).
12
+ register(): Promise<void>;
13
+
14
+ /// Show the notification with initial options.
15
+ show(options: TShowOptions): Promise<void>;
16
+
17
+ /// Update the notification with new options.
18
+ update(options: TUpdateOptions): Promise<void>;
19
+
20
+ /// Hide the notification (can be shown again later).
21
+ hide(): Promise<void>;
22
+
23
+ /// Unregister the notification (must register again to use).
24
+ unregister(): Promise<void>;
25
+
26
+ /// Check if the notification is currently active.
27
+ isActive(): Promise<boolean>;
28
+
29
+ /// Add an event listener for notification events.
30
+ addEventListener<T extends TEventName>(
31
+ eventName: T,
32
+ callback: NotificationCallback<T>
33
+ ): AudioEventSubscription;
34
+
35
+ /// Remove an event listener.
36
+ removeEventListener(subscription: AudioEventSubscription): void;
37
+ }
38
+
39
+ /// Metadata and state information for playback notifications.
40
+ export interface PlaybackNotificationInfo {
41
+ title?: string;
42
+ artist?: string;
43
+ album?: string;
44
+ artwork?: string | { uri: string };
45
+ androidSmallIcon?: string | { uri: string };
46
+ duration?: number;
47
+ elapsedTime?: number;
48
+ speed?: number;
49
+ state?: 'playing' | 'paused';
50
+ }
51
+
52
+ /// Available playback control actions.
53
+ export type PlaybackControlName =
54
+ | 'play'
55
+ | 'pause'
56
+ | 'next'
57
+ | 'previous'
58
+ | 'skipForward'
59
+ | 'skipBackward'
60
+ | 'seekTo';
61
+
62
+ /// Event names for playback notification actions.
63
+ interface PlaybackNotificationEvent {
64
+ playbackNotificationPlay: EventEmptyType;
65
+ playbackNotificationPause: EventEmptyType;
66
+ playbackNotificationNext: EventEmptyType;
67
+ playbackNotificationPrevious: EventEmptyType;
68
+ playbackNotificationSkipForward: EventTypeWithValue;
69
+ playbackNotificationSkipBackward: EventTypeWithValue;
70
+ playbackNotificationSeekTo: EventTypeWithValue;
71
+ playbackNotificationDismissed: EventEmptyType;
72
+ }
73
+
74
+ export type PlaybackNotificationEventName = keyof PlaybackNotificationEvent;
75
+
76
+ /// Metadata and state information for recording notifications.
77
+ export interface RecordingNotificationInfo {
78
+ title?: string;
79
+ description?: string;
80
+ artwork?: string | { uri: string };
81
+ state?: 'recording' | 'stopped';
82
+ control?: RecordingControlName;
83
+ enabled?: boolean;
84
+ }
85
+
86
+ /// Available recording control actions.
87
+ export type RecordingControlName = 'start' | 'stop';
88
+
89
+ /// Event names for recording notification actions.
90
+ interface RecordingNotificationEvent {
91
+ recordingNotificationStart: EventEmptyType;
92
+ recordingNotificationStop: EventEmptyType;
93
+ recordingNotificationDismissed: EventEmptyType;
94
+ }
95
+
96
+ export type RecordingNotificationEventName = keyof RecordingNotificationEvent;
97
+
98
+ export type NotificationEvents = PlaybackNotificationEvent &
99
+ RecordingNotificationEvent;
100
+
101
+ export type NotificationEventName = keyof NotificationEvents;
102
+
103
+ export type NotificationCallback<Name extends NotificationEventName> = (
104
+ event: NotificationEvents[Name]
105
+ ) => void;
106
+
107
+ /// Options for a simple notification with title and text.
108
+ export interface SimpleNotificationOptions {
109
+ title?: string;
110
+ text?: string;
111
+ }
@@ -34,24 +34,6 @@ export interface SessionOptions {
34
34
  iosAllowHaptics?: boolean;
35
35
  }
36
36
 
37
- export type MediaState = 'state_playing' | 'state_paused';
38
-
39
- interface BaseLockScreenInfo {
40
- [key: string]: string | boolean | number | undefined;
41
- }
42
-
43
- export interface LockScreenInfo extends BaseLockScreenInfo {
44
- title?: string;
45
- artwork?: string;
46
- artist?: string;
47
- album?: string;
48
- duration?: number;
49
- description?: string; // android only
50
- state?: MediaState;
51
- speed?: number;
52
- elapsedTime?: number;
53
- }
54
-
55
37
  export type PermissionStatus = 'Undetermined' | 'Denied' | 'Granted';
56
38
 
57
39
  export interface AudioDeviceInfo {
package/src/types.ts CHANGED
@@ -44,23 +44,29 @@ export interface OfflineAudioContextOptions {
44
44
  }
45
45
 
46
46
  export enum FileDirectory {
47
- Document = 1,
48
- Cache = 2,
47
+ Document = 0,
48
+ Cache = 1,
49
49
  }
50
50
 
51
51
  export enum FileFormat {
52
- Wav = 1,
53
- Caf = 2,
54
- M4A = 3,
55
- Flac = 4,
52
+ Wav = 0,
53
+ Caf = 1,
54
+ M4A = 2,
55
+ Flac = 3,
56
56
  }
57
57
 
58
58
  export enum IOSAudioQuality {
59
- Min = 1,
60
- Low = 2,
61
- Medium = 3,
62
- High = 4,
63
- Max = 5,
59
+ Min = 0,
60
+ Low = 1,
61
+ Medium = 2,
62
+ High = 3,
63
+ Max = 4,
64
+ }
65
+
66
+ export enum BitDepth {
67
+ Bit16 = 0,
68
+ Bit24 = 1,
69
+ Bit32 = 2,
64
70
  }
65
71
 
66
72
  export enum FlacCompressionLevel {
@@ -75,12 +81,6 @@ export enum FlacCompressionLevel {
75
81
  L8 = 8,
76
82
  }
77
83
 
78
- export enum BitDepth {
79
- Bit16 = 1,
80
- Bit24 = 2,
81
- Bit32 = 3,
82
- }
83
-
84
84
  export interface FilePresetType {
85
85
  bitRate: number;
86
86
  sampleRate: number;
@@ -0,0 +1 @@
1
+ export * from './notification';
@@ -0,0 +1,60 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /* eslint-disable no-useless-constructor */
3
+ /* eslint-disable @typescript-eslint/require-await */
4
+
5
+ import type { AudioEventSubscription } from '../../events';
6
+ import type {
7
+ NotificationManager,
8
+ PlaybackNotificationInfo,
9
+ PlaybackControlName,
10
+ PlaybackNotificationEventName,
11
+ NotificationEvents,
12
+ } from '../../system';
13
+
14
+ /// Mock Manager for playback notifications. Does nothing.
15
+ class PlaybackNotificationManager
16
+ implements
17
+ NotificationManager<
18
+ PlaybackNotificationInfo,
19
+ PlaybackNotificationInfo,
20
+ PlaybackNotificationEventName
21
+ >
22
+ {
23
+ private isRegistered = false;
24
+ private isShown = false;
25
+
26
+ constructor() {}
27
+
28
+ async register(): Promise<void> {}
29
+
30
+ async show(info: PlaybackNotificationInfo): Promise<void> {}
31
+
32
+ async update(info: PlaybackNotificationInfo): Promise<void> {}
33
+
34
+ async hide(): Promise<void> {}
35
+
36
+ async unregister(): Promise<void> {}
37
+
38
+ async enableControl(
39
+ control: PlaybackControlName,
40
+ enabled: boolean
41
+ ): Promise<void> {}
42
+
43
+ async isActive(): Promise<boolean> {
44
+ return this.isShown;
45
+ }
46
+
47
+ addEventListener<T extends PlaybackNotificationEventName>(
48
+ eventName: T,
49
+ callback: (event: NotificationEvents[T]) => void
50
+ ): AudioEventSubscription {
51
+ // dummy subscription object with a no-op remove method
52
+ return {
53
+ remove: () => {},
54
+ } as unknown as AudioEventSubscription;
55
+ }
56
+
57
+ removeEventListener(subscription: AudioEventSubscription): void {}
58
+ }
59
+
60
+ export default new PlaybackNotificationManager();