@@ -152,6 +152,44 @@ actual fun joinMeeting(
152152 meetingSession!! .audioVideo.startRemoteVideo()
153153}
154154
155+ actual fun getAvailableInputDevices (): List <AudioDevice > =
156+ meetingSession?.audioVideo
157+ ?.listAudioDevices()
158+ ?.mapNotNull { device ->
159+ val type = when (device.type) {
160+ MediaDeviceType .AUDIO_BLUETOOTH -> AudioDeviceType .BLUETOOTH
161+ MediaDeviceType .AUDIO_WIRED_HEADSET -> AudioDeviceType .WIRED_HEADSET
162+ MediaDeviceType .AUDIO_USB_HEADSET -> AudioDeviceType .EARPIECE
163+ MediaDeviceType .AUDIO_HANDSET -> AudioDeviceType .BUILT_IN_MIC
164+ else -> return @mapNotNull null
165+ }
166+
167+ AudioDevice (
168+ type = type,
169+ label = device.label
170+ )
171+ }
172+ .orEmpty()
173+
174+ actual fun getAvailableOutputDevices (): List <AudioDevice > =
175+ meetingSession?.audioVideo
176+ ?.listAudioDevices()
177+ ?.mapNotNull { device ->
178+ val type = when (device.type) {
179+ MediaDeviceType .AUDIO_BLUETOOTH -> AudioDeviceType .BLUETOOTH
180+ MediaDeviceType .AUDIO_WIRED_HEADSET -> AudioDeviceType .WIRED_HEADSET
181+ MediaDeviceType .AUDIO_USB_HEADSET -> AudioDeviceType .EARPIECE
182+ MediaDeviceType .AUDIO_BUILTIN_SPEAKER -> AudioDeviceType .SPEAKER
183+ else -> return @mapNotNull null
184+ }
185+
186+ AudioDevice (
187+ type = type,
188+ label = device.label
189+ )
190+ }
191+ .orEmpty()
192+
155193actual fun leaveMeeting () {
156194 try {
157195 if (cameraOn || cameraCaptureSource != null ) {
@@ -289,35 +327,12 @@ actual fun switchCamera() {
289327 source.device = newDevice
290328}
291329
292- actual fun switchAudioDevice (deviceId : String? ) {
293- if (deviceId.isNullOrBlank()) return
294- val devices = meetingSession?.audioVideo?.listAudioDevices() ? : return
295-
296- val target = devices.firstOrNull { device ->
297- if (device.id == deviceId) {
298- true
299- } else if (device.id.isNullOrBlank()) {
300- val typeConst = when (device.type) {
301- MediaDeviceType .AUDIO_BUILTIN_SPEAKER -> AudioDeviceType .SPEAKER
302- MediaDeviceType .AUDIO_HANDSET -> AudioDeviceType .EARPIECE
303- MediaDeviceType .AUDIO_BLUETOOTH -> AudioDeviceType .BLUETOOTH
304- MediaDeviceType .AUDIO_WIRED_HEADSET -> AudioDeviceType .WIRED_HEADSET
305- else -> AudioDeviceType .UNKNOWN
306- }
307- val typeName = typeConst.name
308- val suffix = when (typeConst) {
309- AudioDeviceType .SPEAKER -> " PHONE_SPEAKER"
310- AudioDeviceType .EARPIECE -> " HANDSET_EARPIECE"
311- AudioDeviceType .BLUETOOTH -> deviceId.substringAfter(" ${typeName} _" , " " )
312- else -> device.label.replace(" [^A-Za-z0-9]" .toRegex(), " _" ).uppercase()
313- }
314- " ${typeName} _$suffix " == deviceId
315- } else {
316- false
317- }
318- }
319-
320- target?.let { meetingSession?.audioVideo?.chooseAudioDevice(it) }
330+ actual fun switchAudioDevice (device : String? ) {
331+ val targetChimeDevice = meetingSession
332+ ?.audioVideo
333+ ?.listAudioDevices()
334+ ?.firstOrNull { it.label == device } ? : return
335+ meetingSession?.audioVideo?.chooseAudioDevice(targetChimeDevice)
321336}
322337
323338actual fun subscribeToTopic (topic : String , listener : (TextMessage ) -> Unit ) {
@@ -339,4 +354,4 @@ actual fun subscribeToTopic(topic: String, listener: (TextMessage) -> Unit) {
339354actual fun unsubscribeFromTopic (topic : String ) {
340355 meetingSession?.audioVideo?.removeRealtimeDataMessageObserverFromTopic(topic)
341356 topicObservers.remove(topic)
342- }
357+ }
0 commit comments