summaryrefslogtreecommitdiff
path: root/src/discord
diff options
context:
space:
mode:
Diffstat (limited to 'src/discord')
-rw-r--r--src/discord/discord.cpp6
-rw-r--r--src/discord/discord.hpp12
-rw-r--r--src/discord/objects.cpp2
-rw-r--r--src/discord/objects.hpp2
-rw-r--r--src/discord/voiceclient.cpp10
-rw-r--r--src/discord/voiceclient.hpp10
6 files changed, 34 insertions, 8 deletions
diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp
index ed9b999..5670d4a 100644
--- a/src/discord/discord.cpp
+++ b/src/discord/discord.cpp
@@ -1169,6 +1169,7 @@ void DiscordClient::AcceptVerificationGate(Snowflake guild_id, VerificationGateI
});
}
+#ifdef WITH_VOICE
void DiscordClient::ConnectToVoice(Snowflake channel_id) {
auto channel = GetChannel(channel_id);
if (!channel.has_value() || !channel->GuildID.has_value()) return;
@@ -1178,6 +1179,7 @@ void DiscordClient::ConnectToVoice(Snowflake channel_id) {
m.PreferredRegion = "newark";
m_websocket.Send(m);
}
+#endif
void DiscordClient::SetReferringChannel(Snowflake id) {
if (!id.IsValid()) {
@@ -1498,12 +1500,14 @@ void DiscordClient::HandleGatewayMessage(std::string str) {
case GatewayEvent::GUILD_MEMBERS_CHUNK: {
HandleGatewayGuildMembersChunk(m);
} break;
+#ifdef WITH_VOICE
case GatewayEvent::VOICE_STATE_UPDATE: {
HandleGatewayVoiceStateUpdate(m);
} break;
case GatewayEvent::VOICE_SERVER_UPDATE: {
HandleGatewayVoiceServerUpdate(m);
} break;
+#endif
}
} break;
default:
@@ -2114,6 +2118,7 @@ void DiscordClient::HandleGatewayGuildMembersChunk(const GatewayMessage &msg) {
m_store.EndTransaction();
}
+#ifdef WITH_VOICE
void DiscordClient::HandleGatewayVoiceStateUpdate(const GatewayMessage &msg) {
VoiceStateUpdateData data = msg.Data;
if (data.UserID == m_user_data.ID) {
@@ -2132,6 +2137,7 @@ void DiscordClient::HandleGatewayVoiceServerUpdate(const GatewayMessage &msg) {
m_voice.SetUserID(m_user_data.ID);
m_voice.Start();
}
+#endif
void DiscordClient::HandleGatewayReadySupplemental(const GatewayMessage &msg) {
ReadySupplementalData data = msg.Data;
diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp
index a6eabd9..907c3e6 100644
--- a/src/discord/discord.hpp
+++ b/src/discord/discord.hpp
@@ -181,7 +181,9 @@ public:
void GetVerificationGateInfo(Snowflake guild_id, const sigc::slot<void(std::optional<VerificationGateInfoObject>)> &callback);
void AcceptVerificationGate(Snowflake guild_id, VerificationGateInfoObject info, const sigc::slot<void(DiscordError code)> &callback);
+#ifdef WITH_VOICE
void ConnectToVoice(Snowflake channel_id);
+#endif
void SetReferringChannel(Snowflake id);
@@ -262,11 +264,15 @@ private:
void HandleGatewayMessageAck(const GatewayMessage &msg);
void HandleGatewayUserGuildSettingsUpdate(const GatewayMessage &msg);
void HandleGatewayGuildMembersChunk(const GatewayMessage &msg);
- void HandleGatewayVoiceStateUpdate(const GatewayMessage &msg);
- void HandleGatewayVoiceServerUpdate(const GatewayMessage &msg);
void HandleGatewayReadySupplemental(const GatewayMessage &msg);
void HandleGatewayReconnect(const GatewayMessage &msg);
void HandleGatewayInvalidSession(const GatewayMessage &msg);
+
+#ifdef WITH_VOICE
+ void HandleGatewayVoiceStateUpdate(const GatewayMessage &msg);
+ void HandleGatewayVoiceServerUpdate(const GatewayMessage &msg);
+#endif
+
void HeartbeatThread();
void SendIdentify();
void SendResume();
@@ -326,7 +332,9 @@ private:
bool m_wants_resume = false; // reconnecting specifically to resume
std::string m_session_id;
+#ifdef WITH_VOICE
DiscordVoiceClient m_voice;
+#endif
mutable std::mutex m_msg_mutex;
Glib::Dispatcher m_msg_dispatch;
diff --git a/src/discord/objects.cpp b/src/discord/objects.cpp
index 5ca8718..a6a7cc6 100644
--- a/src/discord/objects.cpp
+++ b/src/discord/objects.cpp
@@ -641,6 +641,7 @@ void from_json(const nlohmann::json &j, GuildMembersChunkData &m) {
JS_D("guild_id", m.GuildID);
}
+#ifdef WITH_VOICE
void to_json(nlohmann::json &j, const VoiceStateUpdateMessage &m) {
j["op"] = GatewayOp::VoiceStateUpdate;
j["d"]["guild_id"] = m.GuildID;
@@ -661,3 +662,4 @@ void from_json(const nlohmann::json &j, VoiceServerUpdateData &m) {
JS_D("guild_id", m.GuildID);
JS_D("endpoint", m.Endpoint);
}
+#endif
diff --git a/src/discord/objects.hpp b/src/discord/objects.hpp
index 240b4c5..c9c8aff 100644
--- a/src/discord/objects.hpp
+++ b/src/discord/objects.hpp
@@ -867,6 +867,7 @@ struct GuildMembersChunkData {
friend void from_json(const nlohmann::json &j, GuildMembersChunkData &m);
};
+#ifdef WITH_VOICE
struct VoiceStateUpdateMessage {
Snowflake GuildID;
Snowflake ChannelID;
@@ -892,3 +893,4 @@ struct VoiceServerUpdateData {
friend void from_json(const nlohmann::json &j, VoiceServerUpdateData &m);
};
+#endif
diff --git a/src/discord/voiceclient.cpp b/src/discord/voiceclient.cpp
index 7aaa4a5..d8855fd 100644
--- a/src/discord/voiceclient.cpp
+++ b/src/discord/voiceclient.cpp
@@ -1,3 +1,5 @@
+#ifdef WITH_VOICE
+ // clang-format off
#include "voiceclient.hpp"
#include "json.hpp"
#include <sodium.h>
@@ -10,6 +12,7 @@
#else
#define S_ADDR(var) (var).sin_addr.s_addr
#endif
+// clang-format on
UDPSocket::UDPSocket() {
m_socket = socket(AF_INET, SOCK_DGRAM, 0);
@@ -88,11 +91,11 @@ std::vector<uint8_t> UDPSocket::Receive() {
void UDPSocket::Stop() {
m_running = false;
-#ifdef _WIN32
+ #ifdef _WIN32
shutdown(m_socket, SD_BOTH);
-#else
+ #else
shutdown(m_socket, SHUT_RDWR);
-#endif
+ #endif
if (m_thread.joinable()) m_thread.join();
}
@@ -385,3 +388,4 @@ void from_json(const nlohmann::json &j, VoiceSessionDescriptionData &m) {
JS_D("mode", m.Mode);
JS_D("secret_key", m.SecretKey);
}
+#endif
diff --git a/src/discord/voiceclient.hpp b/src/discord/voiceclient.hpp
index 615bbde..4b988d5 100644
--- a/src/discord/voiceclient.hpp
+++ b/src/discord/voiceclient.hpp
@@ -1,4 +1,6 @@
#pragma once
+#ifdef WITH_VOICE
+// clang-format off
#include "snowflake.hpp"
#include "waiter.hpp"
#include "websocket.hpp"
@@ -6,6 +8,7 @@
#include <queue>
#include <string>
#include <glibmm/dispatcher.h>
+// clang-format on
enum class VoiceGatewayCloseCode : uint16_t {
UnknownOpcode = 4001,
@@ -124,11 +127,11 @@ public:
private:
void ReadThread();
-#ifdef _WIN32
+ #ifdef _WIN32
SOCKET m_socket;
-#else
+ #else
int m_socket;
-#endif
+ #endif
sockaddr_in m_server;
std::atomic<bool> m_running = false;
@@ -203,3 +206,4 @@ private:
Waiter m_heartbeat_waiter;
std::thread m_heartbeat_thread;
};
+#endif