Skip to content

Commit

Permalink
fix(client): don't try to reopen device after failure until a new dev…
Browse files Browse the repository at this point in the history
…ice is found
  • Loading branch information
Apehum committed May 3, 2024
1 parent c55498f commit 66bb3ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<String> 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()) {
Expand All @@ -271,11 +279,16 @@ private void tickJob() throws DeviceException {
}

if (inputDevices.isEmpty()) {
if (inputFactory.getDeviceNames().size() > 0 && !config.getVoice().getDisableInputDevice().value()) {
List<String> 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()) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 66bb3ae

Please sign in to comment.