0.3.3 • Published 9 years ago
rayson v0.3.3
rayson
Rayson is a JSON-RPC 2.0 mqtt client and mqtt server for node.js based on jayson.
Installation
$ npm install --save rayson
Server
jason-mqtt server played as a mqtt consumer, so it need a mqtt server start first. We can use mosca.
Exposes an array of functions which retrieves and returns data.
var rayson = require('../'/*'rayson'*/);
var moscaServer = new require('mosca').Server({port: 9999}); // start mosca server for test
var server = rayson.server({
localtime: function (cb) {
console.log('localtime has been called');
cb(null, new Date());
}
}).mqtt('mqtt://localhost:9999', '$rpc/server1/localtime');
server.format('msgpack'); // default is `json`
Client
Consumes the api exposed by the previous example.
var rayson = require('../'/*'rayson'*/);
var client = rayson.client.mqtt('mqtt://localhost:9999', '$rpc/:sid/localtime');
client.format('msgpack'); // default is `json`
client.mqtt.on('error', function (err) {
console.error(err);
});
client.mqtt.on('connect', function () {
console.log('connected');
});
client.mqtt.on('reconnect', function () {
console.log('reconnect');
});
client.mqtt.on('offline', function () {
console.log('offline');
});
client.sid('server1').request('localtime', [], function(err, error, time) {
console.log('localtime: ', time);
}).timeout(10);
License
MIT © taoyuan
0.3.3
9 years ago
0.3.2
9 years ago
0.3.1
9 years ago
0.3.0
9 years ago
0.2.4
10 years ago
0.2.3
10 years ago
0.2.2
10 years ago
0.2.1
10 years ago
0.2.0
10 years ago
0.1.11
10 years ago
0.1.10
10 years ago
0.1.9
10 years ago
0.1.8
10 years ago
0.1.7
10 years ago
0.1.6
10 years ago
0.1.5
10 years ago
0.1.4
10 years ago
0.1.3
10 years ago