To simplify our pubsub integration for the chat app, we're going to define a class that abstracts the implementation details of pubsub module into simple operations like join, leave, etc. Once we implement pubsub we will replace our custom protocol with the custom chat topic /chat/1.0.0
that all nodes will connect to join the group chat.
- Create a new file named
chat.js
- Define a class
Chat
with a constructor that takes a libp2p node and a topic and then starts the node if it's not already active - Add dummy class functions for
start
,stop
,join
,leave
, andsend
- Hint, make sure these functions are asynchronous since this is peer to peer and things don't always happen as quickly as we like.
- Make the class the default export
- Create a const export
TOPIC
and initialise it with the chat topic (/chat/1.0.0
)