diff options
| author | Fwf <[email protected]> | 2020-01-25 16:24:44 +0000 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-04-04 03:00:27 -0400 |
| commit | fa34d357a1c28a48210e68e4b7b1f32320e44b9b (patch) | |
| tree | b9dd9674e46f01675d99f664e3e80e9f6ecaccf9 /discord/voice_client.py | |
| parent | [commands] Implement `commands.before/after_invoke` (diff) | |
| download | discord.py-fa34d357a1c28a48210e68e4b7b1f32320e44b9b.tar.xz discord.py-fa34d357a1c28a48210e68e4b7b1f32320e44b9b.zip | |
Added VoiceClient.latency and VoiceClient.average_latency
This also implements the heartbeating a bit more consistent to the
official Discord client.
Diffstat (limited to 'discord/voice_client.py')
| -rw-r--r-- | discord/voice_client.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/discord/voice_client.py b/discord/voice_client.py index 091fe261..757f7858 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -57,7 +57,6 @@ try: except ImportError: has_nacl = False - log = logging.getLogger(__name__) class VoiceClient: @@ -207,6 +206,22 @@ class VoiceClient: self._handshake_complete.set() + @property + def latency(self): + """:class:`float`: Latency between a HEARTBEAT and a HEARTBEAT_ACK in seconds. + + This could be referred to as the Discord Voice WebSocket latency and is + an analogue of user's voice latencies as seen in the Discord client. + """ + ws = self.ws + return float("inf") if not ws else ws.latency + + @property + def average_latency(self): + """:class:`float`: Average of most recent 20 HEARTBEAT latencies in seconds.""" + ws = self.ws + return float("inf") if not ws else ws.average_latency + async def connect(self, *, reconnect=True, _tries=0, do_handshake=True): log.info('Connecting to voice...') try: @@ -342,7 +357,6 @@ class VoiceClient: return header + box.encrypt(bytes(data), bytes(nonce)).ciphertext + nonce[:4] - def play(self, source, *, after=None): """Plays an :class:`AudioSource`. |