Skip to content

Commit

Permalink
Improved connection info behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
lotharthesavior committed Feb 24, 2024
1 parent 059a822 commit 4757bbf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@ class Constants
// Action Events

public const ACTION_EVENT_CHANNEL_PRESENCE = 'channel-presence';

// Reactive Actions

public const ACTION_CONNECTION_INFO = 'connection-info';
}
2 changes: 1 addition & 1 deletion src/ConveyorServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private function startServer(): void
$fd = $request->fd;
// @phpstan-ignore-next-line
$this->server->defer(function () use ($fd) {
$action = 'connection-info';
$action = Constants::ACTION_CONNECTION_INFO;
$data = json_encode(['fd' => $fd, 'event' => $action]);
$hash = md5($data . time());
$this->server->push($fd, json_encode([
Expand Down
10 changes: 10 additions & 0 deletions tests/Feature/OpenSwooleSocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ public function testCanAddCustomActionThroughServer()
string $message,
) use ($counter) {
$parsedData = json_decode($message, true);

if ($parsedData['action'] === Constants::ACTION_CONNECTION_INFO) {
return;
}

$counter->add(1);
if ($parsedData['data'] === 'done') {
$counter->add(1);
Expand Down Expand Up @@ -254,6 +259,11 @@ functionToAdd: function (array $data) use ($expectedName) {
$expectedName
) {
$parsedData = json_decode($message, true);

if ($parsedData['action'] === Constants::ACTION_CONNECTION_INFO) {
return;
}

$counter->add(1);
if ($parsedData['data']['users'][1] === $expectedName) {
$counter->add(1);
Expand Down

0 comments on commit 4757bbf

Please sign in to comment.