83 "channel_data was deleted, you were kicked, voice server changed, or the main gateway session was dropped. should not "
89 DCA_INLINE voice_websocket_close& operator=(uint16_t valueNew) {
94 DCA_INLINE voice_websocket_close(uint16_t value) {
98 DCA_INLINE
operator jsonifier::string_view() {
99 return voice_websocket_close::outputErrorValues[mappingValues[
static_cast<uint16_t
>(value)]];
102 DCA_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 {
133 jsonifier::string_view_base<uint8_t> voiceData{};
137 struct DiscordCoreAPI_Dll voice_user {
138 voice_user() =
default;
140 voice_user(snowflake userId);
142 voice_user& operator=(voice_user&& data)
noexcept;
144 voice_user& operator=(
const voice_user&) =
delete;
146 voice_user(
const voice_user&) =
delete;
148 discord_core_internal::opus_decoder_wrapper& getDecoder();
150 jsonifier::string_view_base<uint8_t> extractPayload();
152 void insertPayload(jsonifier::string_view_base<uint8_t>);
154 snowflake getUserId();
157 discord_core_internal::ring_buffer<uint8_t, 10> payloads{};
158 discord_core_internal::opus_decoder_wrapper decoder{};
162 struct DiscordCoreAPI_Dll rtp_packet_encrypter {
163 rtp_packet_encrypter() =
default;
165 rtp_packet_encrypter(uint32_t ssrcNew,
const jsonifier::string_base<uint8_t>& keysNew);
167 jsonifier::string_view_base<uint8_t> encryptPacket(discord_core_internal::encoder_return_data& audioData);
170 jsonifier::string_base<uint8_t> data{};
171 jsonifier::string_base<uint8_t> keys{};
172 uint32_t timeStamp{};
177 struct DiscordCoreAPI_Dll moving_averager {
178 moving_averager(uint64_t collectionCountNew);
180 moving_averager operator+=(int64_t value);
185 std::deque<int64_t> values{};
186 uint64_t collectionCount{};
225 class DiscordCoreAPI_Dll voice_connection_bridge :
public discord_core_internal::udp_connection {
227 friend class voice_connection;
229 voice_connection_bridge(unordered_map<uint64_t, unique_ptr<voice_user>>* voiceUsersPtrNew, jsonifier::string_base<uint8_t>& encryptionKeyNew, stream_type streamType,
230 const jsonifier::string& baseUrlNew,
const uint16_t portNew, snowflake guildIdNew,
231 std::coroutine_handle<discord_core_api::co_routine<void, false>::promise_type>* tokenNew);
233 DCA_INLINE
void applyGainRamp(int64_t sampleCount);
235 void parseOutgoingVoiceData();
237 void handleAudioBuffer()
override;
241 void disconnect()
override;
244 std::coroutine_handle<discord_core_api::co_routine<void, false>::promise_type>* token{};
245 unordered_map<uint64_t, unique_ptr<voice_user>>* voiceUsersPtr{};
246 jsonifier::string_base<uint8_t> decryptedDataString{};
247 std::array<opus_int16, 23040> downSampledVector{};
248 jsonifier::string_base<uint8_t> encryptionKey{};
249 std::array<opus_int32, 23040> upSampledVector{};
250 jsonifier::vector<uint8_t> resampleVector{};
251 moving_averager voiceUserCountAverage{ 25 };
252 bool doWeKeepAudioData{
false };
259 class DiscordCoreAPI_Dll voice_udpconnection :
public discord_core_internal::udp_connection {
261 voice_udpconnection() =
default;
263 voice_udpconnection(
const jsonifier::string& baseUrlNew, uint16_t portNew, stream_type streamType, voice_connection* ptrNew,
264 std::coroutine_handle<discord_core_api::co_routine<void, false>::promise_type>* stopToken);
266 void handleAudioBuffer()
override;
268 void disconnect()
override;
271 voice_connection* voiceConnection{};
281 friend class discord_core_internal::base_socket_agent;
282 friend class discord_core_internal::sound_cloud_api;
283 friend class discord_core_internal::you_tube_api;
284 friend class voice_connection_bridge;
285 friend class voice_udpconnection;
286 friend class discord_core_client;
287 friend class guild_cache_data;
288 friend class guild_data;
289 friend class song_api;
294 voice_connection(discord_core_internal::websocket_client* baseShardNew, std::atomic_bool* doWeQuitNew);
296 bool areWeConnected();
300 snowflake getChannelId();
308 void connect(
const voice_connect_init_data& initData);
310 ~voice_connection() =
default;
313 std::atomic<voice_connection_state> connectionState{ voice_connection_state::Collecting_Init_Data };
314 unbounded_message_block<discord_core_internal::voice_connection_data> voiceConnectionDataBuffer{};
315 std::coroutine_handle<discord_core_api::co_routine<void, false>::promise_type> token{};
316 nanoseconds intervalCount{
static_cast<int64_t
>(960.0l / 48000.0l * 1000000000.0l) };
317 std::atomic<voice_active_state> prevActiveState{ voice_active_state::stopped };
318 std::atomic<voice_active_state> activeState{ voice_active_state::connecting };
319 discord_core_internal::voice_connection_data voiceConnectionData{};
320 unordered_map<uint64_t, unique_ptr<voice_user>> voiceUsers{};
321 discord_core_internal::opus_encoder_wrapper encoder{};
322 discord_core_internal::websocket_client* baseShard{};
323 unique_ptr<voice_connection_bridge> streamSocket{};
324 jsonifier::string_base<uint8_t> encryptionKey{};
325 voice_connect_init_data voiceConnectInitData{};
326 jsonifier::string audioEncryptionMode{};
327 rtp_packet_encrypter packetEncrypter{};
328 int64_t sampleRatePerSecond{ 48000 };
329 co_routine<void, false> taskThread{};
330 voice_udpconnection udpConnection{};
331 int64_t nsPerSecond{ 1000000000 };
332 audio_frame_data xferAudioData{};
333 jsonifier::string externalIp{};
334 std::atomic_bool wasItAFail{};
335 std::atomic_bool* doWeQuit{};
336 std::atomic_bool doWeSkip{};
337 jsonifier::string voiceIp{};
338 jsonifier::string baseUrl{};
339 int64_t samplesPerPacket{};
340 snowflake currentUserId{};
341 int64_t msPerPacket{};
342 uint32_t audioSSRC{};
345 void parseIncomingVoiceData(jsonifier::string_view_base<uint8_t> rawDataBufferNew);
347 bool onMessageReceived(jsonifier::string_view_base<uint8_t> data);
349 unbounded_message_block<audio_frame_data>& getAudioBuffer();
351 void skipInternal(uint32_t currentRecursionDepth = 0);
353 void checkForAndSendHeartBeat(
const bool isImmedate);
355 void sendSpeakingMessage(
const bool isSpeaking);
357 co_routine<void, false> runVoice();
359 void sendVoiceConnectionData();
361 bool areWeCurrentlyPlaying();
363 bool skip(
bool wasItAFail);
365 void connectInternal();
@ reconnect
You should attempt to reconnect and resume immediately.
voice_connection class - represents the connection to a given voice channel_data.
voice_user_payload extractVoicePayload()
Collects some voice data for a given user.
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.
The voice data for a given user, as raw PCM data, along with their Id.