websocket client example update

This commit is contained in:
Alexander Pankratov 2020-01-12 23:22:41 +03:00
parent a8997ed469
commit 39a269b207
2 changed files with 6 additions and 2 deletions

View File

@ -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)

View File

@ -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 */