mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
Merge pull request #8943 from appwrite/feat-realtime-ping-pong
feat: realtime ping pong
This commit is contained in:
commit
cca5606b70
3 changed files with 31 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -16,3 +16,4 @@ dev/yasd_init.php
|
|||
.phpunit.result.cache
|
||||
Makefile
|
||||
appwrite.json
|
||||
.zed/
|
||||
|
|
@ -592,9 +592,12 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re
|
|||
}
|
||||
|
||||
switch ($message['type']) {
|
||||
/**
|
||||
* This type is used to authenticate.
|
||||
*/
|
||||
case 'ping':
|
||||
$server->send([$connection], json_encode([
|
||||
'type' => 'pong'
|
||||
]));
|
||||
|
||||
break;
|
||||
case 'authentication':
|
||||
if (!array_key_exists('session', $message['data'])) {
|
||||
throw new Exception(Exception::REALTIME_MESSAGE_FORMAT_INVALID, 'Payload is not valid.');
|
||||
|
|
|
|||
|
|
@ -111,6 +111,30 @@ class RealtimeCustomClientTest extends Scope
|
|||
$client->close();
|
||||
}
|
||||
|
||||
public function testPingPong()
|
||||
{
|
||||
$client = $this->getWebsocket(['files'], [
|
||||
'origin' => 'http://localhost'
|
||||
]);
|
||||
$response = json_decode($client->receive(), true);
|
||||
|
||||
$this->assertArrayHasKey('type', $response);
|
||||
$this->assertArrayHasKey('data', $response);
|
||||
$this->assertEquals('connected', $response['type']);
|
||||
$this->assertNotEmpty($response['data']);
|
||||
$this->assertCount(1, $response['data']['channels']);
|
||||
$this->assertContains('files', $response['data']['channels']);
|
||||
|
||||
$client->send(\json_encode([
|
||||
'type' => 'ping'
|
||||
]));
|
||||
|
||||
$response = json_decode($client->receive(), true);
|
||||
$this->assertEquals('pong', $response['type']);
|
||||
|
||||
$client->close();
|
||||
}
|
||||
|
||||
public function testManualAuthentication()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
|
|
|||
Loading…
Reference in a new issue