Понимание событий Mercure - PullRequest
       33

Понимание событий Mercure

0 голосов
/ 24 марта 2020

Привет, я новичок в Mercure и получил базовый пример чата c, но я теряюсь в плане создания для него дополнительной функциональности.

В нашем примере

 const es = new EventSource(subscribeURL);

, который дает нам доступ к некоторым данным сообщения

es.onmessage = ({data}) => {
    const {username, message} = JSON.parse(data)
};
li.append(document.createTextNode(`<${username}> ${message}`))

Это имеет смысл, но доступные данные кажутся ограниченными. Например, веб-сокеты Ratchet четко документируют:

onOpen (ConnectionInterface $conn) - A new client connection has been opened
onClose (ConnectionInterface $conn) - A client connection has been closed
onCall (ConnectionInterface $conn, string $id, Topic $topic, array $params) - The client has made an RPC to the server. You should send a callResult or callError in return
onSubscribe (ConnectionInterface $conn, Topic $topic) - The client has subscribed to a channel, expecting to receive events published to the given $topic
onUnsubscribe (ConnectionInterface $conn, Topic $topic) - The client unsubscribed from a channel, opting out of receiving events from the $topic
onPublish (ConnectionInterface $conn, Topic $topic, string $event) - The user publishes data to a $topic. You should in return an Event Command to Connections who have Subscribed to the $topic
onError (ConnectionInterface $conn, Exception $error) - An error has occurred with a Connection

Сервер Mercure, очевидно, отслеживает соединения и подпрограммы, но я не могу найти или понять документацию, которая позволит мне работать с такими событиями, как подписка или соединение закрыто.

time="2020-03-24T17:14:36Z" level=info msg="Subscriber disconnected" remote_addr="" subscriber_topics="[chat]"

В одном примере это может означать, что когда кто-либо подключается или отключается от чата, мы можем отправить уведомление другим участникам.

Чего мне не хватает? Как я могу получить доступ к событиям без сообщений? Спасибо.

...