mtm-ws-router
v0.0.17
Published
Downloads
4
Readme
MtmWsRouter
MtmWsRouter is a java script version of the client lib for the php package MTM/WsRouter ()
For node.js, you can use this command to install:
npm install mtm-ws-router
import the service:
import { MtmWsRouter } from "mtm-ws-router";
USE assuming you have injected the service using the _mtmWsRouter variable name:
var ssl = true;
var id = "myClientName";
var ip = "127.0.0.1";
var port = 6653;
var authData = {"mySecret": "qefuiu&^%$##seeture"}; //authenticate with the border gateway
var bcObj = this._mtmWsRouter.getNodes().getBorderClient(id, ip, port).setSsl(ssl);
//specify the function that should handle ingress messages takes a single argument
bcObj.setIngressCb(this, "ingressHandler");
bcObj.connect(authData).then((rObj)=>{
var peerObj = bcObj.getPeersById("somePeerId");
if (peerObj !== null) {
//send a message to the peer and wait for its response
//data can be anything that is supported by json.stringify
//default timeout is 10000ms
var msgObj = {"type": "message", "data": "Hello peer"};
peerObj.newRequest(msgObj).get().then((data)=>{
console.log(data); //return data
});
} else {
console.log("Missing Peer");
reject("Missing Peer");
}
}, (errObj)=>{
console.log("Connect failed");
console.log(errObj);
});