Channel subscription, getting channel info, and multithreaded event handling
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package com.github.manevolent.ts3j.event;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2014 Bert De Geyter
|
||||
* %%
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
import com.github.manevolent.ts3j.api.ChannelProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelSubscribedEvent extends BaseEvent {
|
||||
|
||||
public ChannelSubscribedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt(ChannelProperty.CID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onChannelSubscribed(this);
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,8 @@ public interface TS3Event {
|
||||
return new ClientNeededPermissionsEvent(command.toMap());
|
||||
case "notifyclientupdated": // CLIENT
|
||||
return new ClientUpdatedEvent(command.toMap());
|
||||
case "notifychannelsubscribed": // CLIENT
|
||||
return new ChannelSubscribedEvent(command.toMap());
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown event: " + command.getName());
|
||||
}
|
||||
|
||||
@@ -65,4 +65,6 @@ public interface TS3Listener {
|
||||
void onClientChanged(ClientUpdatedEvent e);
|
||||
|
||||
void onDisconnected(DisconnectedEvent e);
|
||||
|
||||
void onChannelSubscribed(ChannelSubscribedEvent e);
|
||||
}
|
||||
|
||||
+15
-4
@@ -26,9 +26,7 @@ import java.net.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -48,6 +46,7 @@ public class LocalTeamspeakClientSocket
|
||||
private final DatagramPacket packet = new DatagramPacket(new byte[500], 500);
|
||||
|
||||
private final Map<String, CommandProcessor> namedProcessors = new HashMap<>();
|
||||
private final ExecutorService commandExecutionService = Executors.newCachedThreadPool();
|
||||
private final Object commandSendLock = new Object();
|
||||
|
||||
|
||||
@@ -239,7 +238,8 @@ public class LocalTeamspeakClientSocket
|
||||
processor.process(client, singleCommand);
|
||||
} else if (singleCommand.getName().startsWith("notify")) {
|
||||
TS3Event event = TS3Event.createEvent(singleCommand);
|
||||
listeners.forEach(event::fire);
|
||||
|
||||
commandExecutionService.submit(() -> listeners.forEach(event::fire));
|
||||
} else {
|
||||
CommandProcessor awaitingCommandProcessor;
|
||||
|
||||
@@ -815,6 +815,17 @@ public class LocalTeamspeakClientSocket
|
||||
return clients.iterator().next();
|
||||
}
|
||||
|
||||
public Channel getChannelInfo(int channelId)
|
||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
||||
Command command = new SingleCommand(
|
||||
"channelinfo",
|
||||
ProtocolRole.CLIENT,
|
||||
new CommandSingleParameter("cid", Integer.toString(channelId))
|
||||
);
|
||||
|
||||
return executeCommand(command, x -> new Channel(x.toMap())).get().iterator().next();
|
||||
}
|
||||
|
||||
public void disconnect()
|
||||
throws
|
||||
IOException, TimeoutException,
|
||||
|
||||
Reference in New Issue
Block a user