From 68dcaa35c31dc7555f160f829c3070224c684861 Mon Sep 17 00:00:00 2001 From: Manevolent Date: Sun, 5 Aug 2018 01:24:10 -0400 Subject: [PATCH] Microphone changes --- .../client/LocalTeamspeakClientSocket.java | 40 ++++++++++--------- .../manevolent/ts3j/ServerConnectionTest.java | 4 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java index 8a1230b..7c2affe 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java @@ -330,27 +330,29 @@ public class LocalTeamspeakClientSocket public void run() { PacketBody0Voice voice = new PacketBody0Voice(getRole().getOut()); Microphone microphone; - while (isConnected()) { - // Attempt to get the current microphone instance, saving it in a variable to prevent - // any race conditions by accessing the parent class' this.microphone. - if ((microphone = LocalTeamspeakClientSocket.this.microphone) == null) - continue; - if (microphone.isMuted()) { - // TODO - // Set a state and send a muted event - } else if (microphone.isReady()) { - voice.setCodecType(microphone.getCodec()); - voice.setCodecData(microphone.provide()); + if (!isConnected()) return; - try { - writePacket(voice); - } catch (IOException e) { - // All we are really concerned about here is a disconnection event, in which case the loop - // will exit. - } catch (TimeoutException e) { - // Not really possible, as we might expect, voice doesn't have ACKs. - } + // Attempt to get the current microphone instance, saving it in a variable to prevent + // any race conditions by accessing the parent class' this.microphone. + if ((microphone = LocalTeamspeakClientSocket.this.microphone) == null) + return; + + if (microphone.isMuted()) { + // TODO + // Set a state and send a muted event + } else if (microphone.isReady()) { + voice.setClientId(getClientId()); // not necessary probably + voice.setCodecType(microphone.getCodec()); + voice.setCodecData(microphone.provide()); + + try { + writePacket(voice); + } catch (IOException e) { + // All we are really concerned about here is a disconnection event, in which case the loop + // will exit. + } catch (TimeoutException e) { + // Not really possible; as we might expect, voice doesn't have ACKs. } } } diff --git a/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java b/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java index 90bd54a..28b6a65 100644 --- a/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java +++ b/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java @@ -38,9 +38,9 @@ public class ServerConnectionTest { 10000L ); - client.sendServerMessage("\u26D4"); + client.sendServerMessage("\u26D4 You are not listening to this channel."); - assertEquals(client.getState(), ClientConnectionState.CONNECTED); + assertEquals(client.getState(), ClientConnectionState.CONNECTED); for (Client c : client.listClients()) { client.getClientInfo(c.getId());