@livekit/react-native 1.1.2 → 1.2.0
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 +44 -4
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/livekit/reactnative/LivekitReactNativeModule.kt +14 -0
- package/android/src/main/java/com/livekit/reactnative/audio/AudioManagerUtils.kt +44 -0
- package/android/src/main/java/com/livekit/reactnative/audio/AudioSwitchManager.java +24 -0
- package/lib/commonjs/audio/AudioSession.js +7 -0
- package/lib/commonjs/audio/AudioSession.js.map +1 -1
- package/lib/module/audio/AudioSession.js +7 -0
- package/lib/module/audio/AudioSession.js.map +1 -1
- package/lib/typescript/audio/AudioSession.d.ts +13 -4
- package/package.json +1 -1
- package/src/audio/AudioSession.ts +22 -4
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ This library depends on `@livekit/react-native-webrtc`, which has additional ins
|
|
|
29
29
|
- [iOS Installation Guide](https://github.com/livekit/react-native-webrtc/blob/master/Documentation/iOSInstallation.md)
|
|
30
30
|
- [Android Installation Guide](https://github.com/livekit/react-native-webrtc/blob/master/Documentation/AndroidInstallation.md)
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
---
|
|
33
33
|
|
|
34
34
|
Once the `@livekit/react-native-webrtc` dependency is installed, one last step is needed to finish the installation:
|
|
35
35
|
|
|
@@ -106,8 +106,12 @@ const [room] = useState(() => new Room());
|
|
|
106
106
|
const { participants } = useRoom(room);
|
|
107
107
|
|
|
108
108
|
useEffect(() => {
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
let connect = async () => {
|
|
110
|
+
await AudioSession.startAudioSession();
|
|
111
|
+
await room.connect(url, token, {});
|
|
112
|
+
console.log('connected to ', url, ' ', token);
|
|
113
|
+
};
|
|
114
|
+
connect();
|
|
111
115
|
return () => {
|
|
112
116
|
room.disconnect();
|
|
113
117
|
AudioSession.stopAudioSession();
|
|
@@ -126,6 +130,40 @@ const videoView = participants.length > 0 && (
|
|
|
126
130
|
|
|
127
131
|
Additional documentation for the LiveKit SDK can be found at https://docs.livekit.io/references/client-sdks/
|
|
128
132
|
|
|
133
|
+
## Audio sessions
|
|
134
|
+
|
|
135
|
+
As seen in the above example, we've introduced a new class `AudioSession` that helps
|
|
136
|
+
to manage the audio session on native platforms. This class wraps either [AudioManager](https://developer.android.com/reference/android/media/AudioManager) on Android, or [AVAudioSession](https://developer.apple.com/documentation/avfaudio/avaudiosession) on iOS.
|
|
137
|
+
|
|
138
|
+
You can customize the configuration of the audio session with `configureAudio`.
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
let connect = async () => {
|
|
143
|
+
// configure audio session prior to starting it.
|
|
144
|
+
await AudioSession.configureAudio({
|
|
145
|
+
android: {
|
|
146
|
+
preferredOutputList: ['earpiece'],
|
|
147
|
+
// See [AudioManager](https://developer.android.com/reference/android/media/AudioManager)
|
|
148
|
+
// for details on audio and focus modes.
|
|
149
|
+
audioMode: 'normal',
|
|
150
|
+
audioFocusMode: 'gain',
|
|
151
|
+
},
|
|
152
|
+
ios: {
|
|
153
|
+
defaultOutput: 'earpiece',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
await AudioSession.startAudioSession();
|
|
157
|
+
await room.connect(url, token, {});
|
|
158
|
+
};
|
|
159
|
+
connect();
|
|
160
|
+
return () => {
|
|
161
|
+
room.disconnect();
|
|
162
|
+
AudioSession.stopAudioSession();
|
|
163
|
+
};
|
|
164
|
+
}, [url, token, room]);
|
|
165
|
+
```
|
|
166
|
+
|
|
129
167
|
## Screenshare
|
|
130
168
|
|
|
131
169
|
Enabling screenshare requires extra installation steps:
|
|
@@ -196,10 +234,12 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
|
|
|
196
234
|
Apache License 2.0
|
|
197
235
|
|
|
198
236
|
<!--BEGIN_REPO_NAV-->
|
|
237
|
+
|
|
199
238
|
<br/><table>
|
|
239
|
+
|
|
200
240
|
<thead><tr><th colspan="2">LiveKit Ecosystem</th></tr></thead>
|
|
201
241
|
<tbody>
|
|
202
|
-
<tr><td>Client SDKs</td><td><a href="https://github.com/livekit/components-js">Components</a> · <a href="https://github.com/livekit/client-sdk-js">JavaScript</a> · <a href="https://github.com/livekit/client-sdk-
|
|
242
|
+
<tr><td>Client SDKs</td><td><a href="https://github.com/livekit/components-js">Components</a> · <a href="https://github.com/livekit/client-sdk-js">JavaScript</a> · <a href="https://github.com/livekit/client-sdk-swift">iOS/macOS</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/client-sdk-rust">Rust</a> · <a href="https://github.com/livekit/client-sdk-python">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>
|
|
203
243
|
<tr><td>Server SDKs</td><td><a href="https://github.com/livekit/server-sdk-js">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/agence104/livekit-server-sdk-php">PHP (community)</a> · <a href="https://github.com/tradablebits/livekit-server-sdk-python">Python (community)</a></td></tr><tr></tr>
|
|
204
244
|
<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></td></tr><tr></tr>
|
|
205
245
|
<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/oss/deployment">Self-hosting</a> · <a href="https://github.com/livekit/livekit-cli">CLI</a></td></tr>
|
package/android/build.gradle
CHANGED
|
@@ -129,8 +129,8 @@ dependencies {
|
|
|
129
129
|
// noinspection GradleDynamicVersion
|
|
130
130
|
api 'com.facebook.react:react-native:+'
|
|
131
131
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
132
|
-
api 'com.github.davidliu:audioswitch:
|
|
133
|
-
api 'io.github.webrtc-sdk:android:104.5112.
|
|
132
|
+
api 'com.github.davidliu:audioswitch:fb33b237aa50b3d1d2dea0e0695ecb7b38a98971'
|
|
133
|
+
api 'io.github.webrtc-sdk:android:104.5112.10'
|
|
134
134
|
implementation project(':livekit_react-native-webrtc')
|
|
135
135
|
implementation "androidx.annotation:annotation:1.4.0"
|
|
136
136
|
}
|
|
@@ -2,6 +2,7 @@ package com.livekit.reactnative
|
|
|
2
2
|
|
|
3
3
|
import com.facebook.react.bridge.*
|
|
4
4
|
import com.livekit.reactnative.audio.AudioDeviceKind
|
|
5
|
+
import com.livekit.reactnative.audio.AudioManagerUtils
|
|
5
6
|
import com.livekit.reactnative.audio.AudioSwitchManager
|
|
6
7
|
|
|
7
8
|
|
|
@@ -23,6 +24,19 @@ class LivekitReactNativeModule(reactContext: ReactApplicationContext) : ReactCon
|
|
|
23
24
|
}
|
|
24
25
|
audioManager.preferredDeviceList = preferredDeviceList
|
|
25
26
|
}
|
|
27
|
+
|
|
28
|
+
androidConfig.getString("audioMode")?.let { audioModeString ->
|
|
29
|
+
val audioMode = AudioManagerUtils.audioModeFromString(audioModeString)
|
|
30
|
+
if (audioMode != null) {
|
|
31
|
+
audioManager.setAudioMode(audioMode)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
androidConfig.getString("audioFocusMode")?.let { focusModeString ->
|
|
35
|
+
val focusMode = AudioManagerUtils.focusModeFromString(focusModeString)
|
|
36
|
+
if (focusMode != null) {
|
|
37
|
+
audioManager.setFocusMode(focusMode)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
26
40
|
}
|
|
27
41
|
|
|
28
42
|
@ReactMethod
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package com.livekit.reactnative.audio
|
|
2
|
+
|
|
3
|
+
import android.media.AudioManager
|
|
4
|
+
import android.util.Log
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
object AudioManagerUtils {
|
|
8
|
+
private const val TAG = "AudioManagerUtils"
|
|
9
|
+
|
|
10
|
+
fun audioModeFromString(audioModeString: String?): Int? {
|
|
11
|
+
if (audioModeString == null) {
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var audioMode: Int? = null
|
|
16
|
+
when (audioModeString) {
|
|
17
|
+
"normal" -> audioMode = AudioManager.MODE_NORMAL
|
|
18
|
+
"callScreening" -> audioMode = AudioManager.MODE_CALL_SCREENING
|
|
19
|
+
"inCall" -> audioMode = AudioManager.MODE_IN_CALL
|
|
20
|
+
"inCommunication" -> audioMode = AudioManager.MODE_IN_COMMUNICATION
|
|
21
|
+
"ringtone" -> audioMode = AudioManager.MODE_RINGTONE
|
|
22
|
+
else -> Log.w(TAG, "Unknown audio mode: $audioModeString")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return audioMode
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fun focusModeFromString(focusModeString: String?): Int? {
|
|
29
|
+
if (focusModeString == null) {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var focusMode: Int? = null
|
|
34
|
+
when (focusModeString) {
|
|
35
|
+
"gain" -> focusMode = AudioManager.AUDIOFOCUS_GAIN
|
|
36
|
+
"gainTransient" -> focusMode = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT
|
|
37
|
+
"gainTransientExclusive" -> focusMode = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE
|
|
38
|
+
"gainTransientMayDuck" -> focusMode = AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK
|
|
39
|
+
else -> Log.w(TAG, "Unknown audio focus mode: $focusModeString")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return focusMode
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -43,6 +43,20 @@ public class AudioSwitchManager {
|
|
|
43
43
|
@Nullable
|
|
44
44
|
private AudioSwitch audioSwitch;
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* The audio focus mode to use while started.
|
|
48
|
+
*
|
|
49
|
+
* Defaults to [AudioManager.AUDIOFOCUS_GAIN].
|
|
50
|
+
*/
|
|
51
|
+
private int focusMode = AudioManager.AUDIOFOCUS_GAIN;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The audio mode to use while started.
|
|
55
|
+
*
|
|
56
|
+
* Defaults to [AudioManager.MODE_NORMAL].
|
|
57
|
+
*/
|
|
58
|
+
private int audioMode = AudioManager.MODE_NORMAL;
|
|
59
|
+
|
|
46
60
|
public AudioSwitchManager(@NonNull Context context) {
|
|
47
61
|
this.context = context;
|
|
48
62
|
this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
|
@@ -64,6 +78,8 @@ public class AudioSwitchManager {
|
|
|
64
78
|
audioFocusChangeListener,
|
|
65
79
|
preferredDeviceList
|
|
66
80
|
);
|
|
81
|
+
audioSwitch.setFocusMode(focusMode);
|
|
82
|
+
audioSwitch.setAudioMode(audioMode);
|
|
67
83
|
audioSwitch.start(audioDeviceChangeListener);
|
|
68
84
|
audioSwitch.activate();
|
|
69
85
|
});
|
|
@@ -137,4 +153,12 @@ public class AudioSwitchManager {
|
|
|
137
153
|
selectAudioOutput(kind.audioDeviceClass);
|
|
138
154
|
}
|
|
139
155
|
}
|
|
156
|
+
|
|
157
|
+
public void setFocusMode(int focusMode) {
|
|
158
|
+
this.focusMode = focusMode;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
public void setAudioMode(int audioMode) {
|
|
162
|
+
this.audioMode = audioMode;
|
|
163
|
+
}
|
|
140
164
|
}
|
|
@@ -34,6 +34,13 @@ const LivekitReactNative = _reactNative.NativeModules.LivekitReactNative ? _reac
|
|
|
34
34
|
* 3. `"headset"`
|
|
35
35
|
* 4. `"bluetooth"`
|
|
36
36
|
*
|
|
37
|
+
* * audioMode - The audio mode to use for the audio session. Defaults to 'normal'.
|
|
38
|
+
*
|
|
39
|
+
* * audioFocusMode - The focus mode to use for the audio session. Defaults to 'gain'.
|
|
40
|
+
*
|
|
41
|
+
* See [AudioManager](https://developer.android.com/reference/android/media/AudioManager) for details
|
|
42
|
+
* on audio and focus modes.
|
|
43
|
+
*
|
|
37
44
|
* ----
|
|
38
45
|
* iOS
|
|
39
46
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["AudioSession.ts"],"names":["LINKING_ERROR","Platform","select","ios","default","LivekitReactNative","NativeModules","Proxy","get","Error","AudioSession","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker"],"mappings":";;;;;;;AAAA;;;;AACA,MAAMA,aAAa,GAChB,gFAAD,GACAC,sBAASC,MAAT,CAAgB;AAAEC,EAAAA,GAAG,EAAE,gCAAP;AAAyCC,EAAAA,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;AAMA,MAAMC,kBAAkB,GAAGC,2BAAcD,kBAAd,GACvBC,2BAAcD,kBADS,GAEvB,IAAIE,KAAJ,CACE,EADF,EAEE;AACEC,EAAAA,GAAG,GAAG;AACJ,UAAM,IAAIC,KAAJ,CAAUT,aAAV,CAAN;AACD;;AAHH,CAFF,CAFJ;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;
|
|
1
|
+
{"version":3,"sources":["AudioSession.ts"],"names":["LINKING_ERROR","Platform","select","ios","default","LivekitReactNative","NativeModules","Proxy","get","Error","AudioSession","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker"],"mappings":";;;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AAIT,sBAASc,EAAT,KAAgB,KAApB,EAA2B;AACzB,UAAMV,kBAAkB,CAACc,oBAAnB,EAAN;AACD;AACF,C","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. `\"speaker\"`\n * 2. `\"earpiece\"`\n * 3. `\"headset\"`\n * 4. `\"bluetooth\"`\n *\n * * audioMode - The audio mode to use for the audio session. Defaults to 'normal'.\n *\n * * audioFocusMode - The focus mode to use for the audio session. Defaults to 'gain'.\n *\n * See [AudioManager](https://developer.android.com/reference/android/media/AudioManager) for details\n * on audio and focus modes.\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 audioMode?:\n | 'normal'\n | 'callScreening'\n | 'inCall'\n | 'inCommunication'\n | 'ringtone';\n audioFocusMode?:\n | 'gain'\n | 'gainTransient'\n | 'gainTransientExclusive'\n | 'gainTransientMayDuck';\n };\n ios?: {\n defaultOutput?: 'speaker' | 'earpiece';\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 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 * Note: For applications targeting SDK versions over 30, the runtime BLUETOOTH_CONNECT\n * permission must be requested to send audio to bluetooth headsets.\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"]}
|
|
@@ -26,6 +26,13 @@ const LivekitReactNative = NativeModules.LivekitReactNative ? NativeModules.Live
|
|
|
26
26
|
* 3. `"headset"`
|
|
27
27
|
* 4. `"bluetooth"`
|
|
28
28
|
*
|
|
29
|
+
* * audioMode - The audio mode to use for the audio session. Defaults to 'normal'.
|
|
30
|
+
*
|
|
31
|
+
* * audioFocusMode - The focus mode to use for the audio session. Defaults to 'gain'.
|
|
32
|
+
*
|
|
33
|
+
* See [AudioManager](https://developer.android.com/reference/android/media/AudioManager) for details
|
|
34
|
+
* on audio and focus modes.
|
|
35
|
+
*
|
|
29
36
|
* ----
|
|
30
37
|
* iOS
|
|
31
38
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["AudioSession.ts"],"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","LivekitReactNative","Proxy","get","Error","AudioSession","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker"],"mappings":";;AAAA,SAASA,aAAT,EAAwBC,QAAxB,QAAwC,cAAxC;AACA,MAAMC,aAAa,GAChB,gFAAD,GACAD,QAAQ,CAACE,MAAT,CAAgB;AAAEC,EAAAA,GAAG,EAAE,gCAAP;AAAyCC,EAAAA,OAAO,EAAE;AAAlD,CAAhB,CADA,GAEA,sDAFA,GAGA,6CAJF;AAMA,MAAMC,kBAAkB,GAAGN,aAAa,CAACM,kBAAd,GACvBN,aAAa,CAACM,kBADS,GAEvB,IAAIC,KAAJ,CACE,EADF,EAEE;AACEC,EAAAA,GAAG,GAAG;AACJ,UAAM,IAAIC,KAAJ,CAAUP,aAAV,CAAN;AACD;;AAHH,CAFF,CAFJ;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;
|
|
1
|
+
{"version":3,"sources":["AudioSession.ts"],"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","LivekitReactNative","Proxy","get","Error","AudioSession","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker"],"mappings":";;AAAA,SAASA,aAAT,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AN;AACD,C;;gBAtEkBP,Y,0BA6EW,YAAY;AACxC,MAAIT,QAAQ,CAACc,EAAT,KAAgB,KAApB,EAA2B;AACzB,UAAMT,kBAAkB,CAACa,oBAAnB,EAAN;AACD;AACF,C","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. `\"speaker\"`\n * 2. `\"earpiece\"`\n * 3. `\"headset\"`\n * 4. `\"bluetooth\"`\n *\n * * audioMode - The audio mode to use for the audio session. Defaults to 'normal'.\n *\n * * audioFocusMode - The focus mode to use for the audio session. Defaults to 'gain'.\n *\n * See [AudioManager](https://developer.android.com/reference/android/media/AudioManager) for details\n * on audio and focus modes.\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 audioMode?:\n | 'normal'\n | 'callScreening'\n | 'inCall'\n | 'inCommunication'\n | 'ringtone';\n audioFocusMode?:\n | 'gain'\n | 'gainTransient'\n | 'gainTransientExclusive'\n | 'gainTransientMayDuck';\n };\n ios?: {\n defaultOutput?: 'speaker' | 'earpiece';\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 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 * Note: For applications targeting SDK versions over 30, the runtime BLUETOOTH_CONNECT\n * permission must be requested to send audio to bluetooth headsets.\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"]}
|
|
@@ -13,6 +13,13 @@
|
|
|
13
13
|
* 3. `"headset"`
|
|
14
14
|
* 4. `"bluetooth"`
|
|
15
15
|
*
|
|
16
|
+
* * audioMode - The audio mode to use for the audio session. Defaults to 'normal'.
|
|
17
|
+
*
|
|
18
|
+
* * audioFocusMode - The focus mode to use for the audio session. Defaults to 'gain'.
|
|
19
|
+
*
|
|
20
|
+
* See [AudioManager](https://developer.android.com/reference/android/media/AudioManager) for details
|
|
21
|
+
* on audio and focus modes.
|
|
22
|
+
*
|
|
16
23
|
* ----
|
|
17
24
|
* iOS
|
|
18
25
|
*
|
|
@@ -21,11 +28,13 @@
|
|
|
21
28
|
* By default, this is set to `"speaker"`
|
|
22
29
|
*/
|
|
23
30
|
export declare type AudioConfiguration = {
|
|
24
|
-
android
|
|
25
|
-
preferredOutputList
|
|
31
|
+
android?: {
|
|
32
|
+
preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];
|
|
33
|
+
audioMode?: 'normal' | 'callScreening' | 'inCall' | 'inCommunication' | 'ringtone';
|
|
34
|
+
audioFocusMode?: 'gain' | 'gainTransient' | 'gainTransientExclusive' | 'gainTransientMayDuck';
|
|
26
35
|
};
|
|
27
|
-
ios
|
|
28
|
-
defaultOutput
|
|
36
|
+
ios?: {
|
|
37
|
+
defaultOutput?: 'speaker' | 'earpiece';
|
|
29
38
|
};
|
|
30
39
|
};
|
|
31
40
|
export default class AudioSession {
|
package/package.json
CHANGED
|
@@ -31,6 +31,13 @@ const LivekitReactNative = NativeModules.LivekitReactNative
|
|
|
31
31
|
* 3. `"headset"`
|
|
32
32
|
* 4. `"bluetooth"`
|
|
33
33
|
*
|
|
34
|
+
* * audioMode - The audio mode to use for the audio session. Defaults to 'normal'.
|
|
35
|
+
*
|
|
36
|
+
* * audioFocusMode - The focus mode to use for the audio session. Defaults to 'gain'.
|
|
37
|
+
*
|
|
38
|
+
* See [AudioManager](https://developer.android.com/reference/android/media/AudioManager) for details
|
|
39
|
+
* on audio and focus modes.
|
|
40
|
+
*
|
|
34
41
|
* ----
|
|
35
42
|
* iOS
|
|
36
43
|
*
|
|
@@ -39,11 +46,22 @@ const LivekitReactNative = NativeModules.LivekitReactNative
|
|
|
39
46
|
* By default, this is set to `"speaker"`
|
|
40
47
|
*/
|
|
41
48
|
export type AudioConfiguration = {
|
|
42
|
-
android
|
|
43
|
-
preferredOutputList
|
|
49
|
+
android?: {
|
|
50
|
+
preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];
|
|
51
|
+
audioMode?:
|
|
52
|
+
| 'normal'
|
|
53
|
+
| 'callScreening'
|
|
54
|
+
| 'inCall'
|
|
55
|
+
| 'inCommunication'
|
|
56
|
+
| 'ringtone';
|
|
57
|
+
audioFocusMode?:
|
|
58
|
+
| 'gain'
|
|
59
|
+
| 'gainTransient'
|
|
60
|
+
| 'gainTransientExclusive'
|
|
61
|
+
| 'gainTransientMayDuck';
|
|
44
62
|
};
|
|
45
|
-
ios
|
|
46
|
-
defaultOutput
|
|
63
|
+
ios?: {
|
|
64
|
+
defaultOutput?: 'speaker' | 'earpiece';
|
|
47
65
|
};
|
|
48
66
|
};
|
|
49
67
|
|