@livekit/react-native 2.3.1 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -18
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/java/com/livekit/reactnative/LiveKitReactNative.kt +5 -1
- package/ios/LivekitReactNative.m +50 -35
- package/lib/commonjs/audio/AudioSession.js +6 -0
- package/lib/commonjs/audio/AudioSession.js.map +1 -1
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/audio/AudioSession.js +6 -0
- package/lib/module/audio/AudioSession.js.map +1 -1
- package/lib/module/index.js +20 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/audio/AudioSession.d.ts +6 -0
- package/package.json +4 -4
- package/src/audio/AudioSession.ts +6 -0
- package/src/index.tsx +23 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# livekit-react-native
|
|
12
12
|
|
|
13
13
|
<!--BEGIN_DESCRIPTION-->
|
|
14
|
-
Use this SDK to add
|
|
14
|
+
Use this SDK to add realtime video, audio and data features to your React Native app. By connecting to <a href="https://livekit.io/">LiveKit</a> Cloud or a self-hosted server, you can quickly build applications such as multi-modal AI, live streaming, or video calls with just a few lines of code.
|
|
15
15
|
<!--END_DESCRIPTION-->
|
|
16
16
|
|
|
17
17
|
> [!NOTE]
|
|
@@ -295,24 +295,13 @@ Enabling screenshare requires extra installation steps:
|
|
|
295
295
|
|
|
296
296
|
Android screenshare requires a foreground service with type `mediaProjection` to be present.
|
|
297
297
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
Add the following permissions to your `AndroidManifest.xml` file:
|
|
298
|
+
From version 2.4.0 onwards, the foreground service is handled internally,
|
|
299
|
+
but you must declare the permission yourself in your app's AndroidManifest.xml file.
|
|
301
300
|
|
|
302
|
-
```xml
|
|
303
|
-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
304
|
-
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
|
|
305
301
|
```
|
|
306
|
-
|
|
307
|
-
Declare the the service and ensure it's labelled a `mediaProjection` service like so:
|
|
308
|
-
|
|
309
|
-
```xml
|
|
310
|
-
<service android:name="com.supersami.foregroundservice.ForegroundService" android:foregroundServiceType="mediaProjection" />
|
|
311
|
-
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask" />
|
|
302
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PROJECTION" />
|
|
312
303
|
```
|
|
313
304
|
|
|
314
|
-
Once setup, start the foreground service prior to using screenshare.
|
|
315
|
-
|
|
316
305
|
### iOS
|
|
317
306
|
|
|
318
307
|
iOS screenshare requires adding a Broadcast Extension to your iOS project. Follow the integration instructions here:
|
|
@@ -356,6 +345,54 @@ return (
|
|
|
356
345
|
|
|
357
346
|
You will not be able to publish camera or microphone tracks on iOS Simulator.
|
|
358
347
|
|
|
348
|
+
## Background Processing
|
|
349
|
+
|
|
350
|
+
### Android
|
|
351
|
+
|
|
352
|
+
To support staying connected to LiveKit in the background, you will need a foreground service on Android.
|
|
353
|
+
|
|
354
|
+
The example app uses [@supersami/rn-foreground-service](https://github.com/Raja0sama/rn-foreground-service) for this.
|
|
355
|
+
|
|
356
|
+
Add the following permissions to your `AndroidManifest.xml` file:
|
|
357
|
+
|
|
358
|
+
```xml
|
|
359
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
360
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
|
|
361
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
|
|
362
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
Declare the the service and ensure it's labelled a `mediaProjection` service like so:
|
|
366
|
+
|
|
367
|
+
```xml
|
|
368
|
+
<service android:name="com.supersami.foregroundservice.ForegroundService" android:foregroundServiceType="camera|microphone|mediaPlayback" />
|
|
369
|
+
<service android:name="com.supersami.foregroundservice.ForegroundServiceTask" />
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
The camera and microphone permissions/foreground service types can be omitted if you are not using those.
|
|
373
|
+
|
|
374
|
+
Once setup, [start the foreground service](https://github.com/livekit/client-sdk-react-native/blob/main/example/src/callservice/CallService.android.ts) to keep the app alive in the background.
|
|
375
|
+
|
|
376
|
+
### iOS
|
|
377
|
+
|
|
378
|
+
By default, simple background processing can be enabled by selecting the `audio` and `voip`
|
|
379
|
+
[UIBackgroundModes](https://developer.apple.com/documentation/bundleresources/information_property_list/uibackgroundmodes)
|
|
380
|
+
in your XCode project. In your project, select your app target -> Signing & Capabilities -> Add Capability -> Background Modes.
|
|
381
|
+
|
|
382
|
+
These background modes will keep the app alive in the background as long as a mic or audio track is playing.
|
|
383
|
+
|
|
384
|
+
For a more robust background that isn't sensitive to the above conditions, we suggest using
|
|
385
|
+
[CallKit](https://developer.apple.com/documentation/callkit/) to maintain the
|
|
386
|
+
connection while in the background. The example uses
|
|
387
|
+
[react-native-callkeep](https://github.com/react-native-webrtc/react-native-callkeep)
|
|
388
|
+
for simple integration with CallKit.
|
|
389
|
+
|
|
390
|
+
Our example code can be found [here](https://github.com/livekit/client-sdk-react-native/blob/main/example/src/callservice/CallService.ios.ts).
|
|
391
|
+
|
|
392
|
+
For apps planning to use CallKit to handle incoming calls in the background, [it is important to call
|
|
393
|
+
`RTCAudioSession.audioSessionDidActivate/Deactivate` when the call provider activates/deactivates
|
|
394
|
+
the audio session.](https://github.com/livekit/react-native-webrtc/blob/master/Documentation/iOSInstallation.md#callkit)
|
|
395
|
+
|
|
359
396
|
## Troubleshooting
|
|
360
397
|
|
|
361
398
|
#### Cannot read properties of undefined (reading 'split')
|
|
@@ -379,11 +416,11 @@ Apache License 2.0
|
|
|
379
416
|
<br/><table>
|
|
380
417
|
<thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
|
|
381
418
|
<tbody>
|
|
382
|
-
<tr><td>
|
|
419
|
+
<tr><td>Realtime SDKs</td><td><a href="https://github.com/livekit/components-js">React Components</a> · <a href="https://github.com/livekit/client-sdk-js">Browser</a> · <a href="https://github.com/livekit/components-swift">Swift Components</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS/visionOS</a> · <a href="https://github.com/livekit/client-sdk-android">Android</a> · <a href="https://github.com/livekit/client-sdk-flutter">Flutter</a> · <b>React Native</b> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/client-sdk-unity-web">Unity (web)</a> · <a href="https://github.com/livekit/client-sdk-unity">Unity (beta)</a></td></tr><tr></tr>
|
|
383
420
|
<tr><td>Server APIs</td><td><a href="https://github.com/livekit/node-sdks">Node.js</a> · <a href="https://github.com/livekit/server-sdk-go">Golang</a> · <a href="https://github.com/livekit/server-sdk-ruby">Ruby</a> · <a href="https://github.com/livekit/server-sdk-kotlin">Java/Kotlin</a> · <a href="https://github.com/livekit/python-sdks">Python</a> · <a href="https://github.com/livekit/rust-sdks">Rust</a> · <a href="https://github.com/agence104/livekit-server-sdk-php">PHP (community)</a></td></tr><tr></tr>
|
|
384
421
|
<tr><td>Agents Frameworks</td><td><a href="https://github.com/livekit/agents">Python</a> · <a href="https://github.com/livekit/agent-playground">Playground</a></td></tr><tr></tr>
|
|
385
|
-
<tr><td>Services</td><td><a href="https://github.com/livekit/livekit">
|
|
386
|
-
<tr><td>Resources</td><td><a href="https://docs.livekit.io">Docs</a> · <a href="https://github.com/livekit-examples">Example apps</a> · <a href="https://livekit.io/cloud">Cloud</a> · <a href="https://docs.livekit.io/
|
|
422
|
+
<tr><td>Services</td><td><a href="https://github.com/livekit/livekit">LiveKit server</a> · <a href="https://github.com/livekit/egress">Egress</a> · <a href="https://github.com/livekit/ingress">Ingress</a> · <a href="https://github.com/livekit/sip">SIP</a></td></tr><tr></tr>
|
|
423
|
+
<tr><td>Resources</td><td><a href="https://docs.livekit.io">Docs</a> · <a href="https://github.com/livekit-examples">Example apps</a> · <a href="https://livekit.io/cloud">Cloud</a> · <a href="https://docs.livekit.io/home/self-hosting/deployment">Self-hosting</a> · <a href="https://github.com/livekit/livekit-cli">CLI</a></td></tr>
|
|
387
424
|
</tbody>
|
|
388
425
|
</table>
|
|
389
426
|
<!--END_REPO_NAV-->
|
|
@@ -10,4 +10,5 @@
|
|
|
10
10
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
11
11
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
|
12
12
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
|
13
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
13
14
|
</manifest>
|
|
@@ -30,10 +30,14 @@ object LiveKitReactNative {
|
|
|
30
30
|
*/
|
|
31
31
|
@JvmStatic
|
|
32
32
|
@JvmOverloads
|
|
33
|
-
fun setup(
|
|
33
|
+
fun setup(
|
|
34
|
+
context: Context,
|
|
35
|
+
audioType: AudioType = AudioType.CommunicationAudioType()
|
|
36
|
+
) {
|
|
34
37
|
val options = WebRTCModuleOptions.getInstance()
|
|
35
38
|
options.videoEncoderFactory = CustomVideoEncoderFactory(null, true, true)
|
|
36
39
|
options.videoDecoderFactory = CustomVideoDecoderFactory()
|
|
40
|
+
options.enableMediaProjectionService = true
|
|
37
41
|
|
|
38
42
|
val useHardwareAudioProcessing = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
|
|
39
43
|
|
package/ios/LivekitReactNative.m
CHANGED
|
@@ -121,44 +121,59 @@ RCT_EXPORT_METHOD(selectAudioOutput:(NSString *)deviceId
|
|
|
121
121
|
|
|
122
122
|
/// Configure audio config for WebRTC
|
|
123
123
|
RCT_EXPORT_METHOD(setAppleAudioConfiguration:(NSDictionary *) configuration){
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
config.categoryOptions
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
124
|
+
RTCAudioSession* session = [RTCAudioSession sharedInstance];
|
|
125
|
+
RTCAudioSessionConfiguration* config = [RTCAudioSessionConfiguration webRTCConfiguration];
|
|
126
|
+
|
|
127
|
+
NSString* appleAudioCategory = configuration[@"audioCategory"];
|
|
128
|
+
NSArray* appleAudioCategoryOptions = configuration[@"audioCategoryOptions"];
|
|
129
|
+
NSString* appleAudioMode = configuration[@"audioMode"];
|
|
130
|
+
|
|
131
|
+
[session lockForConfiguration];
|
|
132
|
+
|
|
133
|
+
NSError* error = nil;
|
|
134
|
+
BOOL categoryChanged = NO;
|
|
135
|
+
if(appleAudioCategoryOptions != nil) {
|
|
136
|
+
categoryChanged = YES;
|
|
137
|
+
config.categoryOptions = 0;
|
|
138
|
+
for(NSString* option in appleAudioCategoryOptions) {
|
|
139
|
+
if([@"mixWithOthers" isEqualToString:option]) {
|
|
140
|
+
config.categoryOptions |= AVAudioSessionCategoryOptionMixWithOthers;
|
|
141
|
+
} else if([@"duckOthers" isEqualToString:option]) {
|
|
142
|
+
config.categoryOptions |= AVAudioSessionCategoryOptionDuckOthers;
|
|
143
|
+
} else if([@"allowBluetooth" isEqualToString:option]) {
|
|
144
|
+
config.categoryOptions |= AVAudioSessionCategoryOptionAllowBluetooth;
|
|
145
|
+
} else if([@"allowBluetoothA2DP" isEqualToString:option]) {
|
|
146
|
+
config.categoryOptions |= AVAudioSessionCategoryOptionAllowBluetoothA2DP;
|
|
147
|
+
} else if([@"allowAirPlay" isEqualToString:option]) {
|
|
148
|
+
config.categoryOptions |= AVAudioSessionCategoryOptionAllowAirPlay;
|
|
149
|
+
} else if([@"defaultToSpeaker" isEqualToString:option]) {
|
|
150
|
+
config.categoryOptions |= AVAudioSessionCategoryOptionDefaultToSpeaker;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
149
153
|
}
|
|
150
|
-
}
|
|
151
154
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
155
|
+
if(appleAudioCategory != nil) {
|
|
156
|
+
categoryChanged = YES;
|
|
157
|
+
config.category = [AudioUtils audioSessionCategoryFromString:appleAudioCategory];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if(categoryChanged) {
|
|
161
|
+
[session setCategory:config.category withOptions:config.categoryOptions error:&error];
|
|
162
|
+
if(error != nil) {
|
|
163
|
+
NSLog(@"Error setting category: %@", [error localizedDescription]);
|
|
164
|
+
error = nil;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
156
167
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
168
|
+
if(appleAudioMode != nil) {
|
|
169
|
+
config.mode = [AudioUtils audioSessionModeFromString:appleAudioMode];
|
|
170
|
+
[session setMode:config.mode error:&error];
|
|
171
|
+
if(error != nil) {
|
|
172
|
+
NSLog(@"Error setting category: %@", [error localizedDescription]);
|
|
173
|
+
error = nil;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
161
176
|
|
|
162
|
-
|
|
177
|
+
[session unlockForConfiguration];
|
|
163
178
|
}
|
|
164
179
|
@end
|
|
@@ -162,6 +162,12 @@ _defineProperty(AudioSession, "showAudioRoutePicker", async () => {
|
|
|
162
162
|
await LivekitReactNative.showAudioRoutePicker();
|
|
163
163
|
}
|
|
164
164
|
});
|
|
165
|
+
/**
|
|
166
|
+
* Directly change the AVAudioSession category/mode.
|
|
167
|
+
*
|
|
168
|
+
* @param config The configuration to use. Null values will be omitted and the
|
|
169
|
+
* existing values will be unchanged.
|
|
170
|
+
*/
|
|
165
171
|
_defineProperty(AudioSession, "setAppleAudioConfiguration", async config => {
|
|
166
172
|
if (_reactNative.Platform.OS === 'ios') {
|
|
167
173
|
await LivekitReactNative.setAppleAudioConfiguration(config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","LINKING_ERROR","Platform","select","ios","default","LivekitReactNative","NativeModules","Proxy","get","Error","AndroidAudioTypePresets","exports","communication","manageAudioFocus","audioMode","audioFocusMode","audioStreamType","audioAttributesUsageType","audioAttributesContentType","media","getDefaultAppleAudioConfigurationForMode","mode","preferSpeakerOutput","audioCategory","audioCategoryOptions","AudioSession","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker","setAppleAudioConfiguration"],"sources":["AudioSession.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\nconst LINKING_ERROR =\n `The package '@livekit/react-native' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst LivekitReactNative = NativeModules.LivekitReactNative\n ? NativeModules.LivekitReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\n/**\n * Configuration for the underlying AudioSession.\n *\n * ----\n * Android specific options:\n *\n * * preferredOutputList - The preferred order in which to automatically select an audio output.\n * This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.\n *\n * By default, the order is set to:\n * 1. `\"bluetooth\"\n * 2. `\"headset\"``\n * 3. `\"speaker\"`\n * 4. `\"earpiece\"`\n *\n * * audioTypeOptions - An {@link AndroidAudioTypeOptions} object which provides the\n * audio options to use on Android.\n *\n * See {@link AndroidAudioTypePresets} for pre-configured values.\n *\n * ----\n * iOS\n *\n * * defaultOutput - The default preferred output to use when a wired headset or bluetooth output is unavailable.\n *\n * By default, this is set to `\"speaker\"`\n */\nexport type AudioConfiguration = {\n android?: {\n preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];\n audioTypeOptions: AndroidAudioTypeOptions;\n };\n ios?: {\n defaultOutput?: 'speaker' | 'earpiece';\n };\n};\n\nexport type AndroidAudioTypeOptions = {\n /**\n * Whether LiveKit should handle managing the audio focus or not.\n *\n * Defaults to true.\n */\n manageAudioFocus?: boolean;\n\n /**\n * Corresponds to {@link https://developer.android.com/reference/android/media/AudioManager#setMode(int)}\n *\n * Defaults to 'inCommunication'.\n */\n audioMode?:\n | 'normal'\n | 'callScreening'\n | 'inCall'\n | 'inCommunication'\n | 'ringtone';\n\n /**\n * Corresponds to the duration hint when requesting audio focus.\n *\n * Defaults to 'gain'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN}\n */\n audioFocusMode?:\n | 'gain'\n | 'gainTransient'\n | 'gainTransientExclusive'\n | 'gainTransientMayDuck';\n\n /**\n * Corresponds to Android's AudioAttributes usage type.\n *\n * Defaults to 'voiceCommunication'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesUsageType?:\n | 'alarm'\n | 'assistanceAccessibility'\n | 'assistanceNavigationGuidance'\n | 'assistanceSonification'\n | 'assistant'\n | 'game'\n | 'media'\n | 'notification'\n | 'notificationEvent'\n | 'notificationRingtone'\n | 'unknown'\n | 'voiceCommunication'\n | 'voiceCommunicationSignalling';\n\n /**\n * Corresponds to Android's AndroidAttributes content type.\n *\n * Defaults to 'speech'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesContentType?:\n | 'movie'\n | 'music'\n | 'sonification'\n | 'speech'\n | 'unknown';\n\n /**\n * Corresponds to the stream type when requesting audio focus. Used on pre-O devices.\n *\n * Defaults to 'voiceCall'\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#STREAM_VOICE_CALL}\n */\n audioStreamType?:\n | 'accessibility'\n | 'alarm'\n | 'dtmf'\n | 'music'\n | 'notification'\n | 'ring'\n | 'system'\n | 'voiceCall';\n\n /**\n * On certain Android devices, audio routing does not function properly and\n * bluetooth microphones will not work unless audio mode is set to\n * `inCommunication` or `inCall`. Audio routing is turned off those cases.\n *\n * If this set to true, will attempt to do audio routing regardless of audio mode.\n *\n * Defaults to false.\n */\n forceHandleAudioRouting?: boolean;\n};\n\nexport const AndroidAudioTypePresets: {\n /**\n * A pre-configured AndroidAudioConfiguration for voice communication.\n */\n communication: AndroidAudioTypeOptions;\n /**\n * A pre-configured AndroidAudioConfiguration for media playback.\n */\n media: AndroidAudioTypeOptions;\n} = {\n communication: {\n manageAudioFocus: true,\n audioMode: 'inCommunication',\n audioFocusMode: 'gain',\n audioStreamType: 'voiceCall',\n audioAttributesUsageType: 'voiceCommunication',\n audioAttributesContentType: 'speech',\n },\n media: {\n manageAudioFocus: true,\n audioMode: 'normal',\n audioFocusMode: 'gain',\n audioStreamType: 'music',\n audioAttributesUsageType: 'media',\n audioAttributesContentType: 'unknown',\n },\n} as const;\n\nexport type AppleAudioMode =\n | 'default'\n | 'gameChat'\n | 'measurement'\n | 'moviePlayback'\n | 'spokenAudio'\n | 'videoChat'\n | 'videoRecording'\n | 'voiceChat'\n | 'voicePrompt';\n\nexport type AppleAudioCategory =\n | 'soloAmbient'\n | 'playback'\n | 'record'\n | 'playAndRecord'\n | 'multiRoute';\n\nexport type AppleAudioCategoryOption =\n | 'mixWithOthers'\n | 'duckOthers'\n | 'interruptSpokenAudioAndMixWithOthers'\n | 'allowBluetooth'\n | 'allowBluetoothA2DP'\n | 'allowAirPlay'\n | 'defaultToSpeaker';\n\nexport type AppleAudioConfiguration = {\n audioCategory?: AppleAudioCategory;\n audioCategoryOptions?: AppleAudioCategoryOption[];\n audioMode?: AppleAudioMode;\n};\n\nexport type AudioTrackState =\n | 'none'\n | 'remoteOnly'\n | 'localOnly'\n | 'localAndRemote';\n\nexport function getDefaultAppleAudioConfigurationForMode(\n mode: AudioTrackState,\n preferSpeakerOutput: boolean = true\n): AppleAudioConfiguration {\n if (mode === 'remoteOnly') {\n return {\n audioCategory: 'playback',\n audioCategoryOptions: ['mixWithOthers'],\n audioMode: 'spokenAudio',\n };\n } else if (mode === 'localAndRemote' || mode === 'localOnly') {\n return {\n audioCategory: 'playAndRecord',\n audioCategoryOptions: ['allowBluetooth', 'mixWithOthers'],\n audioMode: preferSpeakerOutput ? 'videoChat' : 'voiceChat',\n };\n }\n\n return {\n audioCategory: 'soloAmbient',\n audioCategoryOptions: [],\n audioMode: 'default',\n };\n}\n\nexport default class AudioSession {\n /**\n * Applies the provided audio configuration to the underlying AudioSession.\n *\n * Must be called prior to connecting to a Room for the configuration to apply correctly.\n *\n * See also useIOSAudioManagement for automatic configuration of iOS audio options.\n */\n static configureAudio = async (config: AudioConfiguration) => {\n await LivekitReactNative.configureAudio(config);\n };\n\n /**\n * Starts an AudioSession.\n */\n static startAudioSession = async () => {\n await LivekitReactNative.startAudioSession();\n };\n\n /**\n * Stops the existing AudioSession.\n */\n static stopAudioSession = async () => {\n await LivekitReactNative.stopAudioSession();\n };\n\n /**\n * Gets the available audio outputs for use with {@link selectAudioOutput}.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * For Android, will return if available:\n * * \"speaker\"\n * * \"earpiece\"\n * * \"headset\"\n * * \"bluetooth\"\n *\n * ----\n *\n * For iOS, due to OS limitations, the only available types are:\n * * \"default\" - Use default iOS audio routing\n * * \"force_speaker\" - Force audio output through speaker\n *\n * See also {@link showAudioRoutePicker} to display a route picker that\n * can choose between other audio devices (i.e. headset/bluetooth/airplay),\n * or use a library like `react-native-avroutepicker` for a native platform\n * control.\n *\n * @returns the available audio output types\n */\n static getAudioOutputs = async (): Promise<string[]> => {\n if (Platform.OS === 'ios') {\n return ['default', 'force_speaker'];\n } else if (Platform.OS === 'android') {\n return (await LivekitReactNative.getAudioOutputs()) as string[];\n } else {\n return [];\n }\n };\n\n /**\n * Select the provided audio output if available.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * @param deviceId A deviceId retrieved from {@link getAudioOutputs}\n */\n static selectAudioOutput = async (deviceId: string) => {\n await LivekitReactNative.selectAudioOutput(deviceId);\n };\n\n /**\n * iOS only, requires iOS 11+.\n *\n * Displays an AVRoutePickerView for the user to choose their audio output.\n */\n static showAudioRoutePicker = async () => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.showAudioRoutePicker();\n }\n };\n\n static setAppleAudioConfiguration = async (\n config: AppleAudioConfiguration\n ) => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.setAppleAudioConfiguration(config);\n }\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAuD,SAAAC,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,eAAAD,CAAA,QAAAQ,CAAA,GAAAC,YAAA,CAAAT,CAAA,uCAAAQ,CAAA,GAAAA,CAAA,GAAAA,CAAA;AAAA,SAAAC,aAAAT,CAAA,EAAAD,CAAA,2BAAAC,CAAA,KAAAA,CAAA,SAAAA,CAAA,MAAAF,CAAA,GAAAE,CAAA,CAAAU,MAAA,CAAAC,WAAA,kBAAAb,CAAA,QAAAU,CAAA,GAAAV,CAAA,CAAAc,IAAA,CAAAZ,CAAA,EAAAD,CAAA,uCAAAS,CAAA,SAAAA,CAAA,YAAAK,SAAA,yEAAAd,CAAA,GAAAe,MAAA,GAAAC,MAAA,EAAAf,CAAA;AACvD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,MAAOO,QAAgB,IAAK;EACrD,MAAM3B,kBAAkB,CAAC4B,iBAAiB,CAACD,QAAQ,CAAC;AACtD,CAAC;AAED;AACF;AACA;AACA;AACA;AAJEnD,eAAA,CAvEmB4C,YAAY,0BA4ED,YAAY;EACxC,IAAIxB,qBAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMzB,kBAAkB,CAAC6B,oBAAoB,CAAC,CAAC;EACjD;AACF,CAAC;AAAArD,eAAA,CAhFkB4C,YAAY,gCAkFK,MAClCC,MAA+B,IAC5B;EACH,IAAIzB,qBAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMzB,kBAAkB,CAAC8B,0BAA0B,CAACT,MAAM,CAAC;EAC7D;AACF,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_defineProperty","e","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","LINKING_ERROR","Platform","select","ios","default","LivekitReactNative","NativeModules","Proxy","get","Error","AndroidAudioTypePresets","exports","communication","manageAudioFocus","audioMode","audioFocusMode","audioStreamType","audioAttributesUsageType","audioAttributesContentType","media","getDefaultAppleAudioConfigurationForMode","mode","preferSpeakerOutput","audioCategory","audioCategoryOptions","AudioSession","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker","setAppleAudioConfiguration"],"sources":["AudioSession.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\nconst LINKING_ERROR =\n `The package '@livekit/react-native' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst LivekitReactNative = NativeModules.LivekitReactNative\n ? NativeModules.LivekitReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\n/**\n * Configuration for the underlying AudioSession.\n *\n * ----\n * Android specific options:\n *\n * * preferredOutputList - The preferred order in which to automatically select an audio output.\n * This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.\n *\n * By default, the order is set to:\n * 1. `\"bluetooth\"\n * 2. `\"headset\"``\n * 3. `\"speaker\"`\n * 4. `\"earpiece\"`\n *\n * * audioTypeOptions - An {@link AndroidAudioTypeOptions} object which provides the\n * audio options to use on Android.\n *\n * See {@link AndroidAudioTypePresets} for pre-configured values.\n *\n * ----\n * iOS\n *\n * * defaultOutput - The default preferred output to use when a wired headset or bluetooth output is unavailable.\n *\n * By default, this is set to `\"speaker\"`\n */\nexport type AudioConfiguration = {\n android?: {\n preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];\n audioTypeOptions: AndroidAudioTypeOptions;\n };\n ios?: {\n defaultOutput?: 'speaker' | 'earpiece';\n };\n};\n\nexport type AndroidAudioTypeOptions = {\n /**\n * Whether LiveKit should handle managing the audio focus or not.\n *\n * Defaults to true.\n */\n manageAudioFocus?: boolean;\n\n /**\n * Corresponds to {@link https://developer.android.com/reference/android/media/AudioManager#setMode(int)}\n *\n * Defaults to 'inCommunication'.\n */\n audioMode?:\n | 'normal'\n | 'callScreening'\n | 'inCall'\n | 'inCommunication'\n | 'ringtone';\n\n /**\n * Corresponds to the duration hint when requesting audio focus.\n *\n * Defaults to 'gain'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN}\n */\n audioFocusMode?:\n | 'gain'\n | 'gainTransient'\n | 'gainTransientExclusive'\n | 'gainTransientMayDuck';\n\n /**\n * Corresponds to Android's AudioAttributes usage type.\n *\n * Defaults to 'voiceCommunication'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesUsageType?:\n | 'alarm'\n | 'assistanceAccessibility'\n | 'assistanceNavigationGuidance'\n | 'assistanceSonification'\n | 'assistant'\n | 'game'\n | 'media'\n | 'notification'\n | 'notificationEvent'\n | 'notificationRingtone'\n | 'unknown'\n | 'voiceCommunication'\n | 'voiceCommunicationSignalling';\n\n /**\n * Corresponds to Android's AndroidAttributes content type.\n *\n * Defaults to 'speech'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesContentType?:\n | 'movie'\n | 'music'\n | 'sonification'\n | 'speech'\n | 'unknown';\n\n /**\n * Corresponds to the stream type when requesting audio focus. Used on pre-O devices.\n *\n * Defaults to 'voiceCall'\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#STREAM_VOICE_CALL}\n */\n audioStreamType?:\n | 'accessibility'\n | 'alarm'\n | 'dtmf'\n | 'music'\n | 'notification'\n | 'ring'\n | 'system'\n | 'voiceCall';\n\n /**\n * On certain Android devices, audio routing does not function properly and\n * bluetooth microphones will not work unless audio mode is set to\n * `inCommunication` or `inCall`. Audio routing is turned off those cases.\n *\n * If this set to true, will attempt to do audio routing regardless of audio mode.\n *\n * Defaults to false.\n */\n forceHandleAudioRouting?: boolean;\n};\n\nexport const AndroidAudioTypePresets: {\n /**\n * A pre-configured AndroidAudioConfiguration for voice communication.\n */\n communication: AndroidAudioTypeOptions;\n /**\n * A pre-configured AndroidAudioConfiguration for media playback.\n */\n media: AndroidAudioTypeOptions;\n} = {\n communication: {\n manageAudioFocus: true,\n audioMode: 'inCommunication',\n audioFocusMode: 'gain',\n audioStreamType: 'voiceCall',\n audioAttributesUsageType: 'voiceCommunication',\n audioAttributesContentType: 'speech',\n },\n media: {\n manageAudioFocus: true,\n audioMode: 'normal',\n audioFocusMode: 'gain',\n audioStreamType: 'music',\n audioAttributesUsageType: 'media',\n audioAttributesContentType: 'unknown',\n },\n} as const;\n\nexport type AppleAudioMode =\n | 'default'\n | 'gameChat'\n | 'measurement'\n | 'moviePlayback'\n | 'spokenAudio'\n | 'videoChat'\n | 'videoRecording'\n | 'voiceChat'\n | 'voicePrompt';\n\nexport type AppleAudioCategory =\n | 'soloAmbient'\n | 'playback'\n | 'record'\n | 'playAndRecord'\n | 'multiRoute';\n\nexport type AppleAudioCategoryOption =\n | 'mixWithOthers'\n | 'duckOthers'\n | 'interruptSpokenAudioAndMixWithOthers'\n | 'allowBluetooth'\n | 'allowBluetoothA2DP'\n | 'allowAirPlay'\n | 'defaultToSpeaker';\n\nexport type AppleAudioConfiguration = {\n audioCategory?: AppleAudioCategory;\n audioCategoryOptions?: AppleAudioCategoryOption[];\n audioMode?: AppleAudioMode;\n};\n\nexport type AudioTrackState =\n | 'none'\n | 'remoteOnly'\n | 'localOnly'\n | 'localAndRemote';\n\nexport function getDefaultAppleAudioConfigurationForMode(\n mode: AudioTrackState,\n preferSpeakerOutput: boolean = true\n): AppleAudioConfiguration {\n if (mode === 'remoteOnly') {\n return {\n audioCategory: 'playback',\n audioCategoryOptions: ['mixWithOthers'],\n audioMode: 'spokenAudio',\n };\n } else if (mode === 'localAndRemote' || mode === 'localOnly') {\n return {\n audioCategory: 'playAndRecord',\n audioCategoryOptions: ['allowBluetooth', 'mixWithOthers'],\n audioMode: preferSpeakerOutput ? 'videoChat' : 'voiceChat',\n };\n }\n\n return {\n audioCategory: 'soloAmbient',\n audioCategoryOptions: [],\n audioMode: 'default',\n };\n}\n\nexport default class AudioSession {\n /**\n * Applies the provided audio configuration to the underlying AudioSession.\n *\n * Must be called prior to connecting to a Room for the configuration to apply correctly.\n *\n * See also useIOSAudioManagement for automatic configuration of iOS audio options.\n */\n static configureAudio = async (config: AudioConfiguration) => {\n await LivekitReactNative.configureAudio(config);\n };\n\n /**\n * Starts an AudioSession.\n */\n static startAudioSession = async () => {\n await LivekitReactNative.startAudioSession();\n };\n\n /**\n * Stops the existing AudioSession.\n */\n static stopAudioSession = async () => {\n await LivekitReactNative.stopAudioSession();\n };\n\n /**\n * Gets the available audio outputs for use with {@link selectAudioOutput}.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * For Android, will return if available:\n * * \"speaker\"\n * * \"earpiece\"\n * * \"headset\"\n * * \"bluetooth\"\n *\n * ----\n *\n * For iOS, due to OS limitations, the only available types are:\n * * \"default\" - Use default iOS audio routing\n * * \"force_speaker\" - Force audio output through speaker\n *\n * See also {@link showAudioRoutePicker} to display a route picker that\n * can choose between other audio devices (i.e. headset/bluetooth/airplay),\n * or use a library like `react-native-avroutepicker` for a native platform\n * control.\n *\n * @returns the available audio output types\n */\n static getAudioOutputs = async (): Promise<string[]> => {\n if (Platform.OS === 'ios') {\n return ['default', 'force_speaker'];\n } else if (Platform.OS === 'android') {\n return (await LivekitReactNative.getAudioOutputs()) as string[];\n } else {\n return [];\n }\n };\n\n /**\n * Select the provided audio output if available.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * @param deviceId A deviceId retrieved from {@link getAudioOutputs}\n */\n static selectAudioOutput = async (deviceId: string) => {\n await LivekitReactNative.selectAudioOutput(deviceId);\n };\n\n /**\n * iOS only, requires iOS 11+.\n *\n * Displays an AVRoutePickerView for the user to choose their audio output.\n */\n static showAudioRoutePicker = async () => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.showAudioRoutePicker();\n }\n };\n\n /**\n * Directly change the AVAudioSession category/mode.\n *\n * @param config The configuration to use. Null values will be omitted and the\n * existing values will be unchanged.\n */\n static setAppleAudioConfiguration = async (\n config: AppleAudioConfiguration\n ) => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.setAppleAudioConfiguration(config);\n }\n };\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAuD,SAAAC,gBAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAD,CAAA,GAAAI,MAAA,CAAAC,cAAA,CAAAL,CAAA,EAAAC,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YAAA,MAAAC,QAAA,UAAAT,CAAA,CAAAC,CAAA,IAAAC,CAAA,EAAAF,CAAA;AAAA,SAAAG,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;AACA;AACA;AACA;AACA;AAvBEhD,eAAA,CA1BmB4C,YAAY,qBAkDN,YAA+B;EACtD,IAAIxB,qBAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC;EACrC,CAAC,MAAM,IAAI7B,qBAAQ,CAAC6B,EAAE,KAAK,SAAS,EAAE;IACpC,OAAQ,MAAMzB,kBAAkB,CAAC0B,eAAe,CAAC,CAAC;EACpD,CAAC,MAAM;IACL,OAAO,EAAE;EACX;AACF,CAAC;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AANElD,eAAA,CA5DmB4C,YAAY,uBAmEJ,MAAOO,QAAgB,IAAK;EACrD,MAAM3B,kBAAkB,CAAC4B,iBAAiB,CAACD,QAAQ,CAAC;AACtD,CAAC;AAED;AACF;AACA;AACA;AACA;AAJEnD,eAAA,CAvEmB4C,YAAY,0BA4ED,YAAY;EACxC,IAAIxB,qBAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMzB,kBAAkB,CAAC6B,oBAAoB,CAAC,CAAC;EACjD;AACF,CAAC;AAED;AACF;AACA;AACA;AACA;AACA;AALErD,eAAA,CAlFmB4C,YAAY,gCAwFK,MAClCC,MAA+B,IAC5B;EACH,IAAIzB,qBAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMzB,kBAAkB,CAAC8B,0BAA0B,CAACT,MAAM,CAAC;EAC7D;AACF,CAAC","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -138,6 +138,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
138
138
|
*/
|
|
139
139
|
function registerGlobals() {
|
|
140
140
|
(0, _reactNativeWebrtc.registerGlobals)();
|
|
141
|
+
iosCategoryEnforce();
|
|
141
142
|
livekitRegisterGlobals();
|
|
142
143
|
(0, _reactNativeUrlPolyfill.setupURLPolyfill)();
|
|
143
144
|
fixWebrtcAdapter();
|
|
@@ -146,6 +147,25 @@ function registerGlobals() {
|
|
|
146
147
|
shimAsyncIterator();
|
|
147
148
|
shimIterator();
|
|
148
149
|
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Enforces changing to playAndRecord category prior to obtaining microphone.
|
|
153
|
+
*/
|
|
154
|
+
function iosCategoryEnforce() {
|
|
155
|
+
if (_reactNative.Platform.OS === 'ios') {
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
let getUserMediaFunc = global.navigator.mediaDevices.getUserMedia;
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
global.navigator.mediaDevices.getUserMedia = async constraints => {
|
|
160
|
+
if (constraints.audio) {
|
|
161
|
+
await _AudioSession.default.setAppleAudioConfiguration({
|
|
162
|
+
audioCategory: 'playAndRecord'
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return await getUserMediaFunc(constraints);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
149
169
|
function livekitRegisterGlobals() {
|
|
150
170
|
let lkGlobal = {
|
|
151
171
|
platform: _reactNative.Platform.OS,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNativeWebrtc","require","_reactNativeUrlPolyfill","_AudioSession","_interopRequireWildcard","_reactNative","_hooks","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_LiveKitRoom","_VideoTrack","_VideoView","_useParticipant","_useRoom","_logger","_AudioManager","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","registerGlobals","webrtcRegisterGlobals","livekitRegisterGlobals","setupURLPolyfill","fixWebrtcAdapter","shimPromiseAllSettled","shimArrayAt","shimAsyncIterator","shimIterator","lkGlobal","platform","Platform","OS","devicePixelRatio","PixelRatio","global","LiveKitReactNativeGlobal","_window","window","navigator","undefined","userAgent","product","allSettled","shim","Array","at"],"sources":["index.tsx"],"sourcesContent":["import { registerGlobals as webrtcRegisterGlobals } from '@livekit/react-native-webrtc';\nimport { setupURLPolyfill } from 'react-native-url-polyfill';\nimport './polyfills/EncoderDecoderTogether.min.js';\nimport AudioSession, {\n AndroidAudioTypePresets,\n type AndroidAudioTypeOptions,\n type AppleAudioCategory,\n type AppleAudioCategoryOption,\n type AppleAudioConfiguration,\n type AppleAudioMode,\n type AudioTrackState,\n getDefaultAppleAudioConfigurationForMode,\n} from './audio/AudioSession';\nimport type { AudioConfiguration } from './audio/AudioSession';\nimport { PixelRatio, Platform } from 'react-native';\nimport type { LiveKitReactNativeInfo } from 'livekit-client';\nimport type { LogLevel, SetLogLevelOptions } from './logger';\n\n/**\n * Registers the required globals needed for LiveKit to work.\n *\n * Must be called before using LiveKit.\n */\nexport function registerGlobals() {\n webrtcRegisterGlobals();\n livekitRegisterGlobals();\n setupURLPolyfill();\n fixWebrtcAdapter();\n shimPromiseAllSettled();\n shimArrayAt();\n shimAsyncIterator();\n shimIterator();\n}\nfunction livekitRegisterGlobals() {\n let lkGlobal: LiveKitReactNativeInfo = {\n platform: Platform.OS,\n devicePixelRatio: PixelRatio.get(),\n };\n\n // @ts-ignore\n global.LiveKitReactNativeGlobal = lkGlobal;\n}\n\nfunction fixWebrtcAdapter() {\n // @ts-ignore\n if (window?.navigator !== undefined) {\n // @ts-ignore\n const { navigator } = window;\n if (navigator.userAgent === undefined) {\n navigator.userAgent = navigator.product ?? 'Unknown';\n }\n }\n}\n\nfunction shimPromiseAllSettled() {\n var allSettled = require('promise.allsettled');\n allSettled.shim();\n}\n\nfunction shimArrayAt() {\n // Some versions of RN don't have Array.prototype.at, which is used by sdp-transform\n if (!Array.prototype.at) {\n var at = require('array.prototype.at');\n at.shim();\n }\n}\n\nfunction shimAsyncIterator() {\n var shim = require('well-known-symbols/Symbol.asyncIterator/shim');\n shim();\n}\n\nfunction shimIterator() {\n var shim = require('well-known-symbols/Symbol.iterator/shim');\n shim();\n}\nexport * from './hooks';\nexport * from './components/LiveKitRoom';\nexport * from './components/VideoTrack';\nexport * from './components/VideoView'; // deprecated\nexport * from './useParticipant'; // deprecated\nexport * from './useRoom'; // deprecated\nexport * from './logger';\nexport * from './audio/AudioManager';\n\nexport {\n AudioSession,\n AndroidAudioTypePresets,\n getDefaultAppleAudioConfigurationForMode,\n};\nexport type {\n AudioConfiguration,\n AndroidAudioTypeOptions,\n AppleAudioCategory,\n AppleAudioCategoryOption,\n AppleAudioConfiguration,\n AppleAudioMode,\n AudioTrackState,\n LogLevel,\n SetLogLevelOptions,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AACAA,OAAA;AACA,IAAAE,aAAA,GAAAC,uBAAA,CAAAH,OAAA;AAWA,IAAAI,YAAA,GAAAJ,OAAA;AA8DA,IAAAK,MAAA,GAAAL,OAAA;AAAAM,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,YAAA,GAAAlB,OAAA;AAAAM,MAAA,CAAAC,IAAA,CAAAW,YAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,I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AI,CAAC,CAAC;AACnB;AAEA,SAASlB,WAAWA,CAAA,EAAG;EACrB;EACA,IAAI,CAACmB,KAAK,CAACvD,SAAS,CAACwD,EAAE,EAAE;IACvB,IAAIA,EAAE,GAAGlE,OAAO,CAAC,oBAAoB,CAAC;IACtCkE,EAAE,CAACF,IAAI,CAAC,CAAC;EACX;AACF;AAEA,SAASjB,iBAAiBA,CAAA,EAAG;EAC3B,IAAIiB,IAAI,GAAGhE,OAAO,CAAC,8CAA8C,CAAC;EAClEgE,IAAI,CAAC,CAAC;AACR;AAEA,SAAShB,YAAYA,CAAA,EAAG;EACtB,IAAIgB,IAAI,GAAGhE,OAAO,CAAC,yCAAyC,CAAC;EAC7DgE,IAAI,CAAC,CAAC;AACR;;AAIwC;AACN;AACP","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_reactNativeWebrtc","require","_reactNativeUrlPolyfill","_AudioSession","_interopRequireWildcard","_reactNative","_hooks","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_LiveKitRoom","_VideoTrack","_VideoView","_useParticipant","_useRoom","_logger","_AudioManager","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","n","__proto__","a","getOwnPropertyDescriptor","u","i","set","registerGlobals","webrtcRegisterGlobals","iosCategoryEnforce","livekitRegisterGlobals","setupURLPolyfill","fixWebrtcAdapter","shimPromiseAllSettled","shimArrayAt","shimAsyncIterator","shimIterator","Platform","OS","getUserMediaFunc","global","navigator","mediaDevices","getUserMedia","constraints","audio","AudioSession","setAppleAudioConfiguration","audioCategory","lkGlobal","platform","devicePixelRatio","PixelRatio","LiveKitReactNativeGlobal","_window","window","undefined","userAgent","product","allSettled","shim","Array","at"],"sources":["index.tsx"],"sourcesContent":["import { registerGlobals as webrtcRegisterGlobals } from '@livekit/react-native-webrtc';\nimport { setupURLPolyfill } from 'react-native-url-polyfill';\nimport './polyfills/EncoderDecoderTogether.min.js';\nimport AudioSession, {\n AndroidAudioTypePresets,\n type AndroidAudioTypeOptions,\n type AppleAudioCategory,\n type AppleAudioCategoryOption,\n type AppleAudioConfiguration,\n type AppleAudioMode,\n type AudioTrackState,\n getDefaultAppleAudioConfigurationForMode,\n} from './audio/AudioSession';\nimport type { AudioConfiguration } from './audio/AudioSession';\nimport { PixelRatio, Platform } from 'react-native';\nimport { type LiveKitReactNativeInfo } from 'livekit-client';\nimport type { LogLevel, SetLogLevelOptions } from './logger';\n\n/**\n * Registers the required globals needed for LiveKit to work.\n *\n * Must be called before using LiveKit.\n */\nexport function registerGlobals() {\n webrtcRegisterGlobals();\n iosCategoryEnforce();\n livekitRegisterGlobals();\n setupURLPolyfill();\n fixWebrtcAdapter();\n shimPromiseAllSettled();\n shimArrayAt();\n shimAsyncIterator();\n shimIterator();\n}\n\n/**\n * Enforces changing to playAndRecord category prior to obtaining microphone.\n */\nfunction iosCategoryEnforce() {\n if (Platform.OS === 'ios') {\n // @ts-ignore\n let getUserMediaFunc = global.navigator.mediaDevices.getUserMedia;\n // @ts-ignore\n global.navigator.mediaDevices.getUserMedia = async (constraints: any) => {\n if (constraints.audio) {\n await AudioSession.setAppleAudioConfiguration({\n audioCategory: 'playAndRecord',\n });\n }\n\n return await getUserMediaFunc(constraints);\n };\n }\n}\n\nfunction livekitRegisterGlobals() {\n let lkGlobal: LiveKitReactNativeInfo = {\n platform: Platform.OS,\n devicePixelRatio: PixelRatio.get(),\n };\n\n // @ts-ignore\n global.LiveKitReactNativeGlobal = lkGlobal;\n}\n\nfunction fixWebrtcAdapter() {\n // @ts-ignore\n if (window?.navigator !== undefined) {\n // @ts-ignore\n const { navigator } = window;\n if (navigator.userAgent === undefined) {\n navigator.userAgent = navigator.product ?? 'Unknown';\n }\n }\n}\n\nfunction shimPromiseAllSettled() {\n var allSettled = require('promise.allsettled');\n allSettled.shim();\n}\n\nfunction shimArrayAt() {\n // Some versions of RN don't have Array.prototype.at, which is used by sdp-transform\n if (!Array.prototype.at) {\n var at = require('array.prototype.at');\n at.shim();\n }\n}\n\nfunction shimAsyncIterator() {\n var shim = require('well-known-symbols/Symbol.asyncIterator/shim');\n shim();\n}\n\nfunction shimIterator() {\n var shim = require('well-known-symbols/Symbol.iterator/shim');\n shim();\n}\nexport * from './hooks';\nexport * from './components/LiveKitRoom';\nexport * from './components/VideoTrack';\nexport * from './components/VideoView'; // deprecated\nexport * from './useParticipant'; // deprecated\nexport * from './useRoom'; // deprecated\nexport * from './logger';\nexport * from './audio/AudioManager';\n\nexport {\n AudioSession,\n AndroidAudioTypePresets,\n getDefaultAppleAudioConfigurationForMode,\n};\nexport type {\n AudioConfiguration,\n AndroidAudioTypeOptions,\n AppleAudioCategory,\n AppleAudioCategoryOption,\n AppleAudioConfiguration,\n AppleAudioMode,\n AudioTrackState,\n LogLevel,\n SetLogLevelOptions,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAD,OAAA;AACAA,OAAA;AACA,IAAAE,aAAA,GAAAC,uBAAA,CAAAH,OAAA;AAWA,IAAAI,YAAA,GAAAJ,OAAA;AAoFA,IAAAK,MAAA,GAAAL,OAAA;AAAAM,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,YAAA,GAAAlB,OAAA;AAAAM,MAAA,CAAAC,IAAA,CAAAW,YAAA,EA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154
|
await LivekitReactNative.showAudioRoutePicker();
|
|
155
155
|
}
|
|
156
156
|
});
|
|
157
|
+
/**
|
|
158
|
+
* Directly change the AVAudioSession category/mode.
|
|
159
|
+
*
|
|
160
|
+
* @param config The configuration to use. Null values will be omitted and the
|
|
161
|
+
* existing values will be unchanged.
|
|
162
|
+
*/
|
|
157
163
|
_defineProperty(AudioSession, "setAppleAudioConfiguration", async config => {
|
|
158
164
|
if (Platform.OS === 'ios') {
|
|
159
165
|
await LivekitReactNative.setAppleAudioConfiguration(config);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","LivekitReactNative","Proxy","get","Error","AndroidAudioTypePresets","communication","manageAudioFocus","audioMode","audioFocusMode","audioStreamType","audioAttributesUsageType","audioAttributesContentType","media","getDefaultAppleAudioConfigurationForMode","mode","preferSpeakerOutput","audioCategory","audioCategoryOptions","AudioSession","_defineProperty","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker","setAppleAudioConfiguration"],"sources":["AudioSession.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\nconst LINKING_ERROR =\n `The package '@livekit/react-native' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst LivekitReactNative = NativeModules.LivekitReactNative\n ? NativeModules.LivekitReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\n/**\n * Configuration for the underlying AudioSession.\n *\n * ----\n * Android specific options:\n *\n * * preferredOutputList - The preferred order in which to automatically select an audio output.\n * This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.\n *\n * By default, the order is set to:\n * 1. `\"bluetooth\"\n * 2. `\"headset\"``\n * 3. `\"speaker\"`\n * 4. `\"earpiece\"`\n *\n * * audioTypeOptions - An {@link AndroidAudioTypeOptions} object which provides the\n * audio options to use on Android.\n *\n * See {@link AndroidAudioTypePresets} for pre-configured values.\n *\n * ----\n * iOS\n *\n * * defaultOutput - The default preferred output to use when a wired headset or bluetooth output is unavailable.\n *\n * By default, this is set to `\"speaker\"`\n */\nexport type AudioConfiguration = {\n android?: {\n preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];\n audioTypeOptions: AndroidAudioTypeOptions;\n };\n ios?: {\n defaultOutput?: 'speaker' | 'earpiece';\n };\n};\n\nexport type AndroidAudioTypeOptions = {\n /**\n * Whether LiveKit should handle managing the audio focus or not.\n *\n * Defaults to true.\n */\n manageAudioFocus?: boolean;\n\n /**\n * Corresponds to {@link https://developer.android.com/reference/android/media/AudioManager#setMode(int)}\n *\n * Defaults to 'inCommunication'.\n */\n audioMode?:\n | 'normal'\n | 'callScreening'\n | 'inCall'\n | 'inCommunication'\n | 'ringtone';\n\n /**\n * Corresponds to the duration hint when requesting audio focus.\n *\n * Defaults to 'gain'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN}\n */\n audioFocusMode?:\n | 'gain'\n | 'gainTransient'\n | 'gainTransientExclusive'\n | 'gainTransientMayDuck';\n\n /**\n * Corresponds to Android's AudioAttributes usage type.\n *\n * Defaults to 'voiceCommunication'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesUsageType?:\n | 'alarm'\n | 'assistanceAccessibility'\n | 'assistanceNavigationGuidance'\n | 'assistanceSonification'\n | 'assistant'\n | 'game'\n | 'media'\n | 'notification'\n | 'notificationEvent'\n | 'notificationRingtone'\n | 'unknown'\n | 'voiceCommunication'\n | 'voiceCommunicationSignalling';\n\n /**\n * Corresponds to Android's AndroidAttributes content type.\n *\n * Defaults to 'speech'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesContentType?:\n | 'movie'\n | 'music'\n | 'sonification'\n | 'speech'\n | 'unknown';\n\n /**\n * Corresponds to the stream type when requesting audio focus. Used on pre-O devices.\n *\n * Defaults to 'voiceCall'\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#STREAM_VOICE_CALL}\n */\n audioStreamType?:\n | 'accessibility'\n | 'alarm'\n | 'dtmf'\n | 'music'\n | 'notification'\n | 'ring'\n | 'system'\n | 'voiceCall';\n\n /**\n * On certain Android devices, audio routing does not function properly and\n * bluetooth microphones will not work unless audio mode is set to\n * `inCommunication` or `inCall`. Audio routing is turned off those cases.\n *\n * If this set to true, will attempt to do audio routing regardless of audio mode.\n *\n * Defaults to false.\n */\n forceHandleAudioRouting?: boolean;\n};\n\nexport const AndroidAudioTypePresets: {\n /**\n * A pre-configured AndroidAudioConfiguration for voice communication.\n */\n communication: AndroidAudioTypeOptions;\n /**\n * A pre-configured AndroidAudioConfiguration for media playback.\n */\n media: AndroidAudioTypeOptions;\n} = {\n communication: {\n manageAudioFocus: true,\n audioMode: 'inCommunication',\n audioFocusMode: 'gain',\n audioStreamType: 'voiceCall',\n audioAttributesUsageType: 'voiceCommunication',\n audioAttributesContentType: 'speech',\n },\n media: {\n manageAudioFocus: true,\n audioMode: 'normal',\n audioFocusMode: 'gain',\n audioStreamType: 'music',\n audioAttributesUsageType: 'media',\n audioAttributesContentType: 'unknown',\n },\n} as const;\n\nexport type AppleAudioMode =\n | 'default'\n | 'gameChat'\n | 'measurement'\n | 'moviePlayback'\n | 'spokenAudio'\n | 'videoChat'\n | 'videoRecording'\n | 'voiceChat'\n | 'voicePrompt';\n\nexport type AppleAudioCategory =\n | 'soloAmbient'\n | 'playback'\n | 'record'\n | 'playAndRecord'\n | 'multiRoute';\n\nexport type AppleAudioCategoryOption =\n | 'mixWithOthers'\n | 'duckOthers'\n | 'interruptSpokenAudioAndMixWithOthers'\n | 'allowBluetooth'\n | 'allowBluetoothA2DP'\n | 'allowAirPlay'\n | 'defaultToSpeaker';\n\nexport type AppleAudioConfiguration = {\n audioCategory?: AppleAudioCategory;\n audioCategoryOptions?: AppleAudioCategoryOption[];\n audioMode?: AppleAudioMode;\n};\n\nexport type AudioTrackState =\n | 'none'\n | 'remoteOnly'\n | 'localOnly'\n | 'localAndRemote';\n\nexport function getDefaultAppleAudioConfigurationForMode(\n mode: AudioTrackState,\n preferSpeakerOutput: boolean = true\n): AppleAudioConfiguration {\n if (mode === 'remoteOnly') {\n return {\n audioCategory: 'playback',\n audioCategoryOptions: ['mixWithOthers'],\n audioMode: 'spokenAudio',\n };\n } else if (mode === 'localAndRemote' || mode === 'localOnly') {\n return {\n audioCategory: 'playAndRecord',\n audioCategoryOptions: ['allowBluetooth', 'mixWithOthers'],\n audioMode: preferSpeakerOutput ? 'videoChat' : 'voiceChat',\n };\n }\n\n return {\n audioCategory: 'soloAmbient',\n audioCategoryOptions: [],\n audioMode: 'default',\n };\n}\n\nexport default class AudioSession {\n /**\n * Applies the provided audio configuration to the underlying AudioSession.\n *\n * Must be called prior to connecting to a Room for the configuration to apply correctly.\n *\n * See also useIOSAudioManagement for automatic configuration of iOS audio options.\n */\n static configureAudio = async (config: AudioConfiguration) => {\n await LivekitReactNative.configureAudio(config);\n };\n\n /**\n * Starts an AudioSession.\n */\n static startAudioSession = async () => {\n await LivekitReactNative.startAudioSession();\n };\n\n /**\n * Stops the existing AudioSession.\n */\n static stopAudioSession = async () => {\n await LivekitReactNative.stopAudioSession();\n };\n\n /**\n * Gets the available audio outputs for use with {@link selectAudioOutput}.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * For Android, will return if available:\n * * \"speaker\"\n * * \"earpiece\"\n * * \"headset\"\n * * \"bluetooth\"\n *\n * ----\n *\n * For iOS, due to OS limitations, the only available types are:\n * * \"default\" - Use default iOS audio routing\n * * \"force_speaker\" - Force audio output through speaker\n *\n * See also {@link showAudioRoutePicker} to display a route picker that\n * can choose between other audio devices (i.e. headset/bluetooth/airplay),\n * or use a library like `react-native-avroutepicker` for a native platform\n * control.\n *\n * @returns the available audio output types\n */\n static getAudioOutputs = async (): Promise<string[]> => {\n if (Platform.OS === 'ios') {\n return ['default', 'force_speaker'];\n } else if (Platform.OS === 'android') {\n return (await LivekitReactNative.getAudioOutputs()) as string[];\n } else {\n return [];\n }\n };\n\n /**\n * Select the provided audio output if available.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * @param deviceId A deviceId retrieved from {@link getAudioOutputs}\n */\n static selectAudioOutput = async (deviceId: string) => {\n await LivekitReactNative.selectAudioOutput(deviceId);\n };\n\n /**\n * iOS only, requires iOS 11+.\n *\n * Displays an AVRoutePickerView for the user to choose their audio output.\n */\n static showAudioRoutePicker = async () => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.showAudioRoutePicker();\n }\n };\n\n static setAppleAudioConfiguration = async (\n config: AppleAudioConfiguration\n ) => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.setAppleAudioConfiguration(config);\n }\n };\n}\n"],"mappings":";;;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,MAAMC,aAAa,GACjB,gFAAgF,GAChFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMC,kBAAkB,GAAGN,aAAa,CAACM,kBAAkB,GACvDN,aAAa,CAACM,kBAAkB,GAChC,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA6GA,OAAO,MAAMQ,uBASZ,GAAG;EACFC,aAAa,EAAE;IACbC,gBAAgB,EAAE,IAAI;IACtBC,SAAS,EAAE,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ACpC,MAAMlB,kBAAkB,CAACuB,gBAAgB,CAAC,CAAC;AAC7C,CAAC;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAvBEJ,eAAA,CA1BmBD,YAAY,qBAkDN,YAA+B;EACtD,IAAIvB,QAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,OAAO,CAAC,SAAS,EAAE,eAAe,CAAC;EACrC,CAAC,MAAM,IAAI7B,QAAQ,CAAC6B,EAAE,KAAK,SAAS,EAAE;IACpC,OAAQ,MAAMxB,kBAAkB,CAACyB,eAAe,CAAC,CAAC;EACpD,CAAC,MAAM;IACL,OAAO,EAAE;EACX;AACF,CAAC;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AANEN,eAAA,CA5DmBD,YAAY,uBAmEJ,MAAOQ,QAAgB,IAAK;EACrD,MAAM1B,kBAAkB,CAAC2B,iBAAiB,CAACD,QAAQ,CAAC;AACtD,CAAC;AAED;AACF;AACA;AACA;AACA;AAJEP,eAAA,CAvEmBD,YAAY,0BA4ED,YAAY;EACxC,IAAIvB,QAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMxB,kBAAkB,CAAC4B,oBAAoB,CAAC,CAAC;EACjD;AACF,CAAC;AAAAT,eAAA,CAhFkBD,YAAY,gCAkFK,MAClCE,MAA+B,IAC5B;EACH,IAAIzB,QAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMxB,kBAAkB,CAAC6B,0BAA0B,CAACT,MAAM,CAAC;EAC7D;AACF,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","LivekitReactNative","Proxy","get","Error","AndroidAudioTypePresets","communication","manageAudioFocus","audioMode","audioFocusMode","audioStreamType","audioAttributesUsageType","audioAttributesContentType","media","getDefaultAppleAudioConfigurationForMode","mode","preferSpeakerOutput","audioCategory","audioCategoryOptions","AudioSession","_defineProperty","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker","setAppleAudioConfiguration"],"sources":["AudioSession.ts"],"sourcesContent":["import { NativeModules, Platform } from 'react-native';\nconst LINKING_ERROR =\n `The package '@livekit/react-native' doesn't seem to be linked. Make sure: \\n\\n` +\n Platform.select({ ios: \"- You have run 'pod install'\\n\", default: '' }) +\n '- You rebuilt the app after installing the package\\n' +\n '- You are not using Expo managed workflow\\n';\n\nconst LivekitReactNative = NativeModules.LivekitReactNative\n ? NativeModules.LivekitReactNative\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\n/**\n * Configuration for the underlying AudioSession.\n *\n * ----\n * Android specific options:\n *\n * * preferredOutputList - The preferred order in which to automatically select an audio output.\n * This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.\n *\n * By default, the order is set to:\n * 1. `\"bluetooth\"\n * 2. `\"headset\"``\n * 3. `\"speaker\"`\n * 4. `\"earpiece\"`\n *\n * * audioTypeOptions - An {@link AndroidAudioTypeOptions} object which provides the\n * audio options to use on Android.\n *\n * See {@link AndroidAudioTypePresets} for pre-configured values.\n *\n * ----\n * iOS\n *\n * * defaultOutput - The default preferred output to use when a wired headset or bluetooth output is unavailable.\n *\n * By default, this is set to `\"speaker\"`\n */\nexport type AudioConfiguration = {\n android?: {\n preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];\n audioTypeOptions: AndroidAudioTypeOptions;\n };\n ios?: {\n defaultOutput?: 'speaker' | 'earpiece';\n };\n};\n\nexport type AndroidAudioTypeOptions = {\n /**\n * Whether LiveKit should handle managing the audio focus or not.\n *\n * Defaults to true.\n */\n manageAudioFocus?: boolean;\n\n /**\n * Corresponds to {@link https://developer.android.com/reference/android/media/AudioManager#setMode(int)}\n *\n * Defaults to 'inCommunication'.\n */\n audioMode?:\n | 'normal'\n | 'callScreening'\n | 'inCall'\n | 'inCommunication'\n | 'ringtone';\n\n /**\n * Corresponds to the duration hint when requesting audio focus.\n *\n * Defaults to 'gain'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN}\n */\n audioFocusMode?:\n | 'gain'\n | 'gainTransient'\n | 'gainTransientExclusive'\n | 'gainTransientMayDuck';\n\n /**\n * Corresponds to Android's AudioAttributes usage type.\n *\n * Defaults to 'voiceCommunication'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesUsageType?:\n | 'alarm'\n | 'assistanceAccessibility'\n | 'assistanceNavigationGuidance'\n | 'assistanceSonification'\n | 'assistant'\n | 'game'\n | 'media'\n | 'notification'\n | 'notificationEvent'\n | 'notificationRingtone'\n | 'unknown'\n | 'voiceCommunication'\n | 'voiceCommunicationSignalling';\n\n /**\n * Corresponds to Android's AndroidAttributes content type.\n *\n * Defaults to 'speech'.\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioAttributes}\n */\n audioAttributesContentType?:\n | 'movie'\n | 'music'\n | 'sonification'\n | 'speech'\n | 'unknown';\n\n /**\n * Corresponds to the stream type when requesting audio focus. Used on pre-O devices.\n *\n * Defaults to 'voiceCall'\n *\n * See also {@link https://developer.android.com/reference/android/media/AudioManager#STREAM_VOICE_CALL}\n */\n audioStreamType?:\n | 'accessibility'\n | 'alarm'\n | 'dtmf'\n | 'music'\n | 'notification'\n | 'ring'\n | 'system'\n | 'voiceCall';\n\n /**\n * On certain Android devices, audio routing does not function properly and\n * bluetooth microphones will not work unless audio mode is set to\n * `inCommunication` or `inCall`. Audio routing is turned off those cases.\n *\n * If this set to true, will attempt to do audio routing regardless of audio mode.\n *\n * Defaults to false.\n */\n forceHandleAudioRouting?: boolean;\n};\n\nexport const AndroidAudioTypePresets: {\n /**\n * A pre-configured AndroidAudioConfiguration for voice communication.\n */\n communication: AndroidAudioTypeOptions;\n /**\n * A pre-configured AndroidAudioConfiguration for media playback.\n */\n media: AndroidAudioTypeOptions;\n} = {\n communication: {\n manageAudioFocus: true,\n audioMode: 'inCommunication',\n audioFocusMode: 'gain',\n audioStreamType: 'voiceCall',\n audioAttributesUsageType: 'voiceCommunication',\n audioAttributesContentType: 'speech',\n },\n media: {\n manageAudioFocus: true,\n audioMode: 'normal',\n audioFocusMode: 'gain',\n audioStreamType: 'music',\n audioAttributesUsageType: 'media',\n audioAttributesContentType: 'unknown',\n },\n} as const;\n\nexport type AppleAudioMode =\n | 'default'\n | 'gameChat'\n | 'measurement'\n | 'moviePlayback'\n | 'spokenAudio'\n | 'videoChat'\n | 'videoRecording'\n | 'voiceChat'\n | 'voicePrompt';\n\nexport type AppleAudioCategory =\n | 'soloAmbient'\n | 'playback'\n | 'record'\n | 'playAndRecord'\n | 'multiRoute';\n\nexport type AppleAudioCategoryOption =\n | 'mixWithOthers'\n | 'duckOthers'\n | 'interruptSpokenAudioAndMixWithOthers'\n | 'allowBluetooth'\n | 'allowBluetoothA2DP'\n | 'allowAirPlay'\n | 'defaultToSpeaker';\n\nexport type AppleAudioConfiguration = {\n audioCategory?: AppleAudioCategory;\n audioCategoryOptions?: AppleAudioCategoryOption[];\n audioMode?: AppleAudioMode;\n};\n\nexport type AudioTrackState =\n | 'none'\n | 'remoteOnly'\n | 'localOnly'\n | 'localAndRemote';\n\nexport function getDefaultAppleAudioConfigurationForMode(\n mode: AudioTrackState,\n preferSpeakerOutput: boolean = true\n): AppleAudioConfiguration {\n if (mode === 'remoteOnly') {\n return {\n audioCategory: 'playback',\n audioCategoryOptions: ['mixWithOthers'],\n audioMode: 'spokenAudio',\n };\n } else if (mode === 'localAndRemote' || mode === 'localOnly') {\n return {\n audioCategory: 'playAndRecord',\n audioCategoryOptions: ['allowBluetooth', 'mixWithOthers'],\n audioMode: preferSpeakerOutput ? 'videoChat' : 'voiceChat',\n };\n }\n\n return {\n audioCategory: 'soloAmbient',\n audioCategoryOptions: [],\n audioMode: 'default',\n };\n}\n\nexport default class AudioSession {\n /**\n * Applies the provided audio configuration to the underlying AudioSession.\n *\n * Must be called prior to connecting to a Room for the configuration to apply correctly.\n *\n * See also useIOSAudioManagement for automatic configuration of iOS audio options.\n */\n static configureAudio = async (config: AudioConfiguration) => {\n await LivekitReactNative.configureAudio(config);\n };\n\n /**\n * Starts an AudioSession.\n */\n static startAudioSession = async () => {\n await LivekitReactNative.startAudioSession();\n };\n\n /**\n * Stops the existing AudioSession.\n */\n static stopAudioSession = async () => {\n await LivekitReactNative.stopAudioSession();\n };\n\n /**\n * Gets the available audio outputs for use with {@link selectAudioOutput}.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * For Android, will return if available:\n * * \"speaker\"\n * * \"earpiece\"\n * * \"headset\"\n * * \"bluetooth\"\n *\n * ----\n *\n * For iOS, due to OS limitations, the only available types are:\n * * \"default\" - Use default iOS audio routing\n * * \"force_speaker\" - Force audio output through speaker\n *\n * See also {@link showAudioRoutePicker} to display a route picker that\n * can choose between other audio devices (i.e. headset/bluetooth/airplay),\n * or use a library like `react-native-avroutepicker` for a native platform\n * control.\n *\n * @returns the available audio output types\n */\n static getAudioOutputs = async (): Promise<string[]> => {\n if (Platform.OS === 'ios') {\n return ['default', 'force_speaker'];\n } else if (Platform.OS === 'android') {\n return (await LivekitReactNative.getAudioOutputs()) as string[];\n } else {\n return [];\n }\n };\n\n /**\n * Select the provided audio output if available.\n *\n * {@link startAudioSession} must be called prior to using this method.\n *\n * @param deviceId A deviceId retrieved from {@link getAudioOutputs}\n */\n static selectAudioOutput = async (deviceId: string) => {\n await LivekitReactNative.selectAudioOutput(deviceId);\n };\n\n /**\n * iOS only, requires iOS 11+.\n *\n * Displays an AVRoutePickerView for the user to choose their audio output.\n */\n static showAudioRoutePicker = async () => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.showAudioRoutePicker();\n }\n };\n\n /**\n * Directly change the AVAudioSession category/mode.\n *\n * @param config The configuration to use. Null values will be omitted and the\n * existing values will be unchanged.\n */\n static setAppleAudioConfiguration = async (\n config: AppleAudioConfiguration\n ) => {\n if (Platform.OS === 'ios') {\n await LivekitReactNative.setAppleAudioConfiguration(config);\n }\n };\n}\n"],"mappings":";;;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AACtD,MAAMC,aAAa,GACjB,gFAAgF,GAChFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,6CAA6C;AAE/C,MAAMC,kBAAkB,GAAGN,aAAa,CAACM,kBAAkB,GACvDN,aAAa,CAACM,kBAAkB,GAChC,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA6GA,OAAO,MAAMQ,uBASZ,GAAG;EACFC,aAAa,EAAE;IACbC,gBAAgB,EAAE,IAAI;IACtBC,SAAS,EAAE,iBAAiB;IAC5BC,cAAc,EAAE,MAAM;IACtBC,eAAe,EAAE,WAAW;IAC5BC,wBAAwB,EAAE,oBAAoB;IAC9CC,0BAA0B,EAAE;EAC9B,CAAC;EACDC,KAAK,EAAE;IACLN,gBAAgB,EAAE,IAAI;IACtBC,SAAS,EAAE,QAAQ;IACnBC,cAAc,EAAE,MAAM;IACtBC,eAAe,EAAE,OAAO;IACxBC,wBAAwB,EAAE,OAAO;IACjCC,0BAA0B,EAAE;EAC9B;AACF,CAAU;AAyCV,OAAO,SAASE,wCAAwCA,CACtDC,IAAqB,EACrBC,mBAA4B,GAAG,IAAI,EACV;EACzB,IAAID,IAAI,KAAK,YAAY,EAAE;IACzB,OAAO;MACLE,aAAa,EAAE,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M;IACL,OAAO,EAAE;EACX;AACF,CAAC;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AANEN,eAAA,CA5DmBD,YAAY,uBAmEJ,MAAOQ,QAAgB,IAAK;EACrD,MAAM1B,kBAAkB,CAAC2B,iBAAiB,CAACD,QAAQ,CAAC;AACtD,CAAC;AAED;AACF;AACA;AACA;AACA;AAJEP,eAAA,CAvEmBD,YAAY,0BA4ED,YAAY;EACxC,IAAIvB,QAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMxB,kBAAkB,CAAC4B,oBAAoB,CAAC,CAAC;EACjD;AACF,CAAC;AAED;AACF;AACA;AACA;AACA;AACA;AALET,eAAA,CAlFmBD,YAAY,gCAwFK,MAClCE,MAA+B,IAC5B;EACH,IAAIzB,QAAQ,CAAC6B,EAAE,KAAK,KAAK,EAAE;IACzB,MAAMxB,kBAAkB,CAAC6B,0BAA0B,CAACT,MAAM,CAAC;EAC7D;AACF,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import { PixelRatio, Platform } from 'react-native';
|
|
|
10
10
|
*/
|
|
11
11
|
export function registerGlobals() {
|
|
12
12
|
webrtcRegisterGlobals();
|
|
13
|
+
iosCategoryEnforce();
|
|
13
14
|
livekitRegisterGlobals();
|
|
14
15
|
setupURLPolyfill();
|
|
15
16
|
fixWebrtcAdapter();
|
|
@@ -18,6 +19,25 @@ export function registerGlobals() {
|
|
|
18
19
|
shimAsyncIterator();
|
|
19
20
|
shimIterator();
|
|
20
21
|
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Enforces changing to playAndRecord category prior to obtaining microphone.
|
|
25
|
+
*/
|
|
26
|
+
function iosCategoryEnforce() {
|
|
27
|
+
if (Platform.OS === 'ios') {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
let getUserMediaFunc = global.navigator.mediaDevices.getUserMedia;
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
global.navigator.mediaDevices.getUserMedia = async constraints => {
|
|
32
|
+
if (constraints.audio) {
|
|
33
|
+
await AudioSession.setAppleAudioConfiguration({
|
|
34
|
+
audioCategory: 'playAndRecord'
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return await getUserMediaFunc(constraints);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
21
41
|
function livekitRegisterGlobals() {
|
|
22
42
|
let lkGlobal = {
|
|
23
43
|
platform: Platform.OS,
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["registerGlobals","webrtcRegisterGlobals","setupURLPolyfill","AudioSession","AndroidAudioTypePresets","getDefaultAppleAudioConfigurationForMode","PixelRatio","Platform","livekitRegisterGlobals","fixWebrtcAdapter","shimPromiseAllSettled","shimArrayAt","shimAsyncIterator","shimIterator","
|
|
1
|
+
{"version":3,"names":["registerGlobals","webrtcRegisterGlobals","setupURLPolyfill","AudioSession","AndroidAudioTypePresets","getDefaultAppleAudioConfigurationForMode","PixelRatio","Platform","iosCategoryEnforce","livekitRegisterGlobals","fixWebrtcAdapter","shimPromiseAllSettled","shimArrayAt","shimAsyncIterator","shimIterator","OS","getUserMediaFunc","global","navigator","mediaDevices","getUserMedia","constraints","audio","setAppleAudioConfiguration","audioCategory","lkGlobal","platform","devicePixelRatio","get","LiveKitReactNativeGlobal","_window","window","undefined","userAgent","product","allSettled","require","shim","Array","prototype","at"],"sources":["index.tsx"],"sourcesContent":["import { registerGlobals as webrtcRegisterGlobals } from '@livekit/react-native-webrtc';\nimport { setupURLPolyfill } from 'react-native-url-polyfill';\nimport './polyfills/EncoderDecoderTogether.min.js';\nimport AudioSession, {\n AndroidAudioTypePresets,\n type AndroidAudioTypeOptions,\n type AppleAudioCategory,\n type AppleAudioCategoryOption,\n type AppleAudioConfiguration,\n type AppleAudioMode,\n type AudioTrackState,\n getDefaultAppleAudioConfigurationForMode,\n} from './audio/AudioSession';\nimport type { AudioConfiguration } from './audio/AudioSession';\nimport { PixelRatio, Platform } from 'react-native';\nimport { type LiveKitReactNativeInfo } from 'livekit-client';\nimport type { LogLevel, SetLogLevelOptions } from './logger';\n\n/**\n * Registers the required globals needed for LiveKit to work.\n *\n * Must be called before using LiveKit.\n */\nexport function registerGlobals() {\n webrtcRegisterGlobals();\n iosCategoryEnforce();\n livekitRegisterGlobals();\n setupURLPolyfill();\n fixWebrtcAdapter();\n shimPromiseAllSettled();\n shimArrayAt();\n shimAsyncIterator();\n shimIterator();\n}\n\n/**\n * Enforces changing to playAndRecord category prior to obtaining microphone.\n */\nfunction iosCategoryEnforce() {\n if (Platform.OS === 'ios') {\n // @ts-ignore\n let getUserMediaFunc = global.navigator.mediaDevices.getUserMedia;\n // @ts-ignore\n global.navigator.mediaDevices.getUserMedia = async (constraints: any) => {\n if (constraints.audio) {\n await AudioSession.setAppleAudioConfiguration({\n audioCategory: 'playAndRecord',\n });\n }\n\n return await getUserMediaFunc(constraints);\n };\n }\n}\n\nfunction livekitRegisterGlobals() {\n let lkGlobal: LiveKitReactNativeInfo = {\n platform: Platform.OS,\n devicePixelRatio: PixelRatio.get(),\n };\n\n // @ts-ignore\n global.LiveKitReactNativeGlobal = lkGlobal;\n}\n\nfunction fixWebrtcAdapter() {\n // @ts-ignore\n if (window?.navigator !== undefined) {\n // @ts-ignore\n const { navigator } = window;\n if (navigator.userAgent === undefined) {\n navigator.userAgent = navigator.product ?? 'Unknown';\n }\n }\n}\n\nfunction shimPromiseAllSettled() {\n var allSettled = require('promise.allsettled');\n allSettled.shim();\n}\n\nfunction shimArrayAt() {\n // Some versions of RN don't have Array.prototype.at, which is used by sdp-transform\n if (!Array.prototype.at) {\n var at = require('array.prototype.at');\n at.shim();\n }\n}\n\nfunction shimAsyncIterator() {\n var shim = require('well-known-symbols/Symbol.asyncIterator/shim');\n shim();\n}\n\nfunction shimIterator() {\n var shim = require('well-known-symbols/Symbol.iterator/shim');\n shim();\n}\nexport * from './hooks';\nexport * from './components/LiveKitRoom';\nexport * from './components/VideoTrack';\nexport * from './components/VideoView'; // deprecated\nexport * from './useParticipant'; // deprecated\nexport * from './useRoom'; // deprecated\nexport * from './logger';\nexport * from './audio/AudioManager';\n\nexport {\n AudioSession,\n AndroidAudioTypePresets,\n getDefaultAppleAudioConfigurationForMode,\n};\nexport type {\n AudioConfiguration,\n AndroidAudioTypeOptions,\n AppleAudioCategory,\n AppleAudioCategoryOption,\n AppleAudioConfiguration,\n AppleAudioMode,\n AudioTrackState,\n LogLevel,\n SetLogLevelOptions,\n};\n"],"mappings":"AAAA,SAASA,eAAe,IAAIC,qBAAqB,QAAQ,8BAA8B;AACvF,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,OAAO,2CAA2C;AAClD,OAAOC,YAAY,IACjBC,uBAAuB,EAOvBC,wCAAwC,QACnC,sBAAsB;AAE7B,SAASC,UAAU,EAAEC,QAAQ,QAAQ,cAAc;AAInD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASP,eAAeA,CAAA,EAAG;EAChCC,qBAAqB,CAAC,CAAC;EACvBO,kBAAkB,CAAC,CAAC;EACpBC,sBAAsB,CAAC,CAAC;EACxBP,gBAAgB,CAAC,CAAC;EAClBQ,gBAAgB,CAAC,CAAC;EAClBC,qBAAqB,CAAC,CAAC;EACvBC,WAAW,CAAC,CAAC;EACbC,iBAAiB,CAAC,CAAC;EACnBC,YAAY,CAAC,CAAC;AAChB;;AAEA;AACA;AACA;AACA,SAASN,kBAAkBA,CAAA,EAAG;EAC5B,IAAID,QAAQ,CAACQ,EAAE,KAAK,KAAK,EAAE;IACzB;IACA,IAAIC,gBAAgB,GAAGC,MAAM,CAACC,SAAS,CAACC,YAAY,CAACC,YAAY;IACjE;IACAH,MAAM,CAACC,SAAS,CAACC,YAAY,CAACC,YAAY,GAAG,MAAOC,WAAgB,IAAK;MACvE,IAAIA,WAAW,CAACC,KAAK,EAAE;QACrB,MAAMnB,YAAY,CAACoB,0BAA0B,CAAC;UAC5CC,aAAa,EA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Ac,SAAS;AACvB,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,wBAAwB,CAAC,CAAC;AACxC,cAAc,kBAAkB,CAAC,CAAC;AAClC,cAAc,WAAW,CAAC,CAAC;AAC3B,cAAc,UAAU;AACxB,cAAc,sBAAsB;AAEpC,SACElC,YAAY,EACZC,uBAAuB,EACvBC,wCAAwC","ignoreList":[]}
|
|
@@ -166,5 +166,11 @@ export default class AudioSession {
|
|
|
166
166
|
* Displays an AVRoutePickerView for the user to choose their audio output.
|
|
167
167
|
*/
|
|
168
168
|
static showAudioRoutePicker: () => Promise<void>;
|
|
169
|
+
/**
|
|
170
|
+
* Directly change the AVAudioSession category/mode.
|
|
171
|
+
*
|
|
172
|
+
* @param config The configuration to use. Null values will be omitted and the
|
|
173
|
+
* existing values will be unchanged.
|
|
174
|
+
*/
|
|
169
175
|
static setAppleAudioConfiguration: (config: AppleAudioConfiguration) => Promise<void>;
|
|
170
176
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livekit/react-native",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "LiveKit for React Native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@livekit/components-react": "^2.0.6",
|
|
46
46
|
"array.prototype.at": "^1.1.1",
|
|
47
|
-
"livekit-client": "^2.
|
|
47
|
+
"livekit-client": "^2.4.2",
|
|
48
48
|
"loglevel": "^1.8.0",
|
|
49
49
|
"promise.allsettled": "^1.0.5",
|
|
50
50
|
"react-native-url-polyfill": "^1.3.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@babel/preset-env": "^7.20.0",
|
|
56
56
|
"@babel/runtime": "^7.20.0",
|
|
57
57
|
"@commitlint/config-conventional": "^16.2.1",
|
|
58
|
-
"@livekit/react-native-webrtc": "^
|
|
58
|
+
"@livekit/react-native-webrtc": "^125.0.3",
|
|
59
59
|
"@react-native/babel-preset": "0.74.84",
|
|
60
60
|
"@react-native/eslint-config": "0.74.84",
|
|
61
61
|
"@react-native/metro-config": "0.74.84",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"typescript": "5.0.4"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
|
-
"@livekit/react-native-webrtc": "^125.0.
|
|
84
|
+
"@livekit/react-native-webrtc": "^125.0.3",
|
|
85
85
|
"react": "*",
|
|
86
86
|
"react-native": "*"
|
|
87
87
|
},
|
|
@@ -325,6 +325,12 @@ export default class AudioSession {
|
|
|
325
325
|
}
|
|
326
326
|
};
|
|
327
327
|
|
|
328
|
+
/**
|
|
329
|
+
* Directly change the AVAudioSession category/mode.
|
|
330
|
+
*
|
|
331
|
+
* @param config The configuration to use. Null values will be omitted and the
|
|
332
|
+
* existing values will be unchanged.
|
|
333
|
+
*/
|
|
328
334
|
static setAppleAudioConfiguration = async (
|
|
329
335
|
config: AppleAudioConfiguration
|
|
330
336
|
) => {
|
package/src/index.tsx
CHANGED
|
@@ -13,7 +13,7 @@ import AudioSession, {
|
|
|
13
13
|
} from './audio/AudioSession';
|
|
14
14
|
import type { AudioConfiguration } from './audio/AudioSession';
|
|
15
15
|
import { PixelRatio, Platform } from 'react-native';
|
|
16
|
-
import type
|
|
16
|
+
import { type LiveKitReactNativeInfo } from 'livekit-client';
|
|
17
17
|
import type { LogLevel, SetLogLevelOptions } from './logger';
|
|
18
18
|
|
|
19
19
|
/**
|
|
@@ -23,6 +23,7 @@ import type { LogLevel, SetLogLevelOptions } from './logger';
|
|
|
23
23
|
*/
|
|
24
24
|
export function registerGlobals() {
|
|
25
25
|
webrtcRegisterGlobals();
|
|
26
|
+
iosCategoryEnforce();
|
|
26
27
|
livekitRegisterGlobals();
|
|
27
28
|
setupURLPolyfill();
|
|
28
29
|
fixWebrtcAdapter();
|
|
@@ -31,6 +32,27 @@ export function registerGlobals() {
|
|
|
31
32
|
shimAsyncIterator();
|
|
32
33
|
shimIterator();
|
|
33
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Enforces changing to playAndRecord category prior to obtaining microphone.
|
|
38
|
+
*/
|
|
39
|
+
function iosCategoryEnforce() {
|
|
40
|
+
if (Platform.OS === 'ios') {
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
let getUserMediaFunc = global.navigator.mediaDevices.getUserMedia;
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
global.navigator.mediaDevices.getUserMedia = async (constraints: any) => {
|
|
45
|
+
if (constraints.audio) {
|
|
46
|
+
await AudioSession.setAppleAudioConfiguration({
|
|
47
|
+
audioCategory: 'playAndRecord',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return await getUserMediaFunc(constraints);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
34
56
|
function livekitRegisterGlobals() {
|
|
35
57
|
let lkGlobal: LiveKitReactNativeInfo = {
|
|
36
58
|
platform: Platform.OS,
|