spa-wamp

1.0.1 • Public • Published

WAMP Implementation wrapper

build status npm version dependencies status devDependencies status Gitter

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.

Package Sidebar

Install

npm i spa-wamp

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

6.26 kB

Total Files

4

Last publish

Collaborators

  • spasdk