Node.js library for Scaledrone Realtime Messaging Service
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.eslintrc.json
.gitignore init Oct 30, 2015
README.md
index.js Allow publishing strings and numbers Sep 23, 2018
is_json.js
package.json Up version Sep 23, 2018

README.md

Scaledrone Node.js Push API

Official Scaledrone Node.js pushing library

Allows for usage of all Scaledrone's REST API methods.

For the Node.js WebSocket API Client check out this link.

Installation

npm install scaledrone-node-push --save

Usage

Create a new instance of Scaledrone passing it the channelId and secretKey that you can find from the channel's page

const Scaledrone = require('scaledrone-node-push');
const sd = new Scaledrone({
  channelId: 'CHANNEL_ID',
  secretKey: 'SECRET_KEY'
});

Publishing a message

const message = {foo: 'bar'};
const room = 'notifications';
sd.publish(room, message, function(error) {
  // check for errors
});

Publishing the same message to multiple rooms

const message = {foo: 'bar'}
const rooms = ['notifications', 'lounge'];
sd.publish(rooms, message, function(error) {
  // check for errors
});

Get channel stats

sd.channelStats(function(error, reply) {
  // check for errors
  console.log(reply); // { users_count: 2 }
});

Getting the list of users from all rooms

sd.members(function(error, reply) {
  // check for errors
  console.log(reply); // ['bcI:GPhz6A2T', 'b58:fnaJaEfh']
});

Getting the list of rooms that have users in them

sd.rooms(function(error, reply) {
  // check for errors
  console.log(reply); // ["room1", "room2"]
});

Getting the list of users in a room

sd.roomMembers('my-room', function(error, reply) {
  // check for errors
  console.log(reply); // ['bcI:GPhz6A2T', 'b58:fnaJaEfh']
});

Getting the list of rooms and their members

sd.allRoomMembers(function(error, reply) {
  // check for errors
  console.log(reply); // {"room1": ["user1", "user2"], "room2": ["user1"]}
});