Any Channel client has a few key responsibilities that should be followed for all behavior to work as expected:
- Connect to the server and maintain the connection by using a heartbeat.
- Join the requested topics.
- Push messages to a topic and optionally handle responses.
- Receive messages from a topic.
- Handle disconnection and other errors gracefully and try to maintain a connection whenever possible.
Let’s connect to the
PingChannel that we built earlier in the chapter. We’ll push a
ping event and receive a reply from the server, which we will process on the web page.