From 39a269b207262400ebeca03c176431cda4500d9c Mon Sep 17 00:00:00 2001 From: Alexander Pankratov Date: Sun, 12 Jan 2020 23:22:41 +0300 Subject: [PATCH] websocket client example update --- README.md | 4 ++-- examples/websocket-events.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0eb71bf..e91d66a 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,8 @@ Fast, simple, async php telegram api server: * EventHandler updates via websocket. Connect to `ws://127.0.0.1:9503/events`. You will get all events in json. Each event stored inside object, where key is name of session which created event. - When using CombinedAPI (multiple account) name of session can be added to path of websocket endpoint. - `ws://127.0.0.1:9503/events/session_name`. This endpoint will emmit events only from given session. + When using CombinedAPI (multiple account) name of session can be added to path of websocket endpoint: + `ws://127.0.0.1:9503/events/session_name`. This endpoint will send events only from given session. PHP websocket client example: [websocket-events.php](https://github.com/xtrime-ru/TelegramApiServer/blob/master/examples/websocket-events.php) diff --git a/examples/websocket-events.php b/examples/websocket-events.php index 159201a..ffa3108 100644 --- a/examples/websocket-events.php +++ b/examples/websocket-events.php @@ -26,6 +26,10 @@ Amp\Loop::run(function () use($options) { /** @var Connection $connection */ $connection = yield connect($options['url']); + $connection->onClose(static function() use($connection) { + printf("Connection closed. Reason: %s\n", $connection->getCloseReason()); + }); + echo 'Waiting for events...' . PHP_EOL; while ($message = yield $connection->receive()) { /** @var Message $message */