npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swampyer

v1.5.1

Published

A lightweight WAMP client implementing the WAMP v2 basic profile

Downloads

144

Readme

swampyer

A lightweight WAMP client that implements the WAMP v2 basic profile

The library is highly promise based. Almost all available operations return a promise. However, it also allows for subscription to various events useful for monitoring the lifecycle of the WAMP connection.

API documentation

Installation

npm i swampyer

Examples

  • Open an unauthenticated connection without any automatic reconnection

    import { Swampyer } from 'swampyer';
    import { WebsocketJson } from 'swampyer/lib/transports/websocket_json';
    
    //...
    
    const wamp = new Swampyer();
    await wamp.open(new WebsocketJson('ws://localhost:8080/ws'), { realm: 'realm1' });
    
    // Use the `wamp` object for the WAMP operations
  • Open an authenticated connection without any automatic reconnection

    import { Swampyer } from 'swampyer';
    import { WebsocketJson } from 'swampyer/lib/transports/websocket_json';
    
    //...
    
    const wamp = new Swampyer();
    await this.wamp.open(new WebsocketJson('ws://localhost:8080/ws'), {
      realm: 'realm1',
      auth: {
        authId: '<some username here>',
        authMethods: ['ticket'],
        onChallenge: method => '<authentication for the user>',
      }
    });
    
    // Use the `wamp` object for the WAMP operations
  • Open an auto reconnecting unauthenticated connection. If the connection can not be established on the first try or if the connection closes for some reason, then it will keep trying to reconnect until it succeeds or wamp.close() is called.

    import { Swampyer } from 'swampyer';
    import { WebsocketJson } from 'swampyer/lib/transports/websocket_json';
    
    //...
    
    const wamp = new Swampyer();
    this.wamp.openAutoReconnect(
      () => new WebsocketJson('ws://localhost:8080/ws')
      { realm: 'realm1' }
    );
    
    wamp.openEvent.addEventListener(() => {
      // Use the `wamp` object for the WAMP operations
    });
  • By default, the delay between each successive reconnection attempt increases pseudo-exponentially starting from 1ms up to a maximum of 32000ms. The following example sets the delay between reconnection attempts to 1000ms and stops the reconnection process on the 4th attmept

    import { Swampyer } from 'swampyer';
    import { WebsocketJson } from 'swampyer/lib/transports/websocket_json';
    
    //...
    
    const wamp = new Swampyer();
    this.wamp.openAutoReconnect(
      () => new WebsocketJson('ws://localhost:8080/ws')
      {
        realm: 'realm1',
        autoReconnectionDelay: () => 1000,
        stopAutoReconnection: (attempt) => attempt >= 4,
      }
    );
    
    wamp.openEvent.addEventListener(() => {
      // Use the `wamp` object for the WAMP operations
    });

Usage on nodejs

Some adjustments need to be made in order to get this library working in a Nodejs environment:

  • Install a websocket implementation for nodejs (here we use ws as an examples)

  • Run the following at the start of you nodejs code

    const ws = require('ws');
    
    // Other imports ...
    
    global.WebSocket = ws;
    
    // Any code that uses Swampyer ...
    • This will allow WebsocketJson transport provider to work properly in the node environment

Transport Providers

The core library only concerns itself with sending and handling WAMP protocol messages. The method of transporting the WAMP messages to and from a WAMP server, and the serialization/deserialization process is left up to the user. The user must provide a transport provider to the open() method in order to establish a successful WAMP connection.

The library optionally provides WebsocketJson which is a transport provider that allows connection over Websockets and uses JSON to serialize/deserialize the data. This transport provider should satisfy the needs for most users as most WAMP servers communicate over websocket and use the JSON format for the messages.

Custom Transport providers

If a custom transport method or serialization method is required, then the library allows the user to easily create their own custom transport providers.

Custom transport providers must be a class that implements the TransportProvider interface. This ensures that the class implements all the functions that the library needs in order to make use of the transport provider.

See the implementation of WebsocketJson to get an idea of how to implement your own custom transport provider.