barracks-messenger-sdk
Barracks messaging SDK node module
Last updated 3 years ago by bargenson .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install barracks-messenger-sdk 
SYNC missed versions from official npm registry.

Build Status Coverage Status npm version

Barracks Messaging SDK for Javascript (Beta)

The Javascript SDK to enable messaging on your devices

Installation

$ npm install barracks-messenger-sdk

Usage

Create a Barracks Messaging SDK instance :

var BarracksMessenger = require('../src/index').BarracksMessenger;

var barracksMessenger = new BarracksMessenger({
  apiKey: 'Your user API key',
  unitId: 'The unique device identifier'
});

Your user API key you can be found on the Account page of the Barracks application.

Connect to the messaging service :

barracksMessenger.connect({
    onConnect: function() {
      // Do something when your device connects to MQTT
    },
    onError: function(err) {
      // Do something when an error occurs
    },
    onClose: function() {
      // Do something when the connection is closed
    },
    onReconnect: function() {
      // Do somethings when the device attempts to reconnect
    }
});

Subscribe to a topic to enable message reception :

barracksMessenger.subscribe(function (messageReceived) {
    // Do something with a message when you retrieve it
}, { qos: 1 });

A message object has 5 properties :

  • payload : String
  • retained : boolean
  • topic : String
  • length : int
  • qos : 0 or 1

End the connection :

barracksMessenger.end();

Docs & Community

Current Tags

  • 0.0.4                                ...           latest (3 years ago)

3 Versions

  • 0.0.4                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (16)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |