Skip to content
/ wamp Public

Web Application Messaging Protocol implementation SPA wrapper.

License

Notifications You must be signed in to change notification settings

spasdk/wamp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Web Application Messaging Protocol implementation SPA wrapper.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published