use of net.dv8tion.jda.internal.audio.AudioConnection in project JDA by DV8FromTheWorld.
the class VoiceServerUpdateHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
final long guildId = content.getLong("guild_id");
if (getJDA().getGuildSetupController().isLocked(guildId))
return guildId;
Guild guild = getJDA().getGuildById(guildId);
if (guild == null)
throw new IllegalArgumentException("Attempted to start audio connection with Guild that doesn't exist!");
getJDA().getDirectAudioController().update(guild, guild.getSelfMember().getVoiceState().getChannel());
if (content.isNull("endpoint")) {
// to actually connect to the audio server.
return null;
}
// Strip the port from the endpoint.
String endpoint = content.getString("endpoint").replace(":80", "");
String token = content.getString("token");
String sessionId = guild.getSelfMember().getVoiceState().getSessionId();
if (sessionId == null)
throw new IllegalArgumentException("Attempted to create audio connection without having a session ID. Did VOICE_STATE_UPDATED fail?");
VoiceDispatchInterceptor voiceInterceptor = getJDA().getVoiceInterceptor();
if (voiceInterceptor != null) {
voiceInterceptor.onVoiceServerUpdate(new VoiceDispatchInterceptor.VoiceServerUpdate(guild, endpoint, token, sessionId, allContent));
return null;
}
AudioManagerImpl audioManager = (AudioManagerImpl) getJDA().getAudioManagersView().get(guildId);
if (audioManager == null) {
WebSocketClient.LOG.debug("Received a VOICE_SERVER_UPDATE but JDA is not currently connected nor attempted to connect " + "to a VoiceChannel. Assuming that this is caused by another client running on this account. " + "Ignoring the event.");
return null;
}
MiscUtil.locked(audioManager.CONNECTION_LOCK, () -> {
// Synchronized to prevent attempts to close while setting up initial objects.
AudioChannel target = guild.getSelfMember().getVoiceState().getChannel();
if (target == null) {
WebSocketClient.LOG.warn("Ignoring VOICE_SERVER_UPDATE for unknown channel");
return;
}
AudioConnection connection = new AudioConnection(audioManager, endpoint, sessionId, token, target);
audioManager.setAudioConnection(connection);
connection.startConnection();
});
return null;
}
Aggregations