All Projects → guness → node-xcs

guness / node-xcs

Licence: BSD-2-Clause license
NodeJS implementation of Google's XMPP Connection Server

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to node-xcs

ejabberd mod apns
An ejabberd module to send PUSH messages to iOS devices through APNS
Stars: ✭ 31 (-16.22%)
Mutual labels:  xmpp, push-notifications
ejabberd mod gcm
Google Cloud Messaging API for Ejabberd (PUSH Messages)
Stars: ✭ 27 (-27.03%)
Mutual labels:  xmpp, push-notifications
mod push appserver
Simple and extendable appserver for XMPP pushes (aka. XEP-0357)
Stars: ✭ 24 (-35.14%)
Mutual labels:  xmpp, push-notifications
hms-push-serverdemo-php
PHP sample code encapsulates APIs of the HUAWEI Push Kit server.It provides many sample PHP programs about quick access to HUAWEI Push Kit for your reference or usage.
Stars: ✭ 21 (-43.24%)
Mutual labels:  push-notifications
OneSignal-Ionic-Sample
No description or website provided.
Stars: ✭ 85 (+129.73%)
Mutual labels:  push-notifications
mnm-hammer
mnm implements TMTP protocol. Let Internet sites message members directly, instead of unreliable, insecure email. Contributors welcome! (Client)
Stars: ✭ 66 (+78.38%)
Mutual labels:  xmpp
q-municate-web
Q-municate Web chat application
Stars: ✭ 66 (+78.38%)
Mutual labels:  xmpp
VaporGCM
A simple Android GCM/FCM library for Swift/Vapor
Stars: ✭ 25 (-32.43%)
Mutual labels:  push-notifications
HarmonyHub
Library for controlling a Logitech Harmony Hub
Stars: ✭ 19 (-48.65%)
Mutual labels:  xmpp
node-onesignal
Node.js wrapper for the One Signal API
Stars: ✭ 33 (-10.81%)
Mutual labels:  push-notifications
mobpush-api-java-client
MobPush 服务端集成SDK for Java
Stars: ✭ 14 (-62.16%)
Mutual labels:  push-notifications
hatexmpp
fuse xmpp client (xmppfs). The development stopped, you may like https://github.com/l29ah/hatexmpp3
Stars: ✭ 26 (-29.73%)
Mutual labels:  xmpp
stork
(M) Android XMPP Client
Stars: ✭ 51 (+37.84%)
Mutual labels:  xmpp
homebridge-http-rgb-push
Homebridge plugin to control a web/http-based RGB device.
Stars: ✭ 16 (-56.76%)
Mutual labels:  push-notifications
food-delivery-ios-app
A food delivery application built using Swift for iOS. The application uses Pushers notifications feature to send push notifications to mobile devices.
Stars: ✭ 36 (-2.7%)
Mutual labels:  push-notifications
xmpp-php
PHP client library for XMPP (Jabber) protocol
Stars: ✭ 33 (-10.81%)
Mutual labels:  xmpp
GroundControl
Push notification service for Bitcoin wallets
Stars: ✭ 70 (+89.19%)
Mutual labels:  push-notifications
react-native-android-notification-listener
React Native Android Notification Listener - Listen for status bar notifications from all applications
Stars: ✭ 87 (+135.14%)
Mutual labels:  push-notifications
browser-push
Complete workout and guidelines to add web push notifications support for your webapp without third-party notification provider
Stars: ✭ 67 (+81.08%)
Mutual labels:  push-notifications
OneSignal-Java-SDK
OneSignal SDK
Stars: ✭ 28 (-24.32%)
Mutual labels:  push-notifications

node-xcs

node-xcs is a NodeJS implementation of Google's Firebase Connection Server implemented using XMPP Protocol.

Build Status Join the chat at https://gitter.im/guness/node-xcs

Getting Started

Install:

npm install node-xcs

Import:

var Sender = require('node-xcs').Sender;
var Result = require('node-xcs').Result;
var Message = require('node-xcs').Message;
var Notification = require('node-xcs').Notification;

Initiate Sender:

var xcs = new Sender(SenderID, ServerKey);

Build Notification:

var notification = new Notification("ic_launcher")
    .title("Hello buddy!")
    .body("node-xcs is awesome.")
    .build();

Build Message:

var message = new Message("messageId_1046")
    .priority("high")
    .dryRun(false)
    .addData("node-xcs", true)
    .addData("anything_else", false)
    .addData("awesomeness", 100)
    .deliveryReceiptRequested(true)
    .notification(notification)
    .build();

Send Message:

xcs.sendNoRetry(message, to, function (result) {
    if (result.getError()) {
        console.error(result.getErrorDescription());
    } else {
        console.log("message sent: #" + result.getMessageId());
    }
});

Functions

Currently there are two functions to send message, however one of them has not been implemented yet.

Send Message

Use sendNoRetry to send a message.

xcs.sendNoRetry(message, to, [callback(result)]);
Argument Details
message Message to sent (with or without notification)
to A single user, or topic
callback (optional) function(result) Result

End Connection

xcs.end;

Events

Events are defined as below.

xcs.on('message', function(messageId, from,  data, category){}); // Messages received from client (excluding receipts)
xcs.on('receipt', function(messageId, from,  data, category){}); // Only fired for messages where options.delivery_receipt_requested = true

xcs.on('connected', console.log);
xcs.on('disconnected', console.log);
xcs.on('online', console.log);
xcs.on('error', console.log);
xcs.on('message-error', console.log);

Example

var Sender = require('node-xcs').Sender;
var Message = require('node-xcs').Message;
var Notification = require('node-xcs').Notification;
var Result = require('node-xcs').Result;

var xcs = new Sender(SenderID, ServerKey);

xcs.on('message', function(messageId, from, data, category) {
	console.log('received message', arguments);
}); 

xcs.on('receipt', function(messageId, from, data, category) {
	console.log('received receipt', arguments);
});

var notification = new Notification("ic_launcher")
    .title("Hello buddy!")
    .body("node-xcs is awesome.")
    .build();

var message = new Message("messageId_1046")
    .priority("high")
    .dryRun(false)
    .addData("node-xcs", true)
    .addData("anything_else", false)
    .addData("awesomeness", 100)
    .deliveryReceiptRequested(true)
    .notification(notification)
    .build();

xcs.sendNoRetry(message, to, function (result) {
    if (result.getError()) {
        console.error(result.getErrorDescription());
    } else {
        console.log("message sent: #" + result.getMessageId());
    }
});

Echo Client

xcs.on('message', function(_, from, data) {
	xcs.send(from, data);
});

Tests

There are several nice tests. In order to test locally just call:

npm install mocha
npm test

If you also want to test against google servers, you should export some environment variables before starting the test.

export FCM_SERVER_KEY='My_Super_awesome_api_key'
export FCM_SENDER_ID=007
export TRAVIS_PULL_REQUEST=false

Notes on XCS

  • The library still being working on it, so there may be serious problems, use it at your own risk.
  • No events are emitted from XCS or this library when a device new registers: you'll have to send a message from the device and process it yourself
  • Occasionally, FCM performs load balancing, so the connection is sometimes restarted. This library handles this transparently, and your messages will be queued in these situations.
  • This library auto sends acks for receipts of sent messages, however google side receipt reporting is not reliable.

Disclaimer

Based on a work at https://github.com/jacobp100/node-gcm-ccs

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].