Skip to content

Commit f2f7cf2

Browse files
authored
Merge pull request #478 from software-mansion/fix-with-audio-api-plugin
Fix with audio api plugin
2 parents da65760 + 826380b commit f2f7cf2

File tree

5 files changed

+55
-42
lines changed

5 files changed

+55
-42
lines changed

packages/react-native-audio-api/common/cpp/audioapi/core/AudioParam.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ AudioParam::AudioParam(
1717
minValue_(minValue),
1818
maxValue_(maxValue),
1919
context_(context),
20-
audioBus_(
21-
std::make_shared<AudioBus>(
22-
RENDER_QUANTUM_SIZE,
23-
1,
24-
context->getSampleRate())) {
20+
audioBus_(std::make_shared<AudioBus>(
21+
RENDER_QUANTUM_SIZE,
22+
1,
23+
context->getSampleRate())) {
2524
startTime_ = 0;
2625
endTime_ = 0;
2726
startValue_ = value_;

packages/react-native-audio-api/ios/audioapi/ios/AudioAPIModule.mm

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ - (void)invalidate
8585
return [self.audioSessionManager getDevicePreferredSampleRate];
8686
}
8787

88-
RCT_EXPORT_METHOD(
89-
setAudioSessionActivity : (BOOL)enabled resolve : (RCTPromiseResolveBlock)resolve reject : (RCTPromiseRejectBlock)
90-
reject)
88+
RCT_EXPORT_METHOD(setAudioSessionActivity : (BOOL)enabled resolve : (RCTPromiseResolveBlock)
89+
resolve reject : (RCTPromiseRejectBlock)reject)
9190
{
9291
if ([self.audioSessionManager setActive:enabled]) {
9392
resolve(@"true");
@@ -127,16 +126,15 @@ - (void)invalidate
127126
[self.notificationManager observeVolumeChanges:(BOOL)enabled];
128127
}
129128

130-
RCT_EXPORT_METHOD(
131-
requestRecordingPermissions : (nonnull RCTPromiseResolveBlock)resolve reject : (nonnull RCTPromiseRejectBlock)
132-
reject)
129+
RCT_EXPORT_METHOD(requestRecordingPermissions : (nonnull RCTPromiseResolveBlock)
130+
resolve reject : (nonnull RCTPromiseRejectBlock)reject)
133131
{
134132
NSString *res = [self.audioSessionManager requestRecordingPermissions];
135133
resolve(res);
136134
}
137135

138-
RCT_EXPORT_METHOD(
139-
checkRecordingPermissions : (nonnull RCTPromiseResolveBlock)resolve reject : (nonnull RCTPromiseRejectBlock)reject)
136+
RCT_EXPORT_METHOD(checkRecordingPermissions : (nonnull RCTPromiseResolveBlock)
137+
resolve reject : (nonnull RCTPromiseRejectBlock)reject)
140138
{
141139
NSString *res = [self.audioSessionManager checkRecordingPermissions];
142140
resolve(res);

packages/react-native-audio-api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"@commitlint/config-conventional": "^17.0.2",
9191
"@evilmartians/lefthook": "^1.5.0",
9292
"@expo/config-plugins": "^9.0.0",
93+
"@expo/config-types": "^53.0.4",
9394
"@react-native/babel-preset": "0.77.1",
9495
"@react-native/eslint-config": "^0.77.1",
9596
"@react-native/metro-config": "0.77.1",

packages/react-native-audio-api/src/plugin/withAudioAPI.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,28 @@ import {
55
withInfoPlist,
66
withAndroidManifest,
77
} from '@expo/config-plugins';
8-
98
const pkg = require('react-native-audio-api/package.json');
109

10+
interface Options {
11+
iosBackgroundMode: boolean;
12+
androidForegroundService: boolean;
13+
androidFSPermissions: string[];
14+
androidFSTypes: string[];
15+
}
16+
17+
const withDefaultOptions = (options: Partial<Options>): Options => {
18+
return {
19+
iosBackgroundMode: true,
20+
androidForegroundService: true,
21+
androidFSPermissions: [
22+
'android.permission.FOREGROUND_SERVICE',
23+
'android.permission.WAKE_LOCK',
24+
],
25+
androidFSTypes: ['mediaPlayback'],
26+
...options,
27+
};
28+
};
29+
1130
const withBackgroundAudio: ConfigPlugin = (config) => {
1231
return withInfoPlist(config, (iosConfig) => {
1332
iosConfig.modResults.UIBackgroundModes = [
@@ -20,18 +39,20 @@ const withBackgroundAudio: ConfigPlugin = (config) => {
2039
});
2140
};
2241

23-
const withAndroidPermissions: ConfigPlugin<{
24-
androidFSPermissions: string[];
25-
}> = (config, { androidFSPermissions }) => {
42+
const withAndroidPermissions: ConfigPlugin<Options> = (
43+
config,
44+
{ androidFSPermissions }: Options
45+
) => {
2646
return AndroidConfig.Permissions.withPermissions(
2747
config,
2848
androidFSPermissions
2949
);
3050
};
3151

32-
const withForegroundService: ConfigPlugin<{
33-
androidFSTypes: string[];
34-
}> = (config, { androidFSTypes }) => {
52+
const withForegroundService: ConfigPlugin<Options> = (
53+
config,
54+
{ androidFSTypes }: Options
55+
) => {
3556
return withAndroidManifest(config, (mod) => {
3657
const manifest = mod.modResults;
3758
const mainApplication =
@@ -59,30 +80,16 @@ const withForegroundService: ConfigPlugin<{
5980
});
6081
};
6182

62-
const withAudioAPI: ConfigPlugin<{
63-
iosBackgroundMode?: boolean;
64-
androidForegroundService?: boolean;
65-
androidFSPermissions?: string[];
66-
androidFSTypes?: string[];
67-
}> = (
68-
config,
69-
{
70-
iosBackgroundMode = true,
71-
androidForegroundService = true,
72-
androidFSPermissions = [],
73-
androidFSTypes = [],
74-
} = {}
75-
) => {
76-
if (iosBackgroundMode) {
83+
const withAudioAPI: ConfigPlugin<Options> = (config, optionsIn) => {
84+
const options = withDefaultOptions(optionsIn ?? {});
85+
86+
if (options.iosBackgroundMode) {
7787
config = withBackgroundAudio(config);
7888
}
79-
if (androidForegroundService) {
80-
config = withAndroidPermissions(config, {
81-
androidFSPermissions,
82-
});
83-
config = withForegroundService(config, {
84-
androidFSTypes,
85-
});
89+
90+
if (options.androidForegroundService) {
91+
config = withAndroidPermissions(config, options);
92+
config = withForegroundService(config, options);
8693
}
8794

8895
return config;

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,13 @@ __metadata:
19931993
languageName: node
19941994
linkType: hard
19951995

1996+
"@expo/config-types@npm:^53.0.4":
1997+
version: 53.0.4
1998+
resolution: "@expo/config-types@npm:53.0.4"
1999+
checksum: 10/536395517b132db489e3a046061f70065f4139bfff39116d129861c69b0d789e8089cca9f4a48b9ffc44991b9f12ae1cd03cc0707a9c4c0e3319c8a4c2b9fc8b
2000+
languageName: node
2001+
linkType: hard
2002+
19962003
"@expo/json-file@npm:~9.1.1":
19972004
version: 9.1.1
19982005
resolution: "@expo/json-file@npm:9.1.1"
@@ -10779,6 +10786,7 @@ __metadata:
1077910786
"@commitlint/config-conventional": "npm:^17.0.2"
1078010787
"@evilmartians/lefthook": "npm:^1.5.0"
1078110788
"@expo/config-plugins": "npm:^9.0.0"
10789+
"@expo/config-types": "npm:^53.0.4"
1078210790
"@react-native/babel-preset": "npm:0.77.1"
1078310791
"@react-native/eslint-config": "npm:^0.77.1"
1078410792
"@react-native/metro-config": "npm:0.77.1"

0 commit comments

Comments
 (0)