0.3.3 • Published 7 years ago

rayson v0.3.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

rayson

Build Dependencies

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

7 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.2.2

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.1.11

9 years ago

0.1.10

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago