1.0.1 • Published 7 years ago
spa-wamp v1.0.1
WAMP Implementation wrapper
Thin wrapper around cjs-wamp module.
Installation
npm install spa-wamp
Usage
Add the constructor to the scope:
var Wamp = require('spa-wamp');
Create a WAMP connection:
var wamp = new Wamp('ws://echo.websocket.org');
Wait for an open state to exec remote method and serve remote request:
wamp.onopen = function () {
wamp.call('getInfo', {id: 128}, function ( error, result ) {
// handle execution result
});
wamp.addListener('getData', function ( params, callback ) {
// handle request ...
// send back results to the sender
callback(null, requestedData);
});
};
Catch a connection loss and automatically reconnect:
wamp.onclose = function () {
console.log('reconnecting in 5 seconds ...');
};
Create a WAMP instance with increased reconnection time:
var wamp = new Wamp('ws://echo.websocket.org', {timeout: 30000});
Timeout can be changed for all instances at once:
Wamp.prototype.timeout = 30000;
To disable automatic reconnection set timeout
to 0;
It's possible to work directly with original WebSocket connection (but messaging should be avoided):
// ok
wamp.socket.close();
// not recommended
wamp.socket.send('some message');
Contribution
If you have any problem or suggestion please open an issue here. Pull requests are welcomed with respect to the JavaScript Code Style.
License
spa-wamp
is released under the MIT License.