# spa-wamp

> Web Application Messaging Protocol lightweight implementation.

Latest version **1.0.1** (published 2018-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install spa-wamp
pnpm add spa-wamp
yarn add spa-wamp
bun add spa-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.0.1 |
| Published | 2018-08-14 |
| First published | 2016-10-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Stanislav Kalashnik |
| Maintainers | spasdk |
| Keywords | spa, sdk, spasdk, framework, wamp, wrapper |

## Links

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

## Dependencies (1)

- [cjs-wamp](https://npm.io/package/cjs-wamp.md) ^1.3.2

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads
- [@modern-js/plugin-swc](https://npm.io/package/@modern-js/plugin-swc.md) — 3.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-08-14
- 1.0.0 — 2016-10-21

## README

WAMP Implementation wrapper
===========================

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

Thin wrapper around [cjs-wamp](https://github.com/cjssdk/wamp) module.


## Installation ##

```bash
npm install spa-wamp
```


## Usage ##

Add the constructor to the scope:

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

Create a WAMP connection:

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

Wait for an open state to exec remote method and serve remote request:

```js
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:

```js
wamp.onclose = function () {
    console.log('reconnecting in 5 seconds ...');
};
````

Create a WAMP instance with increased reconnection time:

```js
var wamp = new Wamp('ws://echo.websocket.org', {timeout: 30000});
```

Timeout can be changed for all instances at once:

```js
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):

```js
// ok
wamp.socket.close();
// not recommended
wamp.socket.send('some message');
```

## Contribution ##

If you have any problem or suggestion please open an issue [here](https://github.com/spasdk/wamp/issues).
Pull requests are welcomed with respect to the [JavaScript Code Style](https://github.com/DarkPark/jscs).


## License ##

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

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