use of org.javacord.core.audio.AudioConnectionImpl in project Javacord by BtoBastian.
the class VoiceStateUpdateHandler method handleSelf.
private void handleSelf(JsonNode packet) {
// We need the session id to connect to an audio websocket
String sessionId = packet.get("session_id").asText();
long channelId = packet.get("channel_id").asLong();
Optional<ServerVoiceChannel> optionalChannel = api.getServerVoiceChannelById(channelId);
if (optionalChannel.isPresent()) {
ServerVoiceChannel channel = optionalChannel.get();
dispatchVoiceStateUpdateEvent(channel, channel.getServer(), packet.get("session_id").asText());
AudioConnectionImpl pendingAudioConnection = api.getPendingAudioConnectionByServerId(channel.getServer().getId());
if (pendingAudioConnection != null) {
pendingAudioConnection.setSessionId(sessionId);
pendingAudioConnection.tryConnect();
}
channel.getServer().getAudioConnection().ifPresent(connection -> {
((AudioConnectionImpl) connection).setSessionId(sessionId);
((AudioConnectionImpl) connection).tryConnect();
});
} else {
LoggerUtil.logMissingChannel(logger, channelId);
}
}
use of org.javacord.core.audio.AudioConnectionImpl in project Javacord by BtoBastian.
the class VoiceServerUpdateHandler method handle.
@Override
public void handle(JsonNode packet) {
String token = packet.get("token").asText();
String endpoint = packet.get("endpoint").asText();
long serverId = packet.get("guild_id").asLong();
// We need the session id to connect to an audio websocket
AudioConnectionImpl pendingAudioConnection = api.getPendingAudioConnectionByServerId(serverId);
if (pendingAudioConnection != null) {
pendingAudioConnection.setToken(token);
pendingAudioConnection.setEndpoint(endpoint);
pendingAudioConnection.tryConnect();
}
api.getServerById(serverId).ifPresent(server -> {
VoiceServerUpdateEvent event = new VoiceServerUpdateEventImpl(server, token, endpoint);
api.getEventDispatcher().dispatchVoiceServerUpdateEvent((DispatchQueueSelector) server, server, event);
});
}
Aggregations