JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q33829F
  • License MIT

The Web Application Messaging Protocol for react-native and web browser.

Package Exports

  • wamp.js

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 (wamp.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

wamp.js

The Web Application Messaging Protocol for js, works in browser and react-native.

This Project is ported from autobahn-js, I removed all it's depencies(crypto-js, when, ws, msgpack-lite), and transformed into es6 style code. My aim is to work in web browser(support WebSocket, Promise) as well as react-native. so only supports json protocol.

install

npm i -S wamp.js

API

now, wamp.js's API is the same as autobahn-js: autobahn-js API

// autobahn-js
var autobahn = require('autobahn');
new autobahn.Connection(...);

// wamp.js
import wamp = require('wamp.js');
new wamp.Connection(...);

NOTE && NEW

// note:
// !!default enable automatic reconnect if host is unreachable

// new APIs and constants.
wamp.debugOn();
wamp.debugOff();
wamp.WAMP_STATUS;
wamp.STATUS;


// add onstatuschange, this can replace onopen and onclose;
connection.onstatuschange(status, details);
// status-> STATUS.DISCONNECTED, details-><close details>
// status-> STATUS.CONNECTING, details->undefined
// status-> STATUS.CONNECTED, details-><onjoin details>
// status-> STATUS.CLOSED, details-><close details>


// add retry and networkOffline notify.
// 1. automatic reconnect is not useful as retry interval time get longer, when network resume online, you must wait.
// 2. as WebSocket in browser(at least chrome) does not close when turn off network,
//       but it cannot send or recevie msgs, so I want to close it manually.
connection.retry(); // initiate to reconnect.
connection.networkOffline(); // notify to close transport.

// add .ping() and .addOnpongListener(handler)
session.ping()
session.addOnponListener(handler)