Fanap's POD Async service (DIRANA)
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.
var params = {
socketAddress: "ws://chat-sandbox.pod.land/ws",
serverName: "chat-server",
reconnectOnClose: true,
connectionCheckTimeout: 10000,
asyncLogging: {
onFunction: true,
onMessageReceive: true,
onMessageSend: true
}
};
var params = {
protocol: "queue",
queueHost: "172.16.0.248",
queuePort: "61613",
queueUsername: "***",
queuePassword: "***",
queueReceive: "queue-in-amjadi-stomp",
queueSend: "queue-out-amjadi-stomp",
queueConnectionTimeout: 20000,
asyncLogging: {
onFunction: true, // log main actions on console
onMessageReceive: true, // log received messages on console
onMessageSend: true // log sent messaged on console
}
};
var params = {
protocol: 'mqtt',
mqttHost: '172.16.106.26',
mqttPort: '1883',
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);
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
*/
});
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);
});
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);
This module helps you to easily connect POD chat service.
npm install podasync --save
npm test
You can send me your thoughts about making this repo great :) Email
Under MIT License.