1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-30 18:53:30 +00:00
arikawa/voice
2020-04-21 16:37:22 -06:00
..
commands.go Improvements to the way voice waits for events 2020-04-21 16:37:22 -06:00
connection.go Improvements to the way voice waits for events 2020-04-21 16:37:22 -06:00
events.go Add janky voice support 2020-04-21 16:37:22 -06:00
op.go Improvements to the way voice waits for events 2020-04-21 16:37:22 -06:00
ops.go Add janky voice support 2020-04-21 16:37:22 -06:00
packet.go Add janky voice support 2020-04-21 16:37:22 -06:00
README.md Improvements to voice/README.md 2020-04-21 16:37:22 -06:00
udp.go Improvements to the way voice waits for events 2020-04-21 16:37:22 -06:00
voice.go Improvements to the way voice waits for events 2020-04-21 16:37:22 -06:00

Voice

Terminology

  • Discord Gateway - The standard Discord Gateway users connect to and receive update events from
  • Discord Voice Gateway - The Discord Voice gateway that allows voice connections to be configured
  • Voice Server - What the Discord Voice Gateway allows connection to for sending of Opus voice packets over UDP
  • Voice Packet - Opus encoded UDP packet that contains audio
  • Application - Could be a custom Discord Client or Bot (nothing that is within this package)
  • Library - Code within this package

Connection Flow

  • The application would get a new *Voice instance by calling NewVoice()
  • When the application wants to connect to a voice channel they would call JoinChannel() on the stored *Voice instance

  • The library sends a Voice State Update to the Discord Gateway
  • The library waits until it receives a Voice Server Update from the Discord Gateway
  • Once a Voice Server Update event is received, a new connection is opened to the Discord Voice Gateway

  • When the connection is opened an Identify Event or Resume Event is sent to the Discord Voice Gateway depending on if the library is reconnecting
  • The Discord Voice Gateway should respond with a Hello Event which will be used to create a new *gateway.Pacemaker and start sending heartbeats to the Discord Voice Gateway

  • The Discord Voice Gateway should also respond with a Ready Event once the connection is opened, providing the required information to connect to a Voice Server
  • Using the information provided in the Ready Event, a new UDP connection is opened to the Voice Server and IP Discovery occurs
  • After IP Discovery returns the Application's external ip and port it connected to the Voice Server with, the library sends a Select Protocol Event to the Discord Voice Gateway
  • The library waits until it receives a Session Description Event from the Discord Voice Gateway
  • Once the Session Description Event is received, Speaking Events and Voice Packets can begin to be sent to the Discord Voice Gateway and Voice Server respectively

Usage

  • The application would get a new *Voice instance by calling NewVoice() and keep it stored for when it needs to open voice connections
  • When the application wants to connect to a voice channel they would call JoinChannel() on the stored *Voice instance
  • JoinChannel() will block as it follows the Connection Flow, returning an error if one occurs and a *Connection if it was successful
  • The application should now call *Connection#Speaking() with the wanted voice flag (Microphone, Soundshare, Priority)
  • The application can now send Voice Packets to the *Connection#OpusSend channel which will be sent to the Voice Server
  • When the application wants to stop sending Voice Packets they should call *Connection#StopSpeaking(), any required voice cleanup (closing streams, etc), then *Connection#Disconnect()

Examples

Coming SoonTM