83 "channel_data was deleted, you were kicked, voice server changed, or the main gateway session was dropped. should not "
89 inline voice_websocket_close& operator=(uint16_t valueNew) {
94 inline voice_websocket_close(uint16_t value) {
98 inline operator jsonifier::string_view() {
99 return voice_websocket_close::outputErrorValues[mappingValues[
static_cast<uint16_t
>(value)]];
102 inline operator bool() {
107 struct voice_socket_ready_data {
108 jsonifier::vector<jsonifier::string> modes{};
109 jsonifier::string ip{};
114 struct voice_session_description_data {
115 jsonifier::vector<uint8_t> secretKey{};
118 struct speaking_data {
123 struct voice_connection_hello_data {
124 uint32_t heartBeatInterval{};
127 struct voice_user_disconnect_data {
131 struct DiscordCoreAPI_Dll voice_user {
132 voice_user() =
default;
134 voice_user(snowflake userId);
136 voice_user& operator=(voice_user&& data)
noexcept;
138 voice_user& operator=(
const voice_user&) =
delete;
140 voice_user(
const voice_user&) =
delete;
142 discord_core_internal::opus_decoder_wrapper& getDecoder();
144 jsonifier::string_view_base<uint8_t> extractPayload();
146 void insertPayload(jsonifier::string_view_base<uint8_t>);
148 snowflake getUserId();
151 discord_core_internal::ring_buffer<uint8_t, 10> payloads{};
152 discord_core_internal::opus_decoder_wrapper decoder{};
156 struct DiscordCoreAPI_Dll rtppacket_encrypter {
157 rtppacket_encrypter() =
default;
159 rtppacket_encrypter(uint32_t ssrcNew,
const jsonifier::string_base<uint8_t>& keysNew);
161 jsonifier::string_view_base<uint8_t> encryptPacket(discord_core_internal::encoder_return_data& audioData);
164 jsonifier::string_base<uint8_t> data{};
165 jsonifier::string_base<uint8_t> keys{};
166 uint32_t timeStamp{};
171 struct DiscordCoreAPI_Dll moving_averager {
172 moving_averager(uint64_t collectionCountNew);
174 moving_averager operator+=(int64_t value);
179 std::deque<int64_t> values{};
180 uint64_t collectionCount{};
219 class DiscordCoreAPI_Dll voice_connection_bridge :
public discord_core_internal::udp_connection {
221 friend class voice_connection;
223 voice_connection_bridge(unordered_map<uint64_t, unique_ptr<voice_user>>* voiceUsersPtrNew, jsonifier::string_base<uint8_t>& encryptionKeyNew, stream_type streamType,
224 const jsonifier::string& baseUrlNew,
const uint16_t portNew, snowflake guildIdNew,
227 inline void applyGainRamp(int64_t sampleCount);
229 void parseOutgoingVoiceData();
231 void handleAudioBuffer()
override;
235 void disconnect()
override;
238 std::coroutine_handle<discord_core_api::co_routine<void, false>::promise_type>* token{};
239 unordered_map<uint64_t, unique_ptr<voice_user>>* voiceUsersPtr{};
240 jsonifier::string_base<uint8_t> decryptedDataString{};
241 std::array<opus_int16, 23040> downSampledVector{};
242 jsonifier::string_base<uint8_t> encryptionKey{};
243 std::array<opus_int32, 23040> upSampledVector{};
244 jsonifier::vector<uint8_t> resampleVector{};
245 moving_averager voiceUserCountAverage{ 25 };
252 class DiscordCoreAPI_Dll voice_udpconnection :
public discord_core_internal::udp_connection {
254 voice_udpconnection() =
default;
256 voice_udpconnection(
const jsonifier::string& baseUrlNew, uint16_t portNew, stream_type streamType, voice_connection* ptrNew,
259 void handleAudioBuffer()
override;
261 void disconnect()
override;
264 voice_connection* voiceConnection{};
274 friend class discord_core_internal::base_socket_agent;
275 friend class discord_core_internal::sound_cloud_api;
276 friend class discord_core_internal::you_tube_api;
277 friend class voice_connection_bridge;
278 friend class voice_udpconnection;
289 bool areWeConnected();
302 std::atomic<voice_connection_state> connectionState{ voice_connection_state::Collecting_Init_Data };
304 std::coroutine_handle<discord_core_api::co_routine<void, false>::promise_type> token{};
305 nanoseconds intervalCount{
static_cast<int64_t
>(960.0l / 48000.0l * 1000000000.0l) };
306 std::atomic<voice_active_state> prevActiveState{ voice_active_state::stopped };
307 std::atomic<voice_active_state> activeState{ voice_active_state::connecting };
308 discord_core_internal::voice_connection_data voiceConnectionData{};
309 unordered_map<uint64_t, unique_ptr<voice_user>> voiceUsers{};
313 jsonifier::string_base<uint8_t> encryptionKey{};
315 jsonifier::string audioEncryptionMode{};
316 rtppacket_encrypter packetEncrypter{};
317 int64_t sampleRatePerSecond{ 48000 };
319 voice_udpconnection udpConnection{};
320 int64_t nsPerSecond{ 1000000000 };
322 jsonifier::string externalIp{};
323 std::atomic_bool wasItAFail{};
324 std::atomic_bool* doWeQuit{};
325 std::atomic_bool doWeSkip{};
326 jsonifier::string voiceIp{};
327 jsonifier::string baseUrl{};
328 int64_t samplesPerPacket{};
330 int64_t msPerPacket{};
331 uint32_t audioSSRC{};
334 void parseIncomingVoiceData(jsonifier::string_view_base<uint8_t> rawDataBufferNew);
336 bool onMessageReceived(jsonifier::string_view_base<uint8_t> data);
340 void skipInternal(uint32_t currentRecursionDepth = 0);
342 void checkForAndSendHeartBeat(
const bool isImmedate);
344 void sendSpeakingMessage(
const bool isSpeaking);
348 void sendVoiceConnectionData();
350 bool areWeCurrentlyPlaying();
352 bool skip(
bool wasItAFail);
354 void connectInternal();
A co_routine - representing a potentially asynchronous operation/function.
discord_core_client - the main class for this library.
A websocket client, for communication via a tcp-connection.
Data structure representing a single guild, for the purposes of populating the cache.
A discord guild. used to connect to/disconnect from voice.
A class representing a snowflake identifier with various operations.
A class representing the song apis.
A thread-safe messaging block for data-structures.
A smart pointer class that provides unique ownership semantics.
voice_connection class - represents the connection to a given voice channel_data.
Voice websocket close codes.
voice_websocket_close_code
Voice websocket close codes.
@ Voice_Server_Crashed
The server crashed. our bad! try resuming.
@ disconnected
channel_data was deleted, you were kicked, voice server changed, or the main gateway session was drop...
@ Session_No_Longer_Valid
Your session is no longer valid.
@ Already_Authenticated
you sent more than one identify payload. stahp.
@ Session_Timeout
Your session has timed out.
@ Unknown_Protocol
We didn't recognize the protocol you sent.
@ Authentication_Failed
the token you sent in your identify payload is incorrect.
@ Unknown_Opcode
You sent an invalid opcode.
@ Failed_To_Decode
You sent an invalid payload in your identifying to the gateway.
@ Server_Not_Found
We can't find the server you're trying to connect to.
@ Unknown_Encryption_Mode
We didn't recognize your encryption.
@ Not_Authenticated
You sent a payload before identifying with the gateway.
@ Normal_Close
Normal close.
@ connect
Allows for joining of a voice channel.
The main namespace for the forward-facing interfaces.
voice_socket_op_codes
The various opcodes that could be sent/received by the voice-websocket.
@ resumed
Acknowledge a successful session resume.
@ heartbeat
Keep the websocket connection alive.
@ Ready_Server
complete the websocket handshake.
@ hello
Time to wait between sending heartbeats in milliseconds.
@ resume
Resume a connection.
@ Session_Description
Describe the session.
@ Heartbeat_ACK
Sent to acknowledge a received client heartbeat.
@ identify
Begin a voice websocket connection.
@ Client_Disconnect
A client has disconnected from the voice channel.
@ Select_Protocol
Select the voice protocol.
@ speaking
Indicate which users are speaking.
voice_connection_state
For the various connection states of the voice_connection class.
@ Collecting_Init_Data
collecting initialization data.
@ Collecting_Ready
collecting the client ready.
@ Sending_Identify
Sending the identify payload.
@ Collecting_Hello
collecting the client hello.
@ Initializing_WebSocket
Initializing the websocket.
@ Initializing_DatagramSocket
Initializing the datagram udp SOCKET.
@ Collecting_Session_Description
collecting the session-description payload.
@ Sending_Select_Protocol
Sending the select-protocol payload.
voice_active_state
For the various active states of the voice_connection class.
Represents a single frame of audio data.
Wrapper class for the opus audio encoder.
For connecting to a voice-channel. "streamInfo" is used when a SOCKET is created to connect this bot ...