Skip to content

Repository files navigation

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:

constScaledrone=require('scaledrone-node-push');constsd=newScaledrone({channelId: 'CHANNEL_ID',secretKey: 'SECRET_KEY'});

Publishing a message

Callback style

constmessage={foo: 'bar'};constroom='notifications';sd.publish(room,message,function(error,reply){if(error){console.error(error);return;}console.log('Message published!',reply);});

Async/await style

(async()=>{try{constmessage={foo: 'bar'};constroom='notifications';constreply=awaitsd.publish(room,message);console.log('Message published!',reply);}catch(err){console.error(err);}})();

Publishing the same message to multiple rooms

Callback style

constmessage={foo: 'bar'};constrooms=['notifications','lounge'];sd.publish(rooms,message,function(error,reply){if(error){console.error(error);return;}console.log('Published to multiple rooms!',reply);});

Async/await style

(async()=>{constmessage={foo: 'bar'};constrooms=['notifications','lounge'];try{constreply=awaitsd.publish(rooms,message);console.log('Published to multiple rooms!',reply);}catch(err){console.error(err);}})();

Get channel stats

// Callbacksd.channelStats(function(error,reply){if(error)returnconsole.error(error);console.log(reply);// { users_count: 2 }});// Async/awaitconststats=awaitsd.channelStats();console.log(stats);

Getting the list of users from all rooms

// Callbacksd.members(function(error,reply){if(error)returnconsole.error(error);console.log(reply);// ['bcI:GPhz6A2T', 'b58:fnaJaEfh']});// Async/awaitconstmembers=awaitsd.members();console.log(members);

Getting the list of rooms that have users in them

// Callbacksd.rooms(function(error,reply){if(error)returnconsole.error(error);console.log(reply);// ["room1", "room2"]});// Async/awaitconstrooms=awaitsd.rooms();console.log(rooms);

Getting the list of users in a room

// Callbacksd.roomMembers('my-room',function(error,reply){if(error)returnconsole.error(error);console.log(reply);// ['bcI:GPhz6A2T', 'b58:fnaJaEfh']});// Async/awaitconstmembers=awaitsd.roomMembers('my-room');console.log(members);

Getting the list of rooms and their members

// Callbacksd.allRoomMembers(function(error,reply){if(error)returnconsole.error(error);console.log(reply);// {"room1": ["user1", "user2"], "room2": ["user1"]}});// Async/awaitconstall=awaitsd.allRoomMembers();console.log(all);

About

Node.js library for Scaledrone Realtime Messaging Service

Resources

Stars

4 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages