mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Avoid creating a Json instance many times.
This commit is contained in:
committed by
Benoit Marty
parent
df48ed5a2d
commit
94392d30b2
+8
-5
@@ -44,6 +44,13 @@ class WebViewAudioManager(
|
|||||||
private val coroutineScope: CoroutineScope,
|
private val coroutineScope: CoroutineScope,
|
||||||
private val onInvalidAudioDeviceAdded: (InvalidAudioDeviceReason) -> Unit,
|
private val onInvalidAudioDeviceAdded: (InvalidAudioDeviceReason) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
private val json by lazy {
|
||||||
|
Json {
|
||||||
|
encodeDefaults = true
|
||||||
|
explicitNulls = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to disable bluetooth audio devices. This must be done on Android versions lower than Android 12,
|
* Whether to disable bluetooth audio devices. This must be done on Android versions lower than Android 12,
|
||||||
* since the WebView approach breaks when using the legacy Bluetooth audio APIs.
|
* since the WebView approach breaks when using the legacy Bluetooth audio APIs.
|
||||||
@@ -308,11 +315,7 @@ class WebViewAudioManager(
|
|||||||
devices: List<SerializableAudioDevice> = listAudioDevices().map(SerializableAudioDevice::fromAudioDeviceInfo),
|
devices: List<SerializableAudioDevice> = listAudioDevices().map(SerializableAudioDevice::fromAudioDeviceInfo),
|
||||||
) {
|
) {
|
||||||
Timber.d("Updating available audio devices")
|
Timber.d("Updating available audio devices")
|
||||||
val jsonSerializer = Json {
|
val deviceList = json.encodeToString(devices)
|
||||||
encodeDefaults = true
|
|
||||||
explicitNulls = false
|
|
||||||
}
|
|
||||||
val deviceList = jsonSerializer.encodeToString(devices)
|
|
||||||
webView.evaluateJavascript("controls.setAvailableOutputDevices($deviceList);", {
|
webView.evaluateJavascript("controls.setAvailableOutputDevices($deviceList);", {
|
||||||
Timber.d("Audio: setAvailableOutputDevices result: $it")
|
Timber.d("Audio: setAvailableOutputDevices result: $it")
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user