# cjs-wamp

> Web Application Messaging Protocol lightweight implementation.

Latest version **1.3.2** (published 2018-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install cjs-wamp
pnpm add cjs-wamp
yarn add cjs-wamp
bun add cjs-wamp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.2 |
| Published | 2018-08-05 |
| First published | 2015-12-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Stanislav Kalashnik |
| Maintainers | cjssdk |
| Keywords | commonjs, sdk, cjssdk, framework, websocket, protocol, messaging, wamp |

## Links

- npm: https://www.npmjs.com/package/cjs-wamp
- Repository: https://github.com/cjssdk/wamp
- Homepage: https://github.com/cjssdk/wamp#readme
- Issues: https://github.com/cjssdk/wamp/issues
- npm.io page: https://npm.io/package/cjs-wamp

## Dependencies (1)

- [cjs-emitter](https://npm.io/package/cjs-emitter.md) ^1.5.3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.3.2 (latest) — 2018-08-05
- 1.3.1 — 2017-06-14
- 1.3.0 — 2016-10-20
- 1.2.0 — 2015-12-17
- 1.1.0 — 2015-12-16
- 1.0.4 — 2015-12-04
- 1.0.3 — 2015-12-04

## README

WAMP Implementation
===================

[![build status](https://img.shields.io/travis/cjssdk/wamp.svg?style=flat-square)](https://travis-ci.org/cjssdk/wamp)
[![npm version](https://img.shields.io/npm/v/cjs-wamp.svg?style=flat-square)](https://www.npmjs.com/package/cjs-wamp)
[![dependencies status](https://img.shields.io/david/cjssdk/wamp.svg?style=flat-square)](https://david-dm.org/cjssdk/wamp)
[![devDependencies status](https://img.shields.io/david/dev/cjssdk/wamp.svg?style=flat-square)](https://david-dm.org/cjssdk/wamp?type=dev)
[![Gitter](https://img.shields.io/badge/gitter-join%20chat-blue.svg?style=flat-square)](https://gitter.im/DarkPark/cjssdk)
[![RunKit](https://img.shields.io/badge/RunKit-try-yellow.svg?style=flat-square)](https://npm.runkit.com/cjs-wamp)


[WAMP](http://wamp-proto.org/) lightweight implementation for both browser and server-side (with [ws](https://www.npmjs.com/package/ws) npm package).

`cjs-wamp` extends [Emitter](https://github.com/cjssdk/emitter) interface.
It does not create any WebSocket connections but uses an existing one.


## Installation ##

```bash
npm install cjs-wamp
```


## Usage ##

Add the constructor to the scope:

```js
var Wamp = require('cjs-wamp');
```

Create an instance from some existing WebSocket connection:

```js
var ws   = new WebSocket('ws://echo.websocket.org'),
    wamp = new Wamp(ws);
```

Send message to execute remotely:

```js
wamp.call('getInfo', {id: 128}, function ( error, result ) {
    // handle execution result
});
```

Serve remote request:

```js
wamp.addListener('getData', function ( params, callback ) {
    // handle request ...
    // send back results to the sender
    callback(null, requestedData);
});
```

Send notification with some optional data:

```js
wamp.call('onUserUpdate', newUserData);
```

Serve received notification:

```js
wamp.addListener('onUserUpdate', function ( event ) {
    // handle notification data ...
});
```

Original WebSocket connection is also available:

```js
wamp.socket.send('some message');
```

Catch the moment when WebSocket connection is ready:

```js
wamp.socket.onopen = function() {
    // send or receive messages here
};
```

Server-side example with [ws](https://www.npmjs.com/package/ws) npm package:

```js
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](https://github.com/cjssdk/wamp/issues)
according to the contribution [rules](.github/contributing.md).


## License ##

`cjs-wamp` is released under the [MIT License](license.md).

---
_Source: https://npm.io/package/cjs-wamp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
