react-native-audio-api 0.11.0-alpha.3 → 0.11.0-alpha.5
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/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +34 -6
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +4 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/ptrs.hpp +8 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/utils.cpp +4 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +1 -0
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +164 -16
- package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioPlayer.kt +10 -8
- package/android/src/main/java/com/swmansion/audioapi/core/NativeAudioRecorder.kt +10 -8
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +3 -4
- package/android/src/main/java/com/swmansion/audioapi/system/CentralizedForegroundService.kt +128 -0
- package/android/src/main/java/com/swmansion/audioapi/system/ForegroundServiceManager.kt +116 -0
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionManager.kt +115 -107
- package/android/src/main/java/com/swmansion/audioapi/system/PermissionRequestListener.kt +2 -1
- package/android/src/main/java/com/swmansion/audioapi/system/notification/BaseNotification.kt +47 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/NotificationRegistry.kt +191 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotification.kt +669 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotificationReceiver.kt +33 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotification.kt +303 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotificationReceiver.kt +45 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/SimpleNotification.kt +119 -0
- package/common/cpp/audioapi/core/utils/AudioFileWriter.h +1 -0
- package/common/cpp/audioapi/core/utils/AudioRecorderCallback.h +1 -0
- package/common/cpp/audioapi/utils/AudioFileProperties.h +17 -17
- package/ios/audioapi/ios/AudioAPIModule.h +2 -2
- package/ios/audioapi/ios/AudioAPIModule.mm +108 -18
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +8 -7
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +1 -1
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +9 -2
- package/ios/audioapi/ios/system/AudioEngine.h +2 -0
- package/ios/audioapi/ios/system/AudioEngine.mm +49 -6
- package/ios/audioapi/ios/system/AudioSessionManager.mm +12 -9
- package/ios/audioapi/ios/system/NotificationManager.mm +7 -4
- package/ios/audioapi/ios/system/notification/BaseNotification.h +58 -0
- package/ios/audioapi/ios/system/notification/NotificationRegistry.h +70 -0
- package/ios/audioapi/ios/system/notification/NotificationRegistry.mm +172 -0
- package/ios/audioapi/ios/system/notification/PlaybackNotification.h +27 -0
- package/ios/audioapi/ios/system/notification/PlaybackNotification.mm +427 -0
- package/lib/commonjs/api.js +72 -1
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/api.web.js +27 -14
- package/lib/commonjs/api.web.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/system/AudioManager.js +6 -9
- package/lib/commonjs/system/AudioManager.js.map +1 -1
- package/lib/commonjs/system/index.js +13 -0
- package/lib/commonjs/system/index.js.map +1 -1
- package/lib/commonjs/system/notification/PlaybackNotificationManager.js +135 -0
- package/lib/commonjs/system/notification/PlaybackNotificationManager.js.map +1 -0
- package/lib/commonjs/system/notification/RecordingNotificationManager.js +182 -0
- package/lib/commonjs/system/notification/RecordingNotificationManager.js.map +1 -0
- package/lib/commonjs/system/notification/SimpleNotificationManager.js +122 -0
- package/lib/commonjs/system/notification/SimpleNotificationManager.js.map +1 -0
- package/lib/commonjs/system/notification/index.js +45 -0
- package/lib/commonjs/system/notification/index.js.map +1 -0
- package/lib/commonjs/system/notification/types.js +6 -0
- package/lib/commonjs/system/notification/types.js.map +1 -0
- package/lib/commonjs/types.js +17 -17
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/web-system/index.js +17 -0
- package/lib/commonjs/web-system/index.js.map +1 -0
- package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js +34 -0
- package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js.map +1 -0
- package/lib/commonjs/web-system/notification/RecordingNotificationManager.js +34 -0
- package/lib/commonjs/web-system/notification/RecordingNotificationManager.js.map +1 -0
- package/lib/commonjs/web-system/notification/index.js +21 -0
- package/lib/commonjs/web-system/notification/index.js.map +1 -0
- package/lib/module/api.js +4 -0
- package/lib/module/api.js.map +1 -1
- package/lib/module/api.web.js +3 -1
- package/lib/module/api.web.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/system/AudioManager.js +6 -9
- package/lib/module/system/AudioManager.js.map +1 -1
- package/lib/module/system/index.js +1 -0
- package/lib/module/system/index.js.map +1 -1
- package/lib/module/system/notification/PlaybackNotificationManager.js +131 -0
- package/lib/module/system/notification/PlaybackNotificationManager.js.map +1 -0
- package/lib/module/system/notification/RecordingNotificationManager.js +178 -0
- package/lib/module/system/notification/RecordingNotificationManager.js.map +1 -0
- package/lib/module/system/notification/SimpleNotificationManager.js +118 -0
- package/lib/module/system/notification/SimpleNotificationManager.js.map +1 -0
- package/lib/module/system/notification/index.js +7 -0
- package/lib/module/system/notification/index.js.map +1 -0
- package/lib/module/system/notification/types.js +4 -0
- package/lib/module/system/notification/types.js.map +1 -0
- package/lib/module/types.js +17 -17
- package/lib/module/types.js.map +1 -1
- package/lib/module/web-system/index.js +4 -0
- package/lib/module/web-system/index.js.map +1 -0
- package/lib/module/web-system/notification/PlaybackNotificationManager.js +30 -0
- package/lib/module/web-system/notification/PlaybackNotificationManager.js.map +1 -0
- package/lib/module/web-system/notification/RecordingNotificationManager.js +30 -0
- package/lib/module/web-system/notification/RecordingNotificationManager.js.map +1 -0
- package/lib/module/web-system/notification/index.js +5 -0
- package/lib/module/web-system/notification/index.js.map +1 -0
- package/lib/typescript/api.d.ts +2 -0
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/api.web.d.ts +3 -1
- package/lib/typescript/api.web.d.ts.map +1 -1
- package/lib/typescript/events/types.d.ts +3 -3
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +16 -5
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/system/AudioManager.d.ts +4 -5
- package/lib/typescript/system/AudioManager.d.ts.map +1 -1
- package/lib/typescript/system/index.d.ts +1 -0
- package/lib/typescript/system/index.d.ts.map +1 -1
- package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts +22 -0
- package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts.map +1 -0
- package/lib/typescript/system/notification/RecordingNotificationManager.d.ts +23 -0
- package/lib/typescript/system/notification/RecordingNotificationManager.d.ts.map +1 -0
- package/lib/typescript/system/notification/SimpleNotificationManager.d.ts +20 -0
- package/lib/typescript/system/notification/SimpleNotificationManager.d.ts.map +1 -0
- package/lib/typescript/system/notification/index.d.ts +5 -0
- package/lib/typescript/system/notification/index.d.ts.map +1 -0
- package/lib/typescript/system/notification/types.d.ts +65 -0
- package/lib/typescript/system/notification/types.d.ts.map +1 -0
- package/lib/typescript/system/types.d.ts +0 -16
- package/lib/typescript/system/types.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +16 -16
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/web-system/index.d.ts +2 -0
- package/lib/typescript/web-system/index.d.ts.map +1 -0
- package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts +19 -0
- package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts.map +1 -0
- package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts +19 -0
- package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts.map +1 -0
- package/lib/typescript/web-system/notification/index.d.ts +3 -0
- package/lib/typescript/web-system/notification/index.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/api.ts +17 -0
- package/src/api.web.ts +7 -2
- package/src/events/types.ts +3 -4
- package/src/specs/NativeAudioAPIModule.ts +23 -7
- package/src/system/AudioManager.ts +10 -23
- package/src/system/index.ts +1 -0
- package/src/system/notification/PlaybackNotificationManager.ts +193 -0
- package/src/system/notification/RecordingNotificationManager.ts +242 -0
- package/src/system/notification/SimpleNotificationManager.ts +170 -0
- package/src/system/notification/index.ts +4 -0
- package/src/system/notification/types.ts +111 -0
- package/src/system/types.ts +0 -18
- package/src/types.ts +17 -17
- package/src/web-system/index.ts +1 -0
- package/src/web-system/notification/PlaybackNotificationManager.ts +60 -0
- package/src/web-system/notification/RecordingNotificationManager.ts +60 -0
- package/src/web-system/notification/index.ts +2 -0
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +0 -347
- package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +0 -273
- package/android/src/main/java/com/swmansion/audioapi/system/MediaReceiver.kt +0 -57
- package/android/src/main/java/com/swmansion/audioapi/system/MediaSessionCallback.kt +0 -61
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { NativeAudioAPIModule } from '../../specs';
|
|
2
|
+
import { AudioEventEmitter, AudioEventSubscription } from '../../events';
|
|
3
|
+
import type {
|
|
4
|
+
NotificationManager,
|
|
5
|
+
PlaybackNotificationInfo,
|
|
6
|
+
PlaybackControlName,
|
|
7
|
+
PlaybackNotificationEventName,
|
|
8
|
+
NotificationEvents,
|
|
9
|
+
} from './types';
|
|
10
|
+
|
|
11
|
+
/// Manager for media playback notifications with controls and MediaSession integration.
|
|
12
|
+
class PlaybackNotificationManager
|
|
13
|
+
implements
|
|
14
|
+
NotificationManager<
|
|
15
|
+
PlaybackNotificationInfo,
|
|
16
|
+
PlaybackNotificationInfo,
|
|
17
|
+
PlaybackNotificationEventName
|
|
18
|
+
>
|
|
19
|
+
{
|
|
20
|
+
private notificationKey = 'playback';
|
|
21
|
+
private isRegistered = false;
|
|
22
|
+
private isShown = false;
|
|
23
|
+
private audioEventEmitter: AudioEventEmitter;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
this.audioEventEmitter = new AudioEventEmitter(global.AudioEventEmitter);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Register the playback notification (must be called before showing).
|
|
30
|
+
async register(): Promise<void> {
|
|
31
|
+
if (this.isRegistered) {
|
|
32
|
+
console.warn('PlaybackNotification is already registered');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!NativeAudioAPIModule) {
|
|
37
|
+
throw new Error('NativeAudioAPIModule is not available');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const result = await NativeAudioAPIModule.registerNotification(
|
|
41
|
+
'playback',
|
|
42
|
+
this.notificationKey
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
if (result.error) {
|
|
46
|
+
throw new Error(result.error);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.isRegistered = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Show the notification with initial metadata.
|
|
53
|
+
async show(info: PlaybackNotificationInfo): Promise<void> {
|
|
54
|
+
if (!this.isRegistered) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'PlaybackNotification must be registered before showing. Call register() first.'
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!NativeAudioAPIModule) {
|
|
61
|
+
throw new Error('NativeAudioAPIModule is not available');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const result = await NativeAudioAPIModule.showNotification(
|
|
65
|
+
this.notificationKey,
|
|
66
|
+
info as Record<string, string | number | boolean | undefined>
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (result.error) {
|
|
70
|
+
throw new Error(result.error);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.isShown = true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// Update the notification with new metadata or state.
|
|
77
|
+
async update(info: PlaybackNotificationInfo): Promise<void> {
|
|
78
|
+
if (!this.isShown) {
|
|
79
|
+
console.warn('PlaybackNotification is not shown. Call show() first.');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!NativeAudioAPIModule) {
|
|
84
|
+
throw new Error('NativeAudioAPIModule is not available');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const result = await NativeAudioAPIModule.updateNotification(
|
|
88
|
+
this.notificationKey,
|
|
89
|
+
info as Record<string, string | number | boolean | undefined>
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (result.error) {
|
|
93
|
+
throw new Error(result.error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// Hide the notification (can be shown again later).
|
|
98
|
+
async hide(): Promise<void> {
|
|
99
|
+
if (!this.isShown) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (!NativeAudioAPIModule) {
|
|
104
|
+
throw new Error('NativeAudioAPIModule is not available');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const result = await NativeAudioAPIModule.hideNotification(
|
|
108
|
+
this.notificationKey
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (result.error) {
|
|
112
|
+
throw new Error(result.error);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.isShown = false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// Unregister the notification (must register again to use).
|
|
119
|
+
async unregister(): Promise<void> {
|
|
120
|
+
if (!this.isRegistered) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (this.isShown) {
|
|
125
|
+
await this.hide();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!NativeAudioAPIModule) {
|
|
129
|
+
throw new Error('NativeAudioAPIModule is not available');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const result = await NativeAudioAPIModule.unregisterNotification(
|
|
133
|
+
this.notificationKey
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (result.error) {
|
|
137
|
+
throw new Error(result.error);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.isRegistered = false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/// Enable or disable a specific playback control.
|
|
144
|
+
async enableControl(
|
|
145
|
+
control: PlaybackControlName,
|
|
146
|
+
enabled: boolean
|
|
147
|
+
): Promise<void> {
|
|
148
|
+
if (!this.isRegistered) {
|
|
149
|
+
console.warn('PlaybackNotification is not registered');
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!NativeAudioAPIModule) {
|
|
154
|
+
throw new Error('NativeAudioAPIModule is not available');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const params = { control, enabled };
|
|
158
|
+
const result = await NativeAudioAPIModule.updateNotification(
|
|
159
|
+
this.notificationKey,
|
|
160
|
+
params as Record<string, string | number | boolean | undefined>
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
if (result.error) {
|
|
164
|
+
throw new Error(result.error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// Check if the notification is currently active.
|
|
169
|
+
async isActive(): Promise<boolean> {
|
|
170
|
+
if (!NativeAudioAPIModule) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return await NativeAudioAPIModule.isNotificationActive(
|
|
175
|
+
this.notificationKey
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// Add an event listener for notification actions.
|
|
180
|
+
addEventListener<T extends PlaybackNotificationEventName>(
|
|
181
|
+
eventName: T,
|
|
182
|
+
callback: (event: NotificationEvents[T]) => void
|
|
183
|
+
): AudioEventSubscription {
|
|
184
|
+
return this.audioEventEmitter.addAudioEventListener(eventName, callback);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Remove an event listener. */
|
|
188
|
+
removeEventListener(subscription: AudioEventSubscription): void {
|
|
189
|
+
subscription.remove();
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export default new PlaybackNotificationManager();
|
|
@@ -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';
|