From e903967befc06d233eb6b0c5b0054c663daa8163 Mon Sep 17 00:00:00 2001 From: Exanlv <51094537+Exanlv@users.noreply.github.com> Date: Sun, 17 Mar 2024 10:13:59 +0100 Subject: [PATCH] Use version in resume url (#82) * Experimental fix for attaching version to resume URL * Fix tests --- src/Gateway/Connection.php | 5 ++++- tests/Gateway/ConnectionTest.php | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Gateway/Connection.php b/src/Gateway/Connection.php index 7a431df5..333e7521 100644 --- a/src/Gateway/Connection.php +++ b/src/Gateway/Connection.php @@ -34,7 +34,8 @@ */ class Connection implements ConnectionInterface { - public const DEFAULT_WEBSOCKET_URL = 'wss://gateway.discord.gg/?v=10'; + public const DEFAULT_WEBSOCKET_URL = 'wss://gateway.discord.gg/'; + private const QUERY_DATA = ['v' => 10]; private const HEARTBEAT_ACK_TIMEOUT = 2.5; @@ -116,6 +117,8 @@ public function resetSequence(): void public function connect(string $url): ExtendedPromiseInterface { + $url .= '?' . http_build_query(self::QUERY_DATA); + return $this->websocket->open($url); } diff --git a/tests/Gateway/ConnectionTest.php b/tests/Gateway/ConnectionTest.php index e9de6492..517d5782 100644 --- a/tests/Gateway/ConnectionTest.php +++ b/tests/Gateway/ConnectionTest.php @@ -37,7 +37,7 @@ public function testGetDefaultUrl(): void new DataMapper(new NullLogger()) ); - $this->assertMatchesRegularExpression('/wss:\/\/gateway.discord.gg\/\?v=(\d+)/', $connection->getDefaultUrl()); + $this->assertEquals('wss://gateway.discord.gg/', $connection->getDefaultUrl()); } public function testSequence(): void @@ -73,7 +73,7 @@ public function testConnect(): void $websocket->expects() ->open() - ->with('::ws url::') + ->with('::ws url::?v=10') ->andReturns(PromiseFake::get('::return::')) ->once();