yarn add @replit/crosis @replit/protocol
Crosis relies on the
@replit/protocol package as a peer dependency. https://github.com/replit/protocol
You should probably familiarize yourself with the protocol before trying to use it. Crosis is just a client that helps you connect and communicate with the container using the protocol.
Read about the protocol here http://protodoc.turbio.repl.co
Usage and concepts
The central concept is a "channel" that you can send commands to and receive commands from. Communicating with channels requires a network connection. The goal of this client is to provide an API to manage what happens when a disconnect and/or reconnect happens. How you handle this is up to you and depends on the desired UX. In some cases you'll want to disable UI to prevent any new messages being sent when offline and then re-enable once connected agian. In other cases you might want to give the user the illusion that they are connected and queue message locally while disconnected and send them once reconnected.
When a client successfully connects (
client.open) the provided callback function is called and passed a channel (this is channel 0). Other channels for specific services can be opened by calling
client.openChannel. The signature of the callback function for
openChannel matches the one from
The callback functions provided to
openChannel can optionally return a function that will be called when the client or channel is closed. This is useful for cleaning up any logic that depends on a channel being available.