Skip to content

Commit

Permalink
fix: untested fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Life committed Nov 27, 2024
1 parent feee595 commit b3205cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
8 changes: 8 additions & 0 deletions include/dpp/discordvoiceclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,14 @@ class DPP_EXPORT discord_voice_client : public websocket_client
*/
virtual ~discord_voice_client();

/**
* @brief Write to websocket. Encapsulates data in frames if the status is CONNECTED.
* @param data The data to send.
* @param _opcode The opcode of the data to send, either binary or text. The default
* is to use the socket's opcode as set in the constructor.
*/
void write(const std::string_view data, ws_opcode _opcode = OP_AUTO) override;

/**
* @brief Handle JSON from the websocket.
* @param buffer The entire buffer content from the websocket client
Expand Down
5 changes: 0 additions & 5 deletions src/dpp/sslclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,6 @@ void ssl_client::on_read(socket fd, const struct socket_events& ev) {
}

void ssl_client::on_write(socket fd, const struct socket_events& e) {
/* We wanted to write before so keep it */
socket_events new_se{e};
new_se.flags |= WANT_WRITE;
owner->socketengine->update_socket(new_se);

if (!tcp_connect_done) {
tcp_connect_done = true;
}
Expand Down
21 changes: 21 additions & 0 deletions src/dpp/voice/enabled/handle_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ void discord_voice_client::update_ratchets(bool force) {

}

void discord_voice_client::write(const std::string_view data, ws_opcode _opcode) {
websocket_client::write(data, _opcode);

bool should_append_want_write = false;
socket_events *new_se = nullptr;
{
std::lock_guard lk(owner->socketengine->fds_mutex);
auto i = owner->socketengine->fds.find(sfd);

should_append_want_write = i != owner->socketengine->fds.end() && (i->second->flags & WANT_WRITE) != WANT_WRITE;
if (should_append_want_write) {
new_se = i->second.get();
new_se->flags |= WANT_WRITE;
}
}

if (should_append_want_write) {
owner->socketengine->update_socket(*new_se);
}
}

bool discord_voice_client::handle_frame(const std::string &data, ws_opcode opcode) {
json j;

Expand Down

0 comments on commit b3205cd

Please sign in to comment.