https://github.com/scaledrone/node-push
Node.js library for Scaledrone Realtime Messaging Service
https://github.com/scaledrone/node-push
Last synced: 2 months ago
JSON representation
Node.js library for Scaledrone Realtime Messaging Service
- Host: GitHub
- URL: https://github.com/scaledrone/node-push
- Owner: ScaleDrone
- Created: 2015-10-30T18:21:31.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-23T05:58:43.000Z (over 6 years ago)
- Last Synced: 2025-01-25T11:44:00.566Z (4 months ago)
- Language: JavaScript
- Homepage: https://www.scaledrone.com
- Size: 7.81 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Scaledrone Node.js Push API
Official Scaledrone Node.js pushing library
Allows for usage of all Scaledrone's [REST API](https://www.scaledrone.com/docs/rest) methods.
For the Node.js WebSocket API Client check out [this link](https://www.scaledrone.com/docs/quick-start/node-websocket).
## 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
```javascript
const Scaledrone = require('scaledrone-node-push');
const sd = new Scaledrone({
channelId: 'CHANNEL_ID',
secretKey: 'SECRET_KEY'
});
```### Publishing a message
```javascript
const message = {foo: 'bar'};
const room = 'notifications';
sd.publish(room, message, function(error) {
// check for errors
});
```### Publishing the same message to multiple rooms
```javascript
const message = {foo: 'bar'}
const rooms = ['notifications', 'lounge'];
sd.publish(rooms, message, function(error) {
// check for errors
});
```### Get channel stats
```javascript
sd.channelStats(function(error, reply) {
// check for errors
console.log(reply); // { users_count: 2 }
});
```### Getting the list of users from all rooms
```javascript
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
```javascript
sd.rooms(function(error, reply) {
// check for errors
console.log(reply); // ["room1", "room2"]
});
```### Getting the list of users in a room
```javascript
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
```javascript
sd.allRoomMembers(function(error, reply) {
// check for errors
console.log(reply); // {"room1": ["user1", "user2"], "room2": ["user1"]}
});
```