podasync

2.8.3 • Public • Published

Synopsis

Fanap's POD Async service (DIRANA)

Code Example

First you have to require PodAsync in your project.

var Async = require('podasync');

To be able to connect to async server, you should set some parameters. Websockets, ActiveMQ and MQTT protocols are currently supported.

Websocket protocol parameters

var params = {
  socketAddress: "ws://chat-sandbox.pod.land/ws",
  serverName: "chat-server",
  reconnectOnClose: true,
  connectionCheckTimeout: 10000,
  asyncLogging: {
    onFunction: true,
    onMessageReceive: true,
    onMessageSend: true
  }
};

ActiveMQ protocol parameters

var params = {
  protocol: "queue",
  servers: [{
    serverHost: "***",
    serverPort: "***",
    serverUsername: "***",
    serverPassword: "***"
  }, {
    serverHost: "***",
    serverPort: "***",
    serverUsername: "***",
    serverPassword: "***"
  }],
  queueReceive: "queue-***",
  queueSend: "queue-***",
  queueConnectionTimeout: 20000,
  asyncLogging: {
    onFunction: true, // log main actions on console
    onMessageReceive: true, // log received messages on console
    onMessageSend: true // log sent messaged on console
  }
};

MQTT parameters

var params = {
    protocol: 'mqtt',
    mqttHost: '***',
    mqttPort: '***',
    mqttUsername: '***',
    mqttPassword: '***',
    mqttConnectionTimeout: 20000,
    mqttClientId: 1234,
    mqttInputQueueName: "out/mqqttout",
    mqttOutputQueueName: "async/chat-server",
    peerId: 118401,
    asyncLogging: {
        onFunction: true, // log main actions on console
        onMessageReceive: true, // log received messages on console
        onMessageSend: true // log sent messaged on console
    }
};

After setting parameters you can make a new connection to Async server.

var asyncClient = new Async(params);

Async Ready Event

After making a new connection, you should wait for asyncReady event to fire so you could be sure that the connection has been estabilished and you are ready to go

asyncClient.on("asyncReady", function() {
  /**
  * Write your code inside asyncReady() function
  */
});

Receive messages

In order to receive messages from Async server, you could listen to message event.

/**
* Listening to responses came from DIRANA
*/
asyncClient.on("message", function(message, ack) {
  console.log(message);
});

Send message

To send a new message to Async server you can use send() function.

/**
* A Custom Message To be Send Through DIRANA
*/
var customMessage = {
  type: 3,
  content: {
    receivers: ["receiver1", "receiver2", "..."],
    content: "Hello Buddy!"
  }
};

/**
* Sending Message
*/
asyncClient.send(customMessage);

Motivation

This module helps you to easily connect POD chat service.

Installation

npm install podasync --save

API Reference

API Docs from POD

Tests

npm test

Contributors

You can send me your thoughts about making this repo great :) Email

License

Under MIT License.

Package Sidebar

Install

npm i podasync

Weekly Downloads

16

Version

2.8.3

License

MIT

Unpacked Size

1.84 MB

Total Files

15

Last publish

Collaborators

  • masoudmanson
  • farhan.naysee