A driver oriented realtime communication library.
npm install droppay-sensor-js -S
<script type="application/ecmascript" src="dist/sensor.js">
- connect
- disconnect
- subscribe
- unsubscribe
- addListener
- removeListener
- release
- publish
Initialize a connection with the service provider.
Close connection with the service provider.
Subscribe to a specific channel. Depending on the driver an array of channels can be used.
Unsubscribe from a specific channel. Depending on the driver an array of channels can be used.
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.
Wipe off a listener from the queue.
Release all channels and disconnect from service provider endpoint.
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
.
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();