Orca
A bot framework that is easy to reason about, easy to debug, and easy to use.
Classes | Typedefs | Enumerations | Functions
discord-voice-connections.h File Reference

File containing internal functions and datatypes for Voice Connections. More...

#include <time.h>
#include <pthread.h>
#include "cee-data-sizes.h"
Include dependency graph for discord-voice-connections.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  discord_voice_cbs
 
struct  discord_voice
 Discord Voice Connection handle, contain information about its active session. More...
 

Typedefs

typedef void(* voice_idle_cb) (struct discord *client, struct discord_voice *vc, const struct discord_user *bot)
 Idle callback. More...
 
typedef void(* voice_speaking_cb) (struct discord *client, struct discord_voice *vc, const struct discord_user *bot, const u64_snowflake_t user_id, const int speaking, const int delay, const int ssrc)
 Voice Speaking callback. More...
 
typedef void(* voice_client_disconnect_cb) (struct discord *client, struct discord_voice *vc, const struct discord_user *bot, const u64_snowflake_t user_id)
 Voice Client Disconnect callback. More...
 
typedef void(* voice_codec_cb) (struct discord *client, struct discord_voice *vc, const struct discord_user *bot, const char audio_codec[], const char video_codec[])
 Voice Codec callback. More...
 

Enumerations

enum  discord_join_vc_status { DISCORD_JOIN_VC_ERROR = 0, DISCORD_JOIN_VC_JOINED = 1, DISCORD_JOIN_VC_EXHAUST_CAPACITY, DISCORD_JOIN_VC_ALREADY_JOINED }
 

Functions

void discord_voice_set_on_idle (struct discord_voice *vc, voice_idle_cb *callback)
 Set a callback that triggers at every event-loop iteration. More...
 
enum discord_join_vc_status discord_join_vc (struct discord *client, struct discord_message *msg, u64_snowflake_t guild_id, u64_snowflake_t channel_id, bool self_mute, bool self_deaf)
 Send a Voice State Update to Discord. More...
 
void discord_send_speaking (struct discord_voice *vc, enum discord_voice_speaking_flags flag, int delay)
 Notify clients that you are speaking or have stopped speaking. More...
 
void _discord_on_voice_state_update (struct discord *client, struct discord_voice_state *vs)
 Update the voice session with a new session_id. More...
 
void _discord_on_voice_server_update (struct discord *client, u64_snowflake_t guild_id, char token[], char endpoint[])
 Update the voice session with a new token and url. More...
 
void discord_voice_shutdown (struct discord_voice *vc)
 Gracefully exits a ongoing Discord Voice connection. More...
 
void discord_voice_reconnect (struct discord_voice *vc, bool resume)
 Gracefully reconnect a ongoing Discord Voice connection. More...
 
bool discord_voice_is_alive (struct discord_voice *vc)
 Check if a Discord Voice connection is alive. More...
 
void discord_voice_connections_init (struct discord *client)
 Initialize the fields of a Discord Voice Connections handle. More...
 

Detailed Description

File containing internal functions and datatypes for Voice Connections.

Author
cee-studio
Date
21 Jun 2021

Typedef Documentation

◆ voice_client_disconnect_cb

typedef void(* voice_client_disconnect_cb) (struct discord *client, struct discord_voice *vc, const struct discord_user *bot, const u64_snowflake_t user_id)

◆ voice_codec_cb

typedef void(* voice_codec_cb) (struct discord *client, struct discord_voice *vc, const struct discord_user *bot, const char audio_codec[], const char video_codec[])

◆ voice_idle_cb

typedef void(* voice_idle_cb) (struct discord *client, struct discord_voice *vc, const struct discord_user *bot)

Idle callback.

Runs on every WebSockets loop iteration, no trigger required

See also
discord_set_voice_cbs()

◆ voice_speaking_cb

typedef void(* voice_speaking_cb) (struct discord *client, struct discord_voice *vc, const struct discord_user *bot, const u64_snowflake_t user_id, const int speaking, const int delay, const int ssrc)

Function Documentation

◆ _discord_on_voice_server_update()

void _discord_on_voice_server_update ( struct discord client,
u64_snowflake_t  guild_id,
char  token[],
char  endpoint[] 
)

Update the voice session with a new token and url.

Parameters
clientthe client created with discord_init()
guild_idthe guild that houses the voice channel
tokenthe unique token identifier
endpointunique wss url received
Todo:
move to discord-internal.h
Note
will prepend with "wss://" and append with "?v=4"

◆ _discord_on_voice_state_update()

void _discord_on_voice_state_update ( struct discord client,
struct discord_voice_state vs 
)

Update the voice session with a new session_id.

Parameters
clientthe client created with discord_init()
vsthe voice state that has been updated
Todo:
move to discord-internal.h

◆ discord_join_vc()

enum discord_join_vc_status discord_join_vc ( struct discord client,
struct discord_message msg,
u64_snowflake_t  guild_id,
u64_snowflake_t  channel_id,
bool  self_mute,
bool  self_deaf 
)

Send a Voice State Update to Discord.

Necessary to connect to the voice server. When succesful a new voice connection instance will start

Parameters
clientthe client created with discord_init()
msg
Todo:
remove this non-intuitive requirement
Parameters
guild_idthe guild that houses the voice channel
channel_idthe voice channel the client wants to connect to
self_mutetrue will join as mute
self_deaftrue will join as deaf
Returns
enum discord_join_vc_status value

◆ discord_send_speaking()

void discord_send_speaking ( struct discord_voice vc,
enum discord_voice_speaking_flags  flag,
int  delay 
)

Notify clients that you are speaking or have stopped speaking.

Parameters
vcthe VC obtained with discord_join_vc()
flag
delayShould be set to 0.
See also
https://discord.com/developers/docs/topics/voice-connections#speaking
https://github.com/discord/discord-api-docs/issues/859#issuecomment-466602485

◆ discord_voice_connections_init()

void discord_voice_connections_init ( struct discord client)

Initialize the fields of a Discord Voice Connections handle.

Parameters
clientthe client created with discord_init()

◆ discord_voice_is_alive()

bool discord_voice_is_alive ( struct discord_voice vc)

Check if a Discord Voice connection is alive.

Parameters
vcthe VC obtained with discord_join_vc()
Returns
true if WebSockets status is different than WS_DISCONNECTED, false otherwise.

◆ discord_voice_reconnect()

void discord_voice_reconnect ( struct discord_voice vc,
bool  resume 
)

Gracefully reconnect a ongoing Discord Voice connection.

Parameters
vcthe VC obtained with discord_join_vc()
resumetrue to attempt to resume to previous session, false reconnect to a fresh session
Note
Helper around ws_set_action()
See also
websockets.h

◆ discord_voice_set_on_idle()

void discord_voice_set_on_idle ( struct discord_voice vc,
voice_idle_cb callback 
)

Set a callback that triggers at every event-loop iteration.

Parameters
vcthe VC obtained with discord_join_vc()
callbackthe callback that will be executed

◆ discord_voice_shutdown()

void discord_voice_shutdown ( struct discord_voice vc)

Gracefully exits a ongoing Discord Voice connection.

Parameters
vcthe VC obtained with discord_join_vc()
Note
Wraps around ws_set_action()
See also
websockets.h