Package Exports
- cjs-wamp
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cjs-wamp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
WAMP Implementation
WAMP lightweight implementation for both browser and server-side (with ws npm package).
cjs-wamp
extends Emitter interface.
It does not create any WebSocket connections but uses an existing one.
Installation
npm install cjs-wamp
Usage
Add the constructor to the scope:
var Wamp = require('cjs-wamp');
Create an instance from some existing WebSocket connection:
var ws = new WebSocket('ws://echo.websocket.org'),
wamp = new Wamp(ws);
Send message to execute remotely:
wamp.call('getInfo', {id: 128}, function ( error, result ) {
// handle execution result
});
Serve remote request:
wamp.addListener('getData', function ( params, callback ) {
// handle request ...
// send back results to the sender
callback(null, requestedData);
});
Send notification with some optional data:
wamp.call('onUserUpdate', newUserData);
Serve received notification:
wamp.addListener('onUserUpdate', function ( event ) {
// handle notification data ...
});
Original WebSocket connection is also available:
wamp.socket.send('some message');
Catch the moment when WebSocket connection is ready:
wamp.socket.onopen = function() {
// send or receive messages here
};
Server-side example with ws npm package:
var server = new (require('ws').Server)({port: 9000}),
Wamp = require('cjs-wamp');
server.on('connection', function ( connection ) {
var wamp = new Wamp(connection);
wamp.call('getInfo', {id: 128}, function ( error, result ) {
// handle execution result
});
});
Error codes
Value | Message | Description |
---|---|---|
-32700 | Parse error | Invalid JSON data was received. |
-32600 | Invalid Request | The JSON sent is not a valid Request object. |
-32601 | Method not found | The method does not exist / is not available. |
Contribution
If you have any problems or suggestions please open an issue according to the contribution rules.
License
cjs-wamp
is released under the MIT License.