diff --git a/include/dpp/discordvoiceclient.h b/include/dpp/discordvoiceclient.h index 14a0f63ec8..6d0d21b251 100644 --- a/include/dpp/discordvoiceclient.h +++ b/include/dpp/discordvoiceclient.h @@ -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 diff --git a/src/dpp/sslclient.cpp b/src/dpp/sslclient.cpp index 454f9517c2..c40820df0a 100644 --- a/src/dpp/sslclient.cpp +++ b/src/dpp/sslclient.cpp @@ -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; } diff --git a/src/dpp/voice/enabled/handle_frame.cpp b/src/dpp/voice/enabled/handle_frame.cpp index 6a8bfe5510..d633a05e12 100644 --- a/src/dpp/voice/enabled/handle_frame.cpp +++ b/src/dpp/voice/enabled/handle_frame.cpp @@ -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;