podasync-ws-only

2.9.0-snapshot.14 • Public • Published

Synopsis

Fanap's POD Async service (DIRANA) - Websocket Only

Code Example

First you have to require PodAsync in your project.

var Async = require('podasync-ws-only');

To be able to connect to async server, you should set some parameters. Websocketsprotocol is 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
  }
};

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-ws-only

Weekly Downloads

28

Version

2.9.0-snapshot.14

License

MIT

Unpacked Size

242 kB

Total Files

19

Last publish

Collaborators

  • masoudmanson
  • farhan.naysee