Skip to content

Commit 6f03ace

Browse files
committed
fix dispatchs not working ig
1 parent 18ded59 commit 6f03ace

File tree

1 file changed

+38
-28
lines changed

1 file changed

+38
-28
lines changed

discord/voice/state.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def __init__(
241241
self._end: threading.Event = threading.Event()
242242

243243
def decode(self, frame: RawData) -> None:
244+
_log.debug('Decoding frame %s', frame)
244245
if not isinstance(frame, RawData):
245246
raise TypeError(
246247
f"expected a RawData object, got {frame.__class__.__name__}"
@@ -407,6 +408,7 @@ def stop_record_socket(self) -> None:
407408
self.sinks.clear()
408409

409410
def handle_voice_recv_packet(self, packet: bytes) -> None:
411+
_log.debug('Handling voice packet %s', packet)
410412
if packet[1] != 0x78:
411413
# We should ignore any payload types we do not understand
412414
# Ref: RFC 3550 5.1 payload type
@@ -429,7 +431,7 @@ def is_first_packet(self) -> bool:
429431
return not self.user_voice_timestamps or not self.sync_recording_start
430432

431433
def dispatch_packet_sinks(self, data: RawData) -> None:
432-
434+
_log.debug('Dispatching packet %s in all sinks', data)
433435
if data.ssrc not in self.user_ssrc_map:
434436
if self.is_first_packet():
435437
self.first_received_packet_ts = data.receive_time
@@ -480,23 +482,28 @@ async def _dispatch_packet(self, data: RawData) -> None:
480482

481483
sink.dispatch("unfiltered_voice_packet_receive", user, data)
482484

483-
futures = [
484-
self.loop.create_task(
485-
utils.maybe_coroutine(fil.filter_packet, sink, user, data)
486-
)
487-
for fil in sink._filters
488-
]
489-
strat = sink._filter_strat
485+
if sink._filters:
486+
futures = [
487+
self.loop.create_task(
488+
utils.maybe_coroutine(fil.filter_packet, sink, user, data)
489+
)
490+
for fil in sink._filters
491+
]
492+
strat = sink._filter_strat
490493

491-
done, pending = await asyncio.wait(futures)
494+
done, pending = await asyncio.wait(futures)
492495

493-
if pending:
494-
for task in pending:
495-
task.set_result(False)
496+
if pending:
497+
for task in pending:
498+
task.set_result(False)
499+
500+
done = (*done, *pending)
496501

497-
done = (*done, *pending)
502+
result = strat([f.result() for f in done])
503+
else:
504+
result = True
498505

499-
if strat([f.result() for f in done]):
506+
if result:
500507
sink.dispatch("voice_packet_receive", user, data)
501508
sink._call_voice_packet_handlers(user, data)
502509

@@ -570,25 +577,28 @@ async def _dispatch_speaking_state(
570577

571578
sink.dispatch("unfiltered_speaking_state_update", resolved, before, after)
572579

573-
futures = [
574-
self.loop.create_task(
575-
utils.maybe_coroutine(
576-
fil.filter_speaking_state, sink, resolved, before, after
580+
if sink._filters:
581+
futures = [
582+
self.loop.create_task(
583+
utils.maybe_coroutine(fil.filter_packet, sink, resolved, before, after)
577584
)
578-
)
579-
for fil in sink._filters
580-
]
581-
strat = sink._filter_strat
585+
for fil in sink._filters
586+
]
587+
strat = sink._filter_strat
582588

583-
done, pending = await asyncio.wait(futures)
589+
done, pending = await asyncio.wait(futures)
584590

585-
if pending:
586-
for task in pending:
587-
task.set_result(False)
591+
if pending:
592+
for task in pending:
593+
task.set_result(False)
588594

589-
done = (*done, *pending)
595+
done = (*done, *pending)
596+
597+
result = strat([f.result() for f in done])
598+
else:
599+
result = True
590600

591-
if strat([f.result() for f in done]):
601+
if result:
592602
sink.dispatch("speaking_state_update", resolved, before, after)
593603
sink._call_speaking_state_handlers(resolved, before, after)
594604

0 commit comments

Comments
 (0)