class Discord::VoiceClient

Defined in:

discordcr/voice.cr

Constant Summary

ENCRYPTED_MODE = "xsalsa20_poly1305"

The mode that tells Discord we want to send encrypted audio

HEARTBEAT_JSON = {op: OP_HEARTBEAT, d: nil}.to_json

The heartbeat is the same every time, so it can be a constant

OP_HEARTBEAT = 3
OP_HELLO = 8
OP_IDENTIFY = 0
OP_READY = 2
OP_SELECT_PROTOCOL = 1
OP_SESSION_DESCRIPTION = 4
OP_SPEAKING = 5
UDP_PROTOCOL = "udp"

Constructors

Instance Method Summary

Constructor Detail

def self.new(payload : Discord::Gateway::VoiceServerUpdatePayload, session : Discord::Gateway::Session, user_id : UInt64 | Snowflake, logger = Logger.new(STDOUT)) #

Creates a new voice client. The payload should be a payload received from Discord as part of a VOICE_SERVER_UPDATE dispatch, received after sending a voice state update (gateway op 4) packet. The session should be the session currently in use by the gateway client on which the aforementioned dispatch was received, and the user_id should be the user ID of the account on which the voice client is created. (It is received as part of the gateway READY dispatch, for example)


[View source]

Instance Method Detail

def close #

Closes the VWS connection, in effect disconnecting from voice.


[View source]
def on_ready(&ready_handler : -> ) #

Sets the handler that should be run once the voice client has connected successfully.


[View source]
def play_opus(buf : Bytes) #

Plays a single opus packet


[View source]
def run #

Initiates the connection process and blocks forever afterwards.


[View source]
def send_speaking(speaking : Bool, delay : Int32 = 0) #

Sends a packet to indicate to Discord whether or not we are speaking right now


[View source]