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

tiip-client-js

v0.2.8

Published

Websocket based JS client using protocol tiip

Downloads

21

Readme

tiip-client-js

Websocket based JS client using protocol tiip. Contains patterns req/rep and pub/sub.

npm i -S tiip-client-js

The socket object contains the patterns/calls. The session object is the authentication layer on top of the socket. A session object always has a socket object inside (Note how the different calls look below).

Example of setup and use of the session object:

import TiipSession from 'tiip-client-js';

const session = new TiipSession();

session.connect('wss://echo.websocket.org');

// Try to init with cached credentials
session.init();

// In other case, login with user credentials
session.auth(userId, passphrase);

// Test if we are connected and authenticated
if (session.authenticated) ...

session.logout()

Examples of session.socket calls:

// session object setup as above

// all these calls are of course depending on server API
session.socket.req('main', 'readProfile');
session.socket.req('main', 'readUser', {descending: false});
session.socket.req('weather', 'readWeatherData', {lat: 58.554, lon: 16.713});
session.socket.sub(msg => console.log(msg.toJS()), '#77:3'); // msg will be delivered as an immutablejs map

TiipSession([url, options])

Constructor of a TiipSession object. Returns a TiipSession (with new).

  • url: Full address of websocket endpoint.
  • options: Option object with the following possible key/values:
    • onRelogin: Callback function that is called when a re-login happens.
    • onReloginFail: Callback function called if a re-login fails.
    • customWsClient: A websocket class to use instead of the built-in.
    • onSend: Callback function invoked whenever something is sent on the socket.
    • onReceive: Callback function called when a message is received.
    • onError: Callback function invoked in case of error on the socket.
    • onClose: Callback function called when the socket closes.
    • timeoutOnRequests: Number of milliseconds to use as request timeout (default 30 seconds).

session.connect([url, options]);

Connect the socket, using url and options set via the constructor, or new ones passed here. Returns the session object (to enable chaining).

  • url: Full address of websocket endpoint.
  • options: See description above, for the constructor.

session.init();

Authenticate with possible cached credentials, otherwise rejects. Returns a promise that resolves on a successful response from the server.

session.auth(userId, passphrase, [tenant, target, signal, args]);

Authenticate (sends a tiip init type message). Returns a promise that resolves on a successful response from the server.

  • userId: Id for the identity attempting to login.
  • passphrase: The passphrase for the identity above.
  • tenant: The tenant to login to (optional).
  • target: The target controller (optional).
  • signal: Possible use of signal, depends on server API.
  • args: Possible use of arguments, depends on server API.

session.socket.req(target, signal, [args, tenant]);

Send a request, get a reply (req/rep). Returns a promise that resolves on a successful response from the server. The reply will be an immutablejs map.

  • target: The sub system or micro service that should receive the request.
  • signal: The specific API call or "question". Example: ‘readUser’.
  • args: (optional) An object with arguments for that particular API call (signal). Example: {"name": "Tom"}
  • tenant: Possible use of tenant, depends on server API.

session.socket.sub(callback, channel, [subChannel, tenant, args]);

Starts a subscription to a channel (pub/sub). The messages delivered to the callback will be of type immutablejs map. Returns a promise that resolves on a successful response from the server.

  • callback: The callback function to run when a message arrives on the subscribed channel.
  • channel: The channel to subscribe to. Could be an ID of a channel object in the data model.
  • subChannel: Optional sub-channel within the channel.
  • tenant: Possible use of tenant, depends on server API.
  • args: Possible additional arguments.

session.socket.unsub(channel, [subChannel, tenant, args]);

Ends a subscription. Returns a promise that resolves when the message was sent successfully.

  • channel: Channel corresponding to an earlier sub call (see sub above).
  • subChannel: Sub channel corresponding to an earlier sub call (see sub above).
  • tenant: Tenant corresponding to an earlier sub call (see sub above).
  • args: Possible additional arguments.

session.socket.pub(payload, channel, [subChannel, signal, source, tenant, args]);

Publishes data on a channel. Returns a promise that resolves when the message was sent successfully.

  • payload: Values to publish, as an array.
  • channel: Channel to publish on. Could be an ID of a channel object in the data model.
  • subChannel: Optional sub channel inside the channel.
  • signal: Optional custom signal.
  • source: Optional array of IDs describing the source of the data.
  • tenant: Possible use of tenant, depends on server API.
  • args: Possible additional arguments.

session.logout();

Log out the session and kill the connection. Cached credentials will be erased.