1.4.2 • Published 3 years ago

droppay-sensor v1.4.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
3 years ago

DropPay SensorJS

A driver oriented realtime communication library.

Installation

Using NodeJS npm command

npm install droppay-sensor-js -S

Using plain javascript on browsers

<script type="application/ecmascript" src="dist/sensor.js">

Supported Drivers

API

  • connect
  • disconnect
  • subscribe
  • unsubscribe
  • addListener
  • removeListener
  • release
  • publish

connect()

Initialize a connection with the service provider.

disconnect()

Close connection with the service provider.

subscribe(ChannelId: String/Array)

Subscribe to a specific channel. Depending on the driver an array of channels can be used.

unsubscribe(ChannelId: String/Array)

Unsubscribe from a specific channel. Depending on the driver an array of channels can be used.

addListener(callback(id: int, message: Object): Function)

Add a listener to the messages queue. Anytime a message is received on the subscribed channel(s) through the estabilished connection, all listeners are notified.

removeListener(callback: Function)

Wipe off a listener from the queue.

release()

Release all channels and disconnect from service provider endpoint.

publish(name/channel: String, payload: String/Object, callback: Function)

Send a payload to the subscribed channel through the estabilished connection. Name/Channel are mandatory, depending on the driver used they can be a message NAME. or a CHANNEL_ID.

Example (PubNub)

import DropPaySensorJS from 'droppay-sensor-js';

const sensor = DropPaySensorJS('pubnub', {
    subscribeKey: 'sub-xxx',
    publishKey: 'pub-xxx',
    ssl: true
});

sensor.addListener((message)=>{
    console.log('received message: ' + JSON.stringify(message))
});

sensor.subscribe('myChannel');

sensor.publish('myChannel', (status, response)=>{
    if (status.error) {
        // handle error
        console.log(status)
    } else {
        console.log("message Published w/ timetoken", response.timetoken)
    }
});

sensor.unsubscribe('myChannel');

sensor.release();
document version 1.0 by Giuseppe Marletta 07/12/2018
1.4.2

3 years ago