Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive voice implementation (feature/voice) #457

Merged
merged 119 commits into from
Apr 16, 2024
Merged

Conversation

kozabrada123
Copy link
Member

@kozabrada123 kozabrada123 commented Dec 16, 2023

(opening this into a pr to track changes, progress, todos and merge conflicts)

This pr (when complete) aims to add voice channel and call support to Chorus via Discord's UDP api.

Current todo:

Features:

  • Voice gateway connection and heartbeating
  • Voice UDP connection
  • Ip Discovery
  • Select protocol
  • Receiving and deserializing audio
  • Audio decryption
  • Audio encryption
  • Sending and serializing audio
  • Public API

Docs:

  • Documentation on related structs, methods etc
  • Usage examples

Compatibility:

  • Gateway WASM combatibility
  • UDP WASM compatibility - the browser cannot do udp.

Code quality:

  • Fix or at least clarify FIXMEs

UDP vs Webrtc

User accounts sometimes use an undocumented Webrtc api for voice and video, while bots use the documented UDP api.
I've decided to implement the UDP api for now, since Webrtc is much more complex and less documented.
We may want to look into Webrtc aswell in the future.

Architecture and public API

My current plan is to have four parts of the impl: the Voice Gateway, voice UDP, Voice Data and Voice Handler

  • Voice Handler would handle coordinating and initializing the Gateway and UDP connections,
  • Voice Data is a struct, which contains needed shared data, such as the encryption key, ssrc, session id, ip & port, etc..
  • Voice Gateway and Voice UDP are the communication channels for Discord's api, using websockets and udp respectively.

The user can then interact with the Voice Gateway to issue gateway commands and receive voice context.
The voice UDP handler would expose a slightly higher level api, with listener events for decrypted and deserialized audio as well as a method which serializes, encrypts and sends audio.

src/errors.rs Outdated Show resolved Hide resolved
src/errors.rs Outdated Show resolved Hide resolved
src/voice/voice_data.rs Outdated Show resolved Hide resolved
src/voice/voice_data.rs Outdated Show resolved Hide resolved
src/voice/udp/handle.rs Outdated Show resolved Hide resolved
src/voice/udp/handle.rs Outdated Show resolved Hide resolved
src/voice/udp/handler.rs Outdated Show resolved Hide resolved
src/voice/udp/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@bitfl0wer bitfl0wer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Amazing work :)
I'd only like the 1-2 questions I had and the spelling mistake thingies to be resolved to be merging, but otherwise this looks great! :D

kozabrada123 and others added 2 commits April 16, 2024 14:47
Co-authored-by: Flori <[email protected]>
@bitfl0wer bitfl0wer mentioned this pull request Apr 16, 2024
2 tasks
src/gateway/gateway.rs Outdated Show resolved Hide resolved
@kozabrada123 kozabrada123 merged commit 56b2381 into dev Apr 16, 2024
6 checks passed
bitfl0wer added a commit that referenced this pull request Apr 16, 2024
## Release 0.15.0

### TODO:
- [x] Merge #457  
- [x] Merge #489 

## Changes

- Primitive voice support: #457
- Cleaner code
    - Replace `Arc<RwLock<T>>` with `Shared<T>`: #466 
    - More, better documentation
    - More tests
    - Fix some typos
    - Make gateway `close()` code cleaner
- Remove `#[derive(Eq)]` from types which falsely had this trait derived
- Change license from AGPL-3 to MPL-2.0: #477 
- Bump `whoami`, `mio`, `h2` to fix CVEs
- Bump versions of used GitHub Actions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: In Progress Type: Enhancement Enhances an existing feature or behaviour. Type: New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants