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

Use Discord heartbeat interval in audio. #2765

Merged
merged 2 commits into from
Nov 18, 2023
Merged

Conversation

josago97
Copy link
Contributor

Description

When an audio connection is created, the heartbeat interval provided by Discrod in its "Hello" message is used.

When it comes to sending the heartbeats, both in the audio and in the Gateway, if these are not sent within the interval, Discord closes the connection. Therefore, a variable has been introduced to reduce this interval by a percentage and thus always ensure that the heartbeat is going to be sent before time runs out.

Modified the code of the AudioCLient class a bit to make it "more readable", some magic numbers have been turned into constants, it doesn't make sense to use "var" instead of "int", "returns" which do nothing because they are already at the end of the method.

P.S. The audio system needs a reconnection system. The only thing this PR does is lower the probability of socket disconnection. In the event that the session times out, or the server does not respond to the heartbeat or anything other than closing the socket, the audio transmission is interrupted and disconnected from the voice channel. If someone implements the audio reconnection it would be appreciated :)

Changes

  • Use Discord heartbeat interval in audio.
  • Reduce heartbeat interval to ensure Discord receives it within range.
  • Refactor some AudioClient code.

Reduce heartbeat interval to ensure Discord receives it within range.
Refactor some AudioClient code.
@quinchs quinchs enabled auto-merge (squash) November 18, 2023 20:49
@quinchs quinchs merged commit 9cedfbc into discord-net:dev Nov 18, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants