Skip to content

Commit

Permalink
laravel-chat: added interval
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfroeller committed Jun 13, 2024
1 parent 7c52cec commit 650dfb3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion laravel-chat/app/Livewire/ChatClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function connectToWebSockets()
$modifiedChats[$monitorId] = $chat;
$modifiedChats[$monitorId]['websocket'] = new WebSocketClient($wsUri);

$modifiedChats[$monitorId]['websocket'] // TODO: implement ping - ping every 2 or 3 seconds
$modifiedChats[$monitorId]['websocket']
->addMiddleware(new WebSocketMiddleware\CloseHandler())
->onText(function (WebSocketClient $client, WebSocketConnection $connection, WebSocketMessage $message) {
$monitorId = self::getMonitorOfClient($client);
Expand All @@ -207,6 +207,11 @@ public function connectToWebSockets()
$this->dispatch('messageReceived', $messageAsHTML);
})
->start();

while ($modifiedChats[$monitorId]['websocket']->isConnected()) { // TODO: implement ping - ping every 50 to 59 seconds
self::sendMessage($monitorId, 'ping');
sleep(10);
}
}

$this->chats->setChats($modifiedChats);
Expand Down

0 comments on commit 650dfb3

Please sign in to comment.