Super fast, and easy to use; realtime messaging.
CatSnake is a package built on top of WebSockets to allow for a publish & subscribe style messaging for quickly building fast realtime applications. Catsnake also utilizes MessagePack so package sizes are very small making Catsnake very fast.
For detailed documentation visit this link.
For quick use you can simply include catsnke in your
For installation with npm just install with
npm i --save pubsub
and then require it
const PubSub = require'pubsub';
Now connect to the PubSub server. See pubsub-server to run your own server, Otherwise you can use the example below to use our free server. (note that channel names may already be reserved, so be creative!)
const cs = 'ws://catsnake.io:3081'commonName: 'A Random Catsnake';// It is best practice to wrap the rest of your Catsnake code in the on method.// this ensures that you're connected to the websocket server before executing.cson =>// Your code here.;
Before you can start sending messages, you should subscribe to a channel (but you don't have to). Don't worry, it's super easy.
cssubscribe'General' data => console.logdata;
Now that you've subscibed to a channel, let's publish a message to all of the other subscribers, and ourselves ofcourse.
cspublish'General'message: 'Ahh! Your dog is attacking me! What is it with mail men and dogs anyways?'thenmsg => console.log'Yay, the server got our message.' ;
Wanna fetch some history? Easy.
History will be sent back in the subscribe method with the
metadata.type of 'history'.
Nice, now let's get info from the channel, this will return information like connected clients, author, etc.
Catsnake gives you multiple options for access control to a channel.
Denying a client access to a channel protected by access control is easy
csdeny'General' 'client-123215' 'secretKey';
Granting a client access to a channel protected by access control is just as simple.
csgrant'General' 'client-123215' 'secretKey';
Before exiting your application you should unsubscribe from the channel. This will leave your client in an offline state but
you can later reconnect with the same client id via the
new Catsnake method, we will go over this more in the advanced
In the event that you are trying to access a private server, after connecting to the server be sure to authenticate with the correct secret.
Catsnake also provides chaining for most methods, so you can prepend authenticate to the beginning of your subscribe function to keep things clean!
For catsnake to keep up to date, and become the best tool it can be; we need contributors like you! We know trying to add your own work might be scary, what will people say? Is my code quality good enough? What if I look dumb? It's fine! Just go ahead and submit your work, worst case we'll tidy things up a bit; I'm positive we can benifit from seeing your ideas.
See the Contributing.md over here for a full list of instructions.