New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pushy

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pushy - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

examples/send.js

42

package.json
{
"name": "pushy",
"description": "Publish-Subscribe system for realtime webapps",
"version": "1.0.0",
"author": {
"name": "Julien Ballestracci",
"email": "julien@nitronet.org"
"version": "2.0.0",
"description": "The official Node.js package for sending push notifications with Pushy.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"express": "3.1.0",
"node-uuid": "1.4.0",
"sockjs": "0.3.5"
},
"keywords": [
"pushy",
"realtime",
"system",
"web",
"publish",
"subscribe",
"pubsub",
"api"
],
"repository": {
"type": "git",
"url": "git://github.com/spokela/pushy-node"
"url": "git+https://github.com/pushy-me/pushy-node.git"
},
"main": "./lib/pushy",
"engines": {
"node": "*"
"author": "Pushy <support@pushy.me>",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/pushy-me/pushy-node/issues"
},
"readmeFilename": "README.md",
"license": "MIT",
"preferGlobal": "false"
"homepage": "https://github.com/pushy-me/pushy-node#readme",
"dependencies": {
"bluebird": "^3.4.1",
"request": "^2.72.0"
}
}

@@ -1,120 +0,71 @@

# Pushy Server
# pushy-node
[![npm version](https://badge.fury.io/js/pushy-node.svg)](https://www.npmjs.com/package/pushy-node)
Pushy is a Publish/Subscribe system for realtime web applications.
This is the server-side made on top of NodeJS and SockJS.
The official Node.js package for sending push notifications with [Pushy](https://pushy.me/).
## Install via NPM
> [Pushy](https://pushy.me/) is the most reliable push notification gateway, perfect for real-time, mission-critical applications.
```
npm install pushy
```
**Note:** If you don't have an existing Node.js project, consider using our [sample Node.js API project](https://github.com/pushy-me/pushy-node-backend) as a starting point to make things easier for you.
## Run the service
## Usage
### Start NodeJS/Pushy:
First, install the package using npm:
```shell
npm install pushy-node --save
```
$ node pushy-server.js config.json
```
### Trigger an event on a channel
Then, use the following sample code to send a push notification to target devices:
To trigger an event on a specific channel, hit the following URL with the required parameters. POST data will be sent alongside the event.
```js
var Pushy = require('pushy-node');
```
http(s)://<pushy-host>:<pushy-port>/pushy/channel/<channel-name>/trigger?event=<event-name>&timestamp=<current-ts>&auth_key=<auth-key>
```
// Plug in your Secret API Key
// Get it here: https://dashboard.pushy.me/
var pushyAPI = new Pushy('SECRET_API_KEY');
Parameters:
* ```pushy-host``` : the hostname of your Pushy server
* ```pushy-port``` : the listening port you defined in *config.json*
* ```channel-name``` : name of the channel where the event should be dispatched
* ```event-name``` : name of the event
* ```current-ts``` : your app's timestamp (UNIXTIME). 600 seconds difference (+/-) is tolerated.
* ```auth-key``` : SHA256 auth key for this command (read more bellow)
// Set push payload data to deliver to device(s)
var data = {
message: 'Hello World!'
};
### Generating authentication key
// Insert target device token(s) here
var tokens = ['DEVICE_TOKEN'];
The authentication key is a SHA256 sum of:
// Set optional push notification options (such as TTL)
var options = {
// Set the notification to expire if not delivered within 30 seconds
time_to_live: 30
};
// Send push notification via the Push Notifications API
// https://pushy.me/docs/api/send-notifications
pushyAPI.sendPushNotification(data, tokens, options, function (err, id) {
// Log errors to console
if (err) {
return console.log('Fatal Error', err);
}
// Log success
console.log('Push sent successfully! (ID: ' + id + ')');
});
```
<channel>:<event>:<timestamp>:<JsonEncodedBody>:<secretKey>
```
Example: we want to send a *test* event to the *Hello* channel, the current timestamp is *123456789* and we don't send any data. Our secret key is *secret*.
Alternatively, send the notification using promises:
```js
pushyAPI.sendPushNotification(data, tokens, options)
.then(function (id) {
// Log success
console.log('Push sent successfully! (ID: ' + id + ')');
}).catch(function (err) {
// Log errors to console
return console.log(err);
});
```
signature string: hello:test:123456789:{}:secret
auth_key: d7f4c3309757c4025269b6576eae10028ec0711c88e6ef605bb44d149cb07803
```
## Private and Presence-enabled Channels
Make sure to replace `SECRET_API_KEY` with your app's Secret API Key listed in the [Dashboard](https://dashboard.pushy.me/).
Any channel named ```private-```something will require an authentification string sent on subscription. If any complementary data is sent, *presence* will be enabled too.
## License
### Authentication
The authentication token should be generated server-side when requested by the client. Then the client should resend his subscription request with this token.
The authentication token is a SHA256 hash generated by this signature string:
```
<connection_id>:<channel>[:<JsonEncodedPresenceData>]:<secretKey>
```
Parameters:
* ```connection_id``` : The connection ID (given to client on connection)
* ```channel``` : Lowercased channel name
* ```JsonEncodedPresenceData``` *optional* : Json encoded presence data (if any)
* ```secretKey``` : Your configured secret key
### Presence-enabled channels
When *presence* is enabled on a channel, presence data sent on subscription will be shared between members everytime a new subscriber join.
The channel will trigger two additionnal events:
* ```pushy:presence-add``` : when a new subscriber join (with its presence data)
* ```pushy:presence-quit``` : when a subscriber quit
When subscribing to a presence-enabled channel, the client will recieve presence data from all current subscribers.
**IMPORTANT** : Presence data is SHARED so please don't put passwords or any sensitive data here. Since its sent very often, it might also be a good idea to keep this data as light as possible (just a username and his avatar-url for example).
## Configuration parameters
* ```port``` *int* : HTTP Port number (default is 8123)
* ```secretKey``` *string* : Secret/long string used server-side to do authentification.
* ```ssl``` *boolean* : Run as an HTTPS server (defaults to false)
* ```sockjs``` *object* : Default SockJS options (see SockJS documentation)
## Commands
Commands are callables made available to the client to interact with your Pushy server througth the SockJS socket. Obviously, the two default commands are *SUBSCRIBE* and *UNSUBSCRIBE* but you can easily add other commands to fit your needs. This can be useful for games, chats etc..
A command signature looks like this:
``` javascript
// Command example
//
// @param SockJsServer sockjs The SockJS server handle (@see lib/sockjs-server.js)
// @param SockJSConnection connection The SockJS connection handle sending the command
// @param Object data Data sent alongside the command
// @param Manager channels Channels Manager instance (@see lib/manager.js)
function(sockjs, connection, data, channels) {
// do something
}
```
## LICENSE
This software is licensed under the MIT License. Please refer to the LICENSE file for more details.
```
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```
[Apache 2.0](LICENSE)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc