rockets
v1.2.4
Published
Server-side client for rockets/rockets
Downloads
23
Readme
This is a client for rockets/rockets.
Demo
See rockets/demo.
Installation
npm install rockets
Usage
var Rockets = require('rockets');
var client = new Rockets();
// Register events on the client.
client.on('connect', function() {
var include = {
// Only receive comments in r/programming.
subreddit: 'programming',
// Only receive comments that contain the pattern 'rockets'.
contains: [
'rockets',
]
};
var exclude = {
// Skip comments that contain the word "hack".
contains: [
'hack',
]
};
// Subscribe to the 'comments' channel.
client.subscribe('comments', include, exclude);
});
client.on('comment', function(comment) {
// Do something using the comment data.
});
// Initiate the client's socket connection.
client.connect();
Events
Events can be registered with client.on('event', handler)
.
| Event | Arguments | Description | |------------|------------|-------------------------------------------------| | connect | | Connection to the server has been established | | disconnect | | Connection to the server has been lost | | error | error | Error has occurred | | model | model | Received model, either post or comment | | comment | model | Received a comment | | post | model | Received a post |
Functions
| Name | Arguments | Description |
|------------|--------------------|-------------------------------------------------|
| subscribe | channel, [include [, exclude]] | Subscribes to a channel, with optional include and exclude rules |
| available | | Returns true
if the socket connection is open |
| close | | Close the connection to the server |
Credits
Illustrations by Ken Samonte.