Search in sources :

Example 1 with AudioConnectionImpl

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);
    }
}
Also used : AudioConnectionImpl(org.javacord.core.audio.AudioConnectionImpl) ServerVoiceChannel(org.javacord.api.entity.channel.ServerVoiceChannel)

Example 2 with AudioConnectionImpl

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);
    });
}
Also used : VoiceServerUpdateEvent(org.javacord.api.event.server.VoiceServerUpdateEvent) VoiceServerUpdateEventImpl(org.javacord.core.event.server.VoiceServerUpdateEventImpl) AudioConnectionImpl(org.javacord.core.audio.AudioConnectionImpl)

Aggregations

AudioConnectionImpl (org.javacord.core.audio.AudioConnectionImpl)2 ServerVoiceChannel (org.javacord.api.entity.channel.ServerVoiceChannel)1 VoiceServerUpdateEvent (org.javacord.api.event.server.VoiceServerUpdateEvent)1 VoiceServerUpdateEventImpl (org.javacord.core.event.server.VoiceServerUpdateEventImpl)1