@livekit/react-native 1.2.0 → 1.4.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 +53 -10
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/livekit/reactnative/LiveKitReactNative.kt +21 -2
- package/android/src/main/java/com/livekit/reactnative/LivekitReactNativeModule.kt +63 -14
- package/android/src/main/java/com/livekit/reactnative/audio/AudioManagerUtils.kt +72 -0
- package/android/src/main/java/com/livekit/reactnative/audio/AudioSwitchManager.java +108 -6
- package/android/src/main/java/com/livekit/reactnative/audio/AudioType.kt +46 -0
- package/android/src/main/java/com/livekit/reactnative/video/SimulcastVideoEncoderFactoryWrapper.kt +2 -1
- package/ios/AudioUtils.h +9 -0
- package/ios/AudioUtils.m +48 -0
- package/ios/LivekitReactNative.m +45 -0
- package/ios/LivekitReactNative.xcodeproj/project.xcworkspace/xcuserdata/davidliu.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/audio/AudioManager.js +108 -0
- package/lib/commonjs/audio/AudioManager.js.map +1 -0
- package/lib/commonjs/audio/AudioSession.js +59 -10
- package/lib/commonjs/audio/AudioSession.js.map +1 -1
- package/lib/commonjs/index.js +105 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/logger.js +32 -0
- package/lib/commonjs/logger.js.map +1 -0
- package/lib/module/audio/AudioManager.js +92 -0
- package/lib/module/audio/AudioManager.js.map +1 -0
- package/lib/module/audio/AudioSession.js +54 -9
- package/lib/module/audio/AudioSession.js.map +1 -1
- package/lib/module/index.js +19 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/logger.js +18 -0
- package/lib/module/logger.js.map +1 -0
- package/lib/typescript/audio/AudioManager.d.ts +11 -0
- package/lib/typescript/audio/AudioSession.d.ts +85 -14
- package/lib/typescript/index.d.ts +6 -2
- package/lib/typescript/logger.d.ts +13 -0
- package/package.json +9 -5
- package/src/audio/AudioManager.ts +119 -0
- package/src/audio/AudioSession.ts +206 -23
- package/src/index.tsx +41 -2
- package/src/logger.ts +23 -0
|
@@ -21,17 +21,15 @@ const LivekitReactNative = NativeModules.LivekitReactNative ? NativeModules.Live
|
|
|
21
21
|
* This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.
|
|
22
22
|
*
|
|
23
23
|
* By default, the order is set to:
|
|
24
|
-
* 1. `"
|
|
25
|
-
* 2. `"
|
|
26
|
-
* 3. `"
|
|
27
|
-
* 4. `"
|
|
24
|
+
* 1. `"bluetooth"
|
|
25
|
+
* 2. `"headset"``
|
|
26
|
+
* 3. `"speaker"`
|
|
27
|
+
* 4. `"earpiece"`
|
|
28
28
|
*
|
|
29
|
-
* *
|
|
29
|
+
* * audioTypeOptions - An {@link AndroidAudioTypeOptions} object which provides the
|
|
30
|
+
* audio options to use on Android.
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* See [AudioManager](https://developer.android.com/reference/android/media/AudioManager) for details
|
|
34
|
-
* on audio and focus modes.
|
|
32
|
+
* See {@link AndroidAudioTypePresets} for pre-configured values.
|
|
35
33
|
*
|
|
36
34
|
* ----
|
|
37
35
|
* iOS
|
|
@@ -41,6 +39,47 @@ const LivekitReactNative = NativeModules.LivekitReactNative ? NativeModules.Live
|
|
|
41
39
|
* By default, this is set to `"speaker"`
|
|
42
40
|
*/
|
|
43
41
|
|
|
42
|
+
export const AndroidAudioTypePresets = {
|
|
43
|
+
communication: {
|
|
44
|
+
manageAudioFocus: true,
|
|
45
|
+
audioMode: 'inCommunication',
|
|
46
|
+
audioFocusMode: 'gain',
|
|
47
|
+
audioStreamType: 'voiceCall',
|
|
48
|
+
audioAttributesUsageType: 'voiceCommunication',
|
|
49
|
+
audioAttributesContentType: 'speech'
|
|
50
|
+
},
|
|
51
|
+
media: {
|
|
52
|
+
manageAudioFocus: true,
|
|
53
|
+
audioMode: 'normal',
|
|
54
|
+
audioFocusMode: 'gain',
|
|
55
|
+
audioStreamType: 'music',
|
|
56
|
+
audioAttributesUsageType: 'media',
|
|
57
|
+
audioAttributesContentType: 'unknown'
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
export function getDefaultAppleAudioConfigurationForMode(mode) {
|
|
61
|
+
let preferSpeakerOutput = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
62
|
+
|
|
63
|
+
if (mode === 'remoteOnly') {
|
|
64
|
+
return {
|
|
65
|
+
audioCategory: 'playback',
|
|
66
|
+
audioCategoryOptions: ['mixWithOthers'],
|
|
67
|
+
audioMode: 'spokenAudio'
|
|
68
|
+
};
|
|
69
|
+
} else if (mode === 'localAndRemote' || mode === 'localOnly') {
|
|
70
|
+
return {
|
|
71
|
+
audioCategory: 'playAndRecord',
|
|
72
|
+
audioCategoryOptions: ['allowBluetooth', 'mixWithOthers'],
|
|
73
|
+
audioMode: preferSpeakerOutput ? 'videoChat' : 'voiceChat'
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
audioCategory: 'soloAmbient',
|
|
79
|
+
audioCategoryOptions: [],
|
|
80
|
+
audioMode: 'default'
|
|
81
|
+
};
|
|
82
|
+
}
|
|
44
83
|
export default class AudioSession {}
|
|
45
84
|
|
|
46
85
|
_defineProperty(AudioSession, "configureAudio", async config => {
|
|
@@ -74,4 +113,10 @@ _defineProperty(AudioSession, "showAudioRoutePicker", async () => {
|
|
|
74
113
|
await LivekitReactNative.showAudioRoutePicker();
|
|
75
114
|
}
|
|
76
115
|
});
|
|
116
|
+
|
|
117
|
+
_defineProperty(AudioSession, "setAppleAudioConfiguration", async config => {
|
|
118
|
+
if (Platform.OS === 'ios') {
|
|
119
|
+
await LivekitReactNative.setAppleAudioConfiguration(config);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
77
122
|
//# sourceMappingURL=AudioSession.js.map
|
|
@@ -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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqBA,eAAe,MAAMQ,YAAN,CAAmB;;gBAAbA,Y,oBAMK,MAAOC,MAAP,IAAsC;AAC5D,QAAML,kBAAkB,CAACM,cAAnB,CAAkCD,MAAlC,CAAN;AACD,C;;gBARkBD,Y,uBAaQ,YAAY;AACrC,QAAMJ,kBAAkB,CAACO,iBAAnB,EAAN;AACD,C;;gBAfkBH,Y,sBAoBO,YAAY;AACpC,QAAMJ,kBAAkB,CAACQ,gBAAnB,EAAN;AACD,C;;gBAtBkBJ,Y,qBAmDM,YAA+B;AACtD,MAAIT,QAAQ,CAACc,EAAT,KAAgB,KAApB,EAA2B;AACzB,WAAO,CAAC,SAAD,EAAY,eAAZ,CAAP;AACD,GAFD,MAEO,IAAId,QAAQ,CAACc,EAAT,KAAgB,SAApB,EAA+B;AACpC,WAAQ,MAAMT,kBAAkB,CAACU,eAAnB,EAAd;AACD,GAFM,MAEA;AACL,WAAO,EAAP;AACD;AACF,C;;gBA3DkBN,Y,uBAoEQ,MAAOO,QAAP,IAA4B;AACrD,QAAMX,kBAAkB,CAACY,iBAAnB,CAAqCD,QAArC,CAAN;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"]}
|
|
1
|
+
{"version":3,"sources":["AudioSession.ts"],"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","config","configureAudio","startAudioSession","stopAudioSession","OS","getAudioOutputs","deviceId","selectAudioOutput","showAudioRoutePicker","setAppleAudioConfiguration"],"mappings":"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","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 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"]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { registerGlobals as webrtcRegisterGlobals } from '@livekit/react-native-webrtc';
|
|
2
2
|
import { setupURLPolyfill } from 'react-native-url-polyfill';
|
|
3
|
-
import
|
|
3
|
+
import 'fastestsmallesttextencoderdecoder';
|
|
4
|
+
import AudioSession, { AndroidAudioTypePresets, AndroidAudioTypeOptions, AppleAudioCategory, AppleAudioCategoryOption, AppleAudioConfiguration, AppleAudioMode, AudioTrackState, getDefaultAppleAudioConfigurationForMode } from './audio/AudioSession';
|
|
4
5
|
import { PixelRatio, Platform } from 'react-native';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -15,6 +16,8 @@ export function registerGlobals() {
|
|
|
15
16
|
fixWebrtcAdapter();
|
|
16
17
|
shimPromiseAllSettled();
|
|
17
18
|
shimArrayAt();
|
|
19
|
+
shimAsyncIterator();
|
|
20
|
+
shimIterator();
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
function livekitRegisterGlobals() {
|
|
@@ -59,8 +62,22 @@ function shimArrayAt() {
|
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
function shimAsyncIterator() {
|
|
66
|
+
var shim = require('well-known-symbols/Symbol.asyncIterator/shim');
|
|
67
|
+
|
|
68
|
+
shim();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function shimIterator() {
|
|
72
|
+
var shim = require('well-known-symbols/Symbol.iterator/shim');
|
|
73
|
+
|
|
74
|
+
shim();
|
|
75
|
+
}
|
|
76
|
+
|
|
62
77
|
export * from './components/VideoView';
|
|
63
78
|
export * from './useParticipant';
|
|
64
79
|
export * from './useRoom';
|
|
65
|
-
export
|
|
80
|
+
export * from './logger';
|
|
81
|
+
export * from './audio/AudioManager';
|
|
82
|
+
export { AudioSession, AndroidAudioTypeOptions, AndroidAudioTypePresets, AppleAudioCategory, AppleAudioCategoryOption, AppleAudioConfiguration, AppleAudioMode, AudioTrackState, getDefaultAppleAudioConfigurationForMode };
|
|
66
83
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["registerGlobals","webrtcRegisterGlobals","setupURLPolyfill","AudioSession","PixelRatio","Platform","livekitRegisterGlobals","fixWebrtcAdapter","shimPromiseAllSettled","shimArrayAt","lkGlobal","platform","OS","devicePixelRatio","get","global","LiveKitReactNativeGlobal","window","navigator","undefined","userAgent","product","allSettled","require","shim","Array","prototype","at"],"mappings":"AAAA,SAASA,eAAe,IAAIC,qBAA5B,QAAyD,8BAAzD;AACA,SAASC,gBAAT,QAAiC,2BAAjC;AACA,OAAOC,YAAP,
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["registerGlobals","webrtcRegisterGlobals","setupURLPolyfill","AudioSession","AndroidAudioTypePresets","AndroidAudioTypeOptions","AppleAudioCategory","AppleAudioCategoryOption","AppleAudioConfiguration","AppleAudioMode","AudioTrackState","getDefaultAppleAudioConfigurationForMode","PixelRatio","Platform","livekitRegisterGlobals","fixWebrtcAdapter","shimPromiseAllSettled","shimArrayAt","shimAsyncIterator","shimIterator","lkGlobal","platform","OS","devicePixelRatio","get","global","LiveKitReactNativeGlobal","window","navigator","undefined","userAgent","product","allSettled","require","shim","Array","prototype","at"],"mappings":"AAAA,SAASA,eAAe,IAAIC,qBAA5B,QAAyD,8BAAzD;AACA,SAASC,gBAAT,QAAiC,2BAAjC;AACA,OAAO,mCAAP;AACA,OAAOC,YAAP,IACEC,uBADF,EAEEC,uBAFF,EAGEC,kBAHF,EAIEC,wBAJF,EAKEC,uBALF,EAMEC,cANF,EAOEC,eAPF,EAQEC,wCARF,QASO,sBATP;AAWA,SAASC,UAAT,EAAqBC,QAArB,QAAqC,cAArC;;AAIA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASb,eAAT,GAA2B;AAChCC,EAAAA,qBAAqB;AACrBa,EAAAA,sBAAsB;AACtBZ,EAAAA,gBAAgB;AAChBa,EAAAA,gBAAgB;AAChBC,EAAAA,qBAAqB;AACrBC,EAAAA,WAAW;AACXC,EAAAA,iBAAiB;AACjBC,EAAAA,YAAY;AACb;;AACD,SAASL,sBAAT,GAAkC;AAChC,MAAIM,QAAgC,GAAG;AACrCC,IAAAA,QAAQ,EAAER,QAAQ,CAACS,EADkB;AAErCC,IAAAA,gBAAgB,EAAEX,UAAU,CAACY,GAAX;AAFmB,GAAvC,CADgC,CAMhC;;AACAC,EAAAA,MAAM,CAACC,wBAAP,GAAkCN,QAAlC;AACD;;AAED,SAASL,gBAAT,GAA4B;AAAA;;AAC1B;AACA,MAAI,YAAAY,MAAM,UAAN,0CAAQC,SAAR,MAAsBC,SAA1B,EAAqC;AACnC;AACA,UAAM;AAAED,MAAAA;AAAF,QAAgBD,MAAtB;;AACA,QAAIC,SAAS,CAACE,SAAV,KAAwBD,SAA5B,EAAuC;AAAA;;AACrCD,MAAAA,SAAS,CAACE,SAAV,yBAAsBF,SAAS,CAACG,OAAhC,mEAA2C,SAA3C;AACD;AACF;AACF;;AAED,SAASf,qBAAT,GAAiC;AAC/B,MAAIgB,UAAU,GAAGC,OAAO,CAAC,oBAAD,CAAxB;;AACAD,EAAAA,UAAU,CAACE,IAAX;AACD;;AAED,SAASjB,WAAT,GAAuB;AACrB;AACA,MAAI,CAACkB,KAAK,CAACC,SAAN,CAAgBC,EAArB,EAAyB;AACvB,QAAIA,EAAE,GAAGJ,OAAO,CAAC,oBAAD,CAAhB;;AACAI,IAAAA,EAAE,CAACH,IAAH;AACD;AACF;;AAED,SAAShB,iBAAT,GAA6B;AAC3B,MAAIgB,IAAI,GAAGD,OAAO,CAAC,8CAAD,CAAlB;;AACAC,EAAAA,IAAI;AACL;;AAED,SAASf,YAAT,GAAwB;AACtB,MAAIe,IAAI,GAAGD,OAAO,CAAC,yCAAD,CAAlB;;AACAC,EAAAA,IAAI;AACL;;AAED,cAAc,wBAAd;AACA,cAAc,kBAAd;AACA,cAAc,WAAd;AACA,cAAc,UAAd;AACA,cAAc,sBAAd;AAEA,SACE/B,YADF,EAGEE,uBAHF,EAIED,uBAJF,EAKEE,kBALF,EAMEC,wBANF,EAOEC,uBAPF,EAQEC,cARF,EASEC,eATF,EAUEC,wCAVF","sourcesContent":["import { registerGlobals as webrtcRegisterGlobals } from '@livekit/react-native-webrtc';\nimport { setupURLPolyfill } from 'react-native-url-polyfill';\nimport 'fastestsmallesttextencoderdecoder';\nimport AudioSession, {\n AndroidAudioTypePresets,\n AndroidAudioTypeOptions,\n AppleAudioCategory,\n AppleAudioCategoryOption,\n AppleAudioConfiguration,\n AppleAudioMode,\n 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}\n\nexport * from './components/VideoView';\nexport * from './useParticipant';\nexport * from './useRoom';\nexport * from './logger';\nexport * from './audio/AudioManager';\n\nexport {\n AudioSession,\n AudioConfiguration,\n AndroidAudioTypeOptions,\n AndroidAudioTypePresets,\n AppleAudioCategory,\n AppleAudioCategoryOption,\n AppleAudioConfiguration,\n AppleAudioMode,\n AudioTrackState,\n getDefaultAppleAudioConfigurationForMode,\n LogLevel,\n SetLogLevelOptions,\n};\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { setLogLevel as setClientSdkLogLevel } from 'livekit-client';
|
|
2
|
+
import loglevel from 'loglevel';
|
|
3
|
+
export const log = loglevel.getLogger('lk-react-native');
|
|
4
|
+
log.setDefaultLevel('WARN');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Set the log level for both the `@livekit/react-native` package and the `@livekit-client` package.
|
|
8
|
+
* To set the `@livekit-client` log independently, use the `liveKitClientLogLevel` prop on the `options` object.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export function setLogLevel(level) {
|
|
12
|
+
var _options$liveKitClien;
|
|
13
|
+
|
|
14
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
|
+
log.setLevel(level);
|
|
16
|
+
setClientSdkLogLevel((_options$liveKitClien = options.liveKitClientLogLevel) !== null && _options$liveKitClien !== void 0 ? _options$liveKitClien : level);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["logger.ts"],"names":["setLogLevel","setClientSdkLogLevel","loglevel","log","getLogger","setDefaultLevel","level","options","setLevel","liveKitClientLogLevel"],"mappings":"AAAA,SAASA,WAAW,IAAIC,oBAAxB,QAAoD,gBAApD;AACA,OAAOC,QAAP,MAAqB,UAArB;AAEA,OAAO,MAAMC,GAAG,GAAGD,QAAQ,CAACE,SAAT,CAAmB,iBAAnB,CAAZ;AACPD,GAAG,CAACE,eAAJ,CAAoB,MAApB;;AAOA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASL,WAAT,CACLM,KADK,EAGC;AAAA;;AAAA,MADNC,OACM,uEADwB,EACxB;AACNJ,EAAAA,GAAG,CAACK,QAAJ,CAAaF,KAAb;AACAL,EAAAA,oBAAoB,0BAACM,OAAO,CAACE,qBAAT,yEAAkCH,KAAlC,CAApB;AACD","sourcesContent":["import { setLogLevel as setClientSdkLogLevel } from 'livekit-client';\nimport loglevel from 'loglevel';\n\nexport const log = loglevel.getLogger('lk-react-native');\nlog.setDefaultLevel('WARN');\n\nexport type LogLevel = Parameters<typeof setClientSdkLogLevel>[0];\nexport type SetLogLevelOptions = {\n liveKitClientLogLevel?: LogLevel;\n};\n\n/**\n * Set the log level for both the `@livekit/react-native` package and the `@livekit-client` package.\n * To set the `@livekit-client` log independently, use the `liveKitClientLogLevel` prop on the `options` object.\n * @public\n */\nexport function setLogLevel(\n level: LogLevel,\n options: SetLogLevelOptions = {}\n): void {\n log.setLevel(level);\n setClientSdkLogLevel(options.liveKitClientLogLevel ?? level);\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Room } from 'livekit-client';
|
|
2
|
+
import { type AppleAudioConfiguration, type AudioTrackState } from './AudioSession';
|
|
3
|
+
/**
|
|
4
|
+
* Handles setting the appropriate AVAudioSession options automatically
|
|
5
|
+
* depending on the audio track states of the Room.
|
|
6
|
+
*
|
|
7
|
+
* @param room
|
|
8
|
+
* @param preferSpeakerOutput
|
|
9
|
+
* @param onConfigureNativeAudio
|
|
10
|
+
*/
|
|
11
|
+
export declare function useIOSAudioManagement(room: Room, preferSpeakerOutput?: boolean, onConfigureNativeAudio?: (trackState: AudioTrackState, preferSpeakerOutput: boolean) => AppleAudioConfiguration): void;
|
|
@@ -8,17 +8,15 @@
|
|
|
8
8
|
* This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.
|
|
9
9
|
*
|
|
10
10
|
* By default, the order is set to:
|
|
11
|
-
* 1. `"
|
|
12
|
-
* 2. `"
|
|
13
|
-
* 3. `"
|
|
14
|
-
* 4. `"
|
|
11
|
+
* 1. `"bluetooth"
|
|
12
|
+
* 2. `"headset"``
|
|
13
|
+
* 3. `"speaker"`
|
|
14
|
+
* 4. `"earpiece"`
|
|
15
15
|
*
|
|
16
|
-
* *
|
|
16
|
+
* * audioTypeOptions - An {@link AndroidAudioTypeOptions} object which provides the
|
|
17
|
+
* audio options to use on Android.
|
|
17
18
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* See [AudioManager](https://developer.android.com/reference/android/media/AudioManager) for details
|
|
21
|
-
* on audio and focus modes.
|
|
19
|
+
* See {@link AndroidAudioTypePresets} for pre-configured values.
|
|
22
20
|
*
|
|
23
21
|
* ----
|
|
24
22
|
* iOS
|
|
@@ -30,13 +28,88 @@
|
|
|
30
28
|
export declare type AudioConfiguration = {
|
|
31
29
|
android?: {
|
|
32
30
|
preferredOutputList?: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];
|
|
33
|
-
|
|
34
|
-
audioFocusMode?: 'gain' | 'gainTransient' | 'gainTransientExclusive' | 'gainTransientMayDuck';
|
|
31
|
+
audioTypeOptions: AndroidAudioTypeOptions;
|
|
35
32
|
};
|
|
36
33
|
ios?: {
|
|
37
34
|
defaultOutput?: 'speaker' | 'earpiece';
|
|
38
35
|
};
|
|
39
36
|
};
|
|
37
|
+
export declare type AndroidAudioTypeOptions = {
|
|
38
|
+
/**
|
|
39
|
+
* Whether LiveKit should handle managing the audio focus or not.
|
|
40
|
+
*
|
|
41
|
+
* Defaults to true.
|
|
42
|
+
*/
|
|
43
|
+
manageAudioFocus?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Corresponds to {@link https://developer.android.com/reference/android/media/AudioManager#setMode(int)}
|
|
46
|
+
*
|
|
47
|
+
* Defaults to 'inCommunication'.
|
|
48
|
+
*/
|
|
49
|
+
audioMode?: 'normal' | 'callScreening' | 'inCall' | 'inCommunication' | 'ringtone';
|
|
50
|
+
/**
|
|
51
|
+
* Corresponds to the duration hint when requesting audio focus.
|
|
52
|
+
*
|
|
53
|
+
* Defaults to 'gain'.
|
|
54
|
+
*
|
|
55
|
+
* See also {@link https://developer.android.com/reference/android/media/AudioManager#AUDIOFOCUS_GAIN}
|
|
56
|
+
*/
|
|
57
|
+
audioFocusMode?: 'gain' | 'gainTransient' | 'gainTransientExclusive' | 'gainTransientMayDuck';
|
|
58
|
+
/**
|
|
59
|
+
* Corresponds to Android's AudioAttributes usage type.
|
|
60
|
+
*
|
|
61
|
+
* Defaults to 'voiceCommunication'.
|
|
62
|
+
*
|
|
63
|
+
* See also {@link https://developer.android.com/reference/android/media/AudioAttributes}
|
|
64
|
+
*/
|
|
65
|
+
audioAttributesUsageType?: 'alarm' | 'assistanceAccessibility' | 'assistanceNavigationGuidance' | 'assistanceSonification' | 'assistant' | 'game' | 'media' | 'notification' | 'notificationEvent' | 'notificationRingtone' | 'unknown' | 'voiceCommunication' | 'voiceCommunicationSignalling';
|
|
66
|
+
/**
|
|
67
|
+
* Corresponds to Android's AndroidAttributes content type.
|
|
68
|
+
*
|
|
69
|
+
* Defaults to 'speech'.
|
|
70
|
+
*
|
|
71
|
+
* See also {@link https://developer.android.com/reference/android/media/AudioAttributes}
|
|
72
|
+
*/
|
|
73
|
+
audioAttributesContentType?: 'movie' | 'music' | 'sonification' | 'speech' | 'unknown';
|
|
74
|
+
/**
|
|
75
|
+
* Corresponds to the stream type when requesting audio focus. Used on pre-O devices.
|
|
76
|
+
*
|
|
77
|
+
* Defaults to 'voiceCall'
|
|
78
|
+
*
|
|
79
|
+
* See also {@link https://developer.android.com/reference/android/media/AudioManager#STREAM_VOICE_CALL}
|
|
80
|
+
*/
|
|
81
|
+
audioStreamType?: 'accessibility' | 'alarm' | 'dtmf' | 'music' | 'notification' | 'ring' | 'system' | 'voiceCall';
|
|
82
|
+
/**
|
|
83
|
+
* On certain Android devices, audio routing does not function properly and
|
|
84
|
+
* bluetooth microphones will not work unless audio mode is set to
|
|
85
|
+
* `inCommunication` or `inCall`. Audio routing is turned off those cases.
|
|
86
|
+
*
|
|
87
|
+
* If this set to true, will attempt to do audio routing regardless of audio mode.
|
|
88
|
+
*
|
|
89
|
+
* Defaults to false.
|
|
90
|
+
*/
|
|
91
|
+
forceHandleAudioRouting?: boolean;
|
|
92
|
+
};
|
|
93
|
+
export declare const AndroidAudioTypePresets: {
|
|
94
|
+
/**
|
|
95
|
+
* A pre-configured AndroidAudioConfiguration for voice communication.
|
|
96
|
+
*/
|
|
97
|
+
communication: AndroidAudioTypeOptions;
|
|
98
|
+
/**
|
|
99
|
+
* A pre-configured AndroidAudioConfiguration for media playback.
|
|
100
|
+
*/
|
|
101
|
+
media: AndroidAudioTypeOptions;
|
|
102
|
+
};
|
|
103
|
+
export declare type AppleAudioMode = 'default' | 'gameChat' | 'measurement' | 'moviePlayback' | 'spokenAudio' | 'videoChat' | 'videoRecording' | 'voiceChat' | 'voicePrompt';
|
|
104
|
+
export declare type AppleAudioCategory = 'soloAmbient' | 'playback' | 'record' | 'playAndRecord' | 'multiRoute';
|
|
105
|
+
export declare type AppleAudioCategoryOption = 'mixWithOthers' | 'duckOthers' | 'interruptSpokenAudioAndMixWithOthers' | 'allowBluetooth' | 'allowBluetoothA2DP' | 'allowAirPlay' | 'defaultToSpeaker';
|
|
106
|
+
export declare type AppleAudioConfiguration = {
|
|
107
|
+
audioCategory?: AppleAudioCategory;
|
|
108
|
+
audioCategoryOptions?: AppleAudioCategoryOption[];
|
|
109
|
+
audioMode?: AppleAudioMode;
|
|
110
|
+
};
|
|
111
|
+
export declare type AudioTrackState = 'none' | 'remoteOnly' | 'localOnly' | 'localAndRemote';
|
|
112
|
+
export declare function getDefaultAppleAudioConfigurationForMode(mode: AudioTrackState, preferSpeakerOutput?: boolean): AppleAudioConfiguration;
|
|
40
113
|
export default class AudioSession {
|
|
41
114
|
/**
|
|
42
115
|
* Applies the provided audio configuration to the underlying AudioSession.
|
|
@@ -63,9 +136,6 @@ export default class AudioSession {
|
|
|
63
136
|
* * "headset"
|
|
64
137
|
* * "bluetooth"
|
|
65
138
|
*
|
|
66
|
-
* Note: For applications targeting SDK versions over 30, the runtime BLUETOOTH_CONNECT
|
|
67
|
-
* permission must be requested to send audio to bluetooth headsets.
|
|
68
|
-
*
|
|
69
139
|
* ----
|
|
70
140
|
*
|
|
71
141
|
* For iOS, due to OS limitations, the only available types are:
|
|
@@ -94,4 +164,5 @@ export default class AudioSession {
|
|
|
94
164
|
* Displays an AVRoutePickerView for the user to choose their audio output.
|
|
95
165
|
*/
|
|
96
166
|
static showAudioRoutePicker: () => Promise<void>;
|
|
167
|
+
static setAppleAudioConfiguration: (config: AppleAudioConfiguration) => Promise<void>;
|
|
97
168
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'fastestsmallesttextencoderdecoder';
|
|
2
|
+
import AudioSession, { AndroidAudioTypePresets, AndroidAudioTypeOptions, AppleAudioCategory, AppleAudioCategoryOption, AppleAudioConfiguration, AppleAudioMode, AudioTrackState, getDefaultAppleAudioConfigurationForMode } from './audio/AudioSession';
|
|
2
3
|
import type { AudioConfiguration } from './audio/AudioSession';
|
|
4
|
+
import type { LogLevel, SetLogLevelOptions } from './logger';
|
|
3
5
|
/**
|
|
4
6
|
* Registers the required globals needed for LiveKit to work.
|
|
5
7
|
*
|
|
@@ -9,4 +11,6 @@ export declare function registerGlobals(): void;
|
|
|
9
11
|
export * from './components/VideoView';
|
|
10
12
|
export * from './useParticipant';
|
|
11
13
|
export * from './useRoom';
|
|
12
|
-
export
|
|
14
|
+
export * from './logger';
|
|
15
|
+
export * from './audio/AudioManager';
|
|
16
|
+
export { AudioSession, AudioConfiguration, AndroidAudioTypeOptions, AndroidAudioTypePresets, AppleAudioCategory, AppleAudioCategoryOption, AppleAudioConfiguration, AppleAudioMode, AudioTrackState, getDefaultAppleAudioConfigurationForMode, LogLevel, SetLogLevelOptions, };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { setLogLevel as setClientSdkLogLevel } from 'livekit-client';
|
|
2
|
+
import loglevel from 'loglevel';
|
|
3
|
+
export declare const log: loglevel.Logger;
|
|
4
|
+
export declare type LogLevel = Parameters<typeof setClientSdkLogLevel>[0];
|
|
5
|
+
export declare type SetLogLevelOptions = {
|
|
6
|
+
liveKitClientLogLevel?: LogLevel;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Set the log level for both the `@livekit/react-native` package and the `@livekit-client` package.
|
|
10
|
+
* To set the `@livekit-client` log independently, use the `liveKitClientLogLevel` prop on the `options` object.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export declare function setLogLevel(level: LogLevel, options?: SetLogLevelOptions): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livekit/react-native",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "LiveKit for React Native",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -43,19 +43,23 @@
|
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"array.prototype.at": "^1.1.1",
|
|
46
|
-
"
|
|
46
|
+
"fastestsmallesttextencoderdecoder": "^1.0.22",
|
|
47
|
+
"livekit-client": "^1.15.0",
|
|
48
|
+
"loglevel": "^1.8.0",
|
|
47
49
|
"promise.allsettled": "^1.0.5",
|
|
48
|
-
"react-native-url-polyfill": "^1.3.0"
|
|
50
|
+
"react-native-url-polyfill": "^1.3.0",
|
|
51
|
+
"well-known-symbols": "^4.0.0"
|
|
49
52
|
},
|
|
50
53
|
"devDependencies": {
|
|
51
54
|
"@babel/core": "^7.20.0",
|
|
52
55
|
"@babel/preset-env": "^7.20.0",
|
|
53
56
|
"@babel/runtime": "^7.20.0",
|
|
54
57
|
"@commitlint/config-conventional": "^16.2.1",
|
|
55
|
-
"@livekit/react-native-webrtc": "^
|
|
58
|
+
"@livekit/react-native-webrtc": "^114.0.0",
|
|
56
59
|
"@react-native-community/eslint-config": "^3.2.0",
|
|
57
60
|
"@release-it/conventional-changelog": "^4.2.0",
|
|
58
61
|
"@tsconfig/react-native": "^2.0.2",
|
|
62
|
+
"@types/fastestsmallesttextencoderdecoder": "^1.0.0",
|
|
59
63
|
"@types/jest": "^29.2.1",
|
|
60
64
|
"@types/react": "^18.0.24",
|
|
61
65
|
"@types/react-native": "^0.71.3",
|
|
@@ -69,7 +73,7 @@
|
|
|
69
73
|
"pod-install": "^0.1.0",
|
|
70
74
|
"prettier": "^2.5.1",
|
|
71
75
|
"react": "18.0.0",
|
|
72
|
-
"react-native": "0.
|
|
76
|
+
"react-native": "0.71.13",
|
|
73
77
|
"react-native-builder-bob": "^0.18.2",
|
|
74
78
|
"release-it": "^14.2.2",
|
|
75
79
|
"typedoc": "^0.23.14",
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
import { RoomEvent, type Room } from 'livekit-client';
|
|
4
|
+
import AudioSession, {
|
|
5
|
+
getDefaultAppleAudioConfigurationForMode,
|
|
6
|
+
type AppleAudioConfiguration,
|
|
7
|
+
type AudioTrackState,
|
|
8
|
+
} from './AudioSession';
|
|
9
|
+
import { log } from '..';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Handles setting the appropriate AVAudioSession options automatically
|
|
13
|
+
* depending on the audio track states of the Room.
|
|
14
|
+
*
|
|
15
|
+
* @param room
|
|
16
|
+
* @param preferSpeakerOutput
|
|
17
|
+
* @param onConfigureNativeAudio
|
|
18
|
+
*/
|
|
19
|
+
export function useIOSAudioManagement(
|
|
20
|
+
room: Room,
|
|
21
|
+
preferSpeakerOutput: boolean = true,
|
|
22
|
+
onConfigureNativeAudio?: (
|
|
23
|
+
trackState: AudioTrackState,
|
|
24
|
+
preferSpeakerOutput: boolean
|
|
25
|
+
) => AppleAudioConfiguration
|
|
26
|
+
) {
|
|
27
|
+
const [localTrackCount, setLocalTrackCount] = useState(0);
|
|
28
|
+
const [remoteTrackCount, setRemoteTrackCount] = useState(0);
|
|
29
|
+
const trackState = useMemo(
|
|
30
|
+
() => computeAudioTrackState(localTrackCount, remoteTrackCount),
|
|
31
|
+
[localTrackCount, remoteTrackCount]
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (Platform.OS !== 'ios') {
|
|
36
|
+
return () => {};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setLocalTrackCount(getLocalAudioTrackCount(room));
|
|
40
|
+
setRemoteTrackCount(getRemoteAudioTrackCount(room));
|
|
41
|
+
|
|
42
|
+
let onLocalPublished = () => {
|
|
43
|
+
setLocalTrackCount(localTrackCount + 1);
|
|
44
|
+
};
|
|
45
|
+
let onLocalUnpublished = () => {
|
|
46
|
+
if (localTrackCount - 1 < 0) {
|
|
47
|
+
log.warn(
|
|
48
|
+
'mismatched local audio track count! attempted to reduce track count below zero.'
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
setLocalTrackCount(Math.max(localTrackCount - 1, 0));
|
|
52
|
+
};
|
|
53
|
+
let onRemotePublished = () => {
|
|
54
|
+
setRemoteTrackCount(remoteTrackCount + 1);
|
|
55
|
+
};
|
|
56
|
+
let onRemoteUnpublished = () => {
|
|
57
|
+
if (remoteTrackCount - 1 < 0) {
|
|
58
|
+
log.warn(
|
|
59
|
+
'mismatched remote audio track count! attempted to reduce track count below zero.'
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
setRemoteTrackCount(Math.max(remoteTrackCount - 1, 0));
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
room
|
|
66
|
+
.on(RoomEvent.LocalTrackPublished, onLocalPublished)
|
|
67
|
+
.on(RoomEvent.LocalTrackUnpublished, onLocalUnpublished)
|
|
68
|
+
.on(RoomEvent.TrackPublished, onRemotePublished)
|
|
69
|
+
.on(RoomEvent.TrackUnpublished, onRemoteUnpublished);
|
|
70
|
+
|
|
71
|
+
return () => {
|
|
72
|
+
room
|
|
73
|
+
.off(RoomEvent.LocalTrackPublished, onLocalPublished)
|
|
74
|
+
.off(RoomEvent.LocalTrackUnpublished, onLocalUnpublished)
|
|
75
|
+
.off(RoomEvent.TrackPublished, onRemotePublished)
|
|
76
|
+
.off(RoomEvent.TrackUnpublished, onRemoteUnpublished);
|
|
77
|
+
};
|
|
78
|
+
}, [room, localTrackCount, remoteTrackCount]);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (Platform.OS !== 'ios') {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let configFunc =
|
|
86
|
+
onConfigureNativeAudio ?? getDefaultAppleAudioConfigurationForMode;
|
|
87
|
+
let audioConfig = configFunc(trackState, preferSpeakerOutput);
|
|
88
|
+
|
|
89
|
+
AudioSession.setAppleAudioConfiguration(audioConfig);
|
|
90
|
+
}, [trackState, onConfigureNativeAudio, preferSpeakerOutput]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function computeAudioTrackState(
|
|
94
|
+
localTracks: number,
|
|
95
|
+
remoteTracks: number
|
|
96
|
+
): AudioTrackState {
|
|
97
|
+
if (localTracks > 0 && remoteTracks > 0) {
|
|
98
|
+
return 'localAndRemote';
|
|
99
|
+
} else if (localTracks > 0 && remoteTracks === 0) {
|
|
100
|
+
return 'localOnly';
|
|
101
|
+
} else if (localTracks === 0 && remoteTracks > 0) {
|
|
102
|
+
return 'remoteOnly';
|
|
103
|
+
} else {
|
|
104
|
+
return 'none';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getLocalAudioTrackCount(room: Room): number {
|
|
109
|
+
return room.localParticipant.audioTracks.entries.length;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getRemoteAudioTrackCount(room: Room): number {
|
|
113
|
+
var audioTracks = 0;
|
|
114
|
+
room.participants.forEach((participant) => {
|
|
115
|
+
audioTracks += participant.audioTracks.entries.length;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return audioTracks;
|
|
119
|
+
}
|