Skip to content

Commit f1812bb

Browse files
committed
handleResume
1 parent 8bc7c4d commit f1812bb

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

  • src/Discord/Voice/Client

src/Discord/Voice/Client/WS.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,19 @@ public function handleConnection(WebSocket $ws): void
220220

221221
$ws->on('close', [$this, 'handleClose']);
222222

223-
$this->handleSendingOfLoginFrame();
223+
if (! $this->sentLoginFrame) {
224+
$this->handleSendingOfLoginFrame();
225+
$this->sentLoginFrame = true;
226+
} elseif (isset(
227+
$this->data['token'],
228+
$this->data['seq'],
229+
$this->discord->voice_sessions[$this->vc->channel->guild_id]
230+
)) {
231+
$this->handleResume();
232+
} else {
233+
$this->discord->getLogger()->debug('existing voice session or data not found, re-sending identify', ['guild_id' => $this->vc->channel->guild_id]);
234+
$this->handleSendingOfLoginFrame();
235+
}
224236
}
225237

226238
/**
@@ -615,4 +627,24 @@ public function handleSendingOfLoginFrame(): void
615627
$this->sentLoginFrame = true;
616628
$this->vc->sentLoginFrame = true;
617629
}
630+
631+
/**
632+
* Resumes a previously established voice connection.
633+
*/
634+
protected function handleResume(): void
635+
{
636+
$payload = Payload::new(
637+
Op::VOICE_RESUME,
638+
[
639+
'server_id' => $this->vc->channel->guild_id,
640+
'session_id' => $this->discord->voice_sessions[$this->vc->channel->guild_id],
641+
'token' => $this->data['token'],
642+
'seq_ack' => $this->data['seq'],
643+
]
644+
);
645+
646+
$this->discord->logger->debug('sending identify (resume)', ['packet' => $payload->__debugInfo()]);
647+
648+
$this->send($payload);
649+
}
618650
}

0 commit comments

Comments
 (0)