Skip to content

Instantly share code, notes, and snippets.

@cgbystrom
Created February 20, 2011 19:17
Show Gist options
  • Save cgbystrom/836224 to your computer and use it in GitHub Desktop.
Save cgbystrom/836224 to your computer and use it in GitHub Desktop.
Quick API overview of node-beaconpush
var bp = require('beaconpush');
// Create a new client
var beaconpush = new bp.Client('<your-api-key>', '<your-secret-key>');
// Get number of users currently connected to your site
beaconpush.usersConnected(function (numConnected) {
console.log('There are ' + numConnected + ' users online');
});
// Get a user object where you do user operations
var user = beaconpush.user('julia');
// Send a stock quote to user 'julia'
user.send({stock: {symbol: "GOOG", quote: 34.2}}, function (err, numDelivered) {
console.log('Delivered ' + numDelivered + ' message(s)');
});
// Check if user is online
user.isConnected(function (err, connected) {
console.log('User ' + user.name + ' is ' + (connected ? 'connected' : 'not connected'));
});
// Disconnect user
user.disconnect(function (err, connected) {
console.log('User ' + user.name + ' was disconnected');
});
// Get a channel object for doing channel operations
var channel = beaconpush.channel('chat');
// Send a chat message to channel
channel.send({chatMessage: {to: "romeo", from: "julia", message: "Oh, Romeo!"}}, function (err, numDelivered) {
console.log('Delivered ' + numDelivered + ' message(s)');
});
// Get users connected to a channel
channel.usersConnected(function (err, users) {
console.log('Users online ' + users);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment