mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-06 09:56:09 +00:00
Added VoiceClient.latency and VoiceClient.average_latency
This also implements the heartbeating a bit more consistent to the official Discord client.
This commit is contained in:
@ -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`.
|
||||
|
||||
|
Reference in New Issue
Block a user