Skip to content

Commit

Permalink
voice session reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Dec 2, 2024
1 parent 315046c commit f2e1edc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions include/dpp/discordclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
#include <mutex>
#include <shared_mutex>



#define DISCORD_API_VERSION "10"
#define API_PATH "/api/v" DISCORD_API_VERSION

namespace dpp {

// Forward declarations
Expand Down
10 changes: 1 addition & 9 deletions include/dpp/wsclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,6 @@ class DPP_EXPORT websocket_client : public ssl_client {
*/
bool parseheader(std::string& buffer);

/**
* @brief Unpack a frame and pass completed frames up the stack.
* @param buffer The buffer to operate on. Gets modified to remove completed frames on the head of the buffer
* @param offset The offset to start at (reserved for future use)
* @param first True if is the first element (reserved for future use)
* @return true if a complete frame has been received
*/
bool unpack(std::string& buffer, uint32_t offset, bool first = true);

/**
* @brief Fill a header for outbound messages
* @param outbuf The raw frame to fill
Expand Down Expand Up @@ -233,6 +224,7 @@ class DPP_EXPORT websocket_client : public ssl_client {
/**
* @brief Send OP_CLOSE error code 1000 to the other side of the connection.
* This indicates graceful close.
* @note This informs Discord to invalidate the session, you cannot resume if you send this
*/
void send_close_packet();

Expand Down
2 changes: 2 additions & 0 deletions src/dpp/discordvoiceclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ void discord_voice_client::error(uint32_t errorcode)
this->terminating = true;
log(dpp::ll_error, "This is a non-recoverable error, giving up on voice connection");
}

this->close();
}

void discord_voice_client::set_user_gain(snowflake user_id, float factor)
Expand Down
4 changes: 2 additions & 2 deletions src/dpp/voice/enabled/cleanup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ namespace dpp {

void discord_voice_client::cleanup()
{
if (encoder) {
if (encoder != nullptr) {
opus_encoder_destroy(encoder);
encoder = nullptr;
}
if (repacketizer) {
if (repacketizer != nullptr) {
opus_repacketizer_destroy(repacketizer);
repacketizer = nullptr;
}
Expand Down
8 changes: 7 additions & 1 deletion src/dpp/voice/enabled/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ void discord_voice_client::on_disconnect() {
}
last_loop_time = current_time;

log(dpp::ll_debug, "Attempting to reconnect the websocket...");
ssl_client::close();
owner->start_timer([this](auto handle) {
log(dpp::ll_debug, "Attempting to reconnect voice websocket " + std::to_string(channel_id) + " to wss://" + hostname + "...");
owner->stop_timer(handle);
cleanup();
if (timer_handle) {
owner->stop_timer(timer_handle);
timer_handle = 0;
}
start = time(nullptr);
setup();
terminating = false;
ssl_client::connect();
Expand Down

0 comments on commit f2e1edc

Please sign in to comment.