From 66bb3ae756daee1428a3e57f5c65577eda68bd1b Mon Sep 17 00:00:00 2001 From: Apehum Date: Fri, 3 May 2024 12:37:48 +0800 Subject: [PATCH] fix(client): don't try to reopen device after failure until a new device is found --- .../client/audio/device/VoiceDeviceManager.java | 17 +++++++++++++++-- gradle.properties | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/client/src/main/java/su/plo/voice/client/audio/device/VoiceDeviceManager.java b/client/src/main/java/su/plo/voice/client/audio/device/VoiceDeviceManager.java index aa68f12c..98a6f9fa 100644 --- a/client/src/main/java/su/plo/voice/client/audio/device/VoiceDeviceManager.java +++ b/client/src/main/java/su/plo/voice/client/audio/device/VoiceDeviceManager.java @@ -44,6 +44,9 @@ public final class VoiceDeviceManager implements DeviceManager { private ScheduledFuture job; + private String failedOutputDevices = ""; + private String failedInputDevices = ""; + @Override public void add(@NotNull AudioDevice device) { checkNotNull(device, "device cannot be null"); @@ -248,11 +251,16 @@ private void tickJob() throws DeviceException { .orElseThrow(() -> new IllegalStateException("OpenAL input factory is not registered"));; if (outputDevices.isEmpty()) { - if (outputFactory.getDeviceNames().size() > 0) { + List deviceNames = outputFactory.getDeviceNames(); + String deviceNamesString = String.join("\n", deviceNames); + + if (deviceNames.size() > 0 && !deviceNamesString.equals(failedOutputDevices)) { try { add(voiceClient.getDeviceManager().openOutputDevice(null, Params.EMPTY)); + failedOutputDevices = ""; } catch (Exception e) { LOGGER.error("Failed to open primary OpenAL output device", e); + failedOutputDevices = deviceNamesString; } if (!voiceClient.getAudioCapture().isActive() && !inputDevices.isEmpty()) { @@ -271,11 +279,16 @@ private void tickJob() throws DeviceException { } if (inputDevices.isEmpty()) { - if (inputFactory.getDeviceNames().size() > 0 && !config.getVoice().getDisableInputDevice().value()) { + List deviceNames = inputFactory.getDeviceNames(); + String deviceNamesString = String.join("\n", deviceNames); + + if (deviceNames.size() > 0 && !deviceNamesString.equals(failedInputDevices) && !config.getVoice().getDisableInputDevice().value()) { try { replace(null, voiceClient.getDeviceManager().openInputDevice(null, Params.EMPTY)); + failedInputDevices = ""; } catch (Exception e) { LOGGER.error("Failed to open input device", e); + failedInputDevices = deviceNamesString; } if (!voiceClient.getAudioCapture().isActive()) { diff --git a/gradle.properties b/gradle.properties index b04d4d3a..6559972a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Version targetJavaVersion=8 mavenGroup=su.plo.voice -buildVersion=2.0.9 +buildVersion=2.0.10 # Gradle args org.gradle.jvmargs=-Xmx2048M