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

satori-rtm-sdk

v1.2.2

Published

JavaScript SDK for Satori RTM

Downloads

4

Readme

JavaScript SDK for Satori RTM

Use the JavaScript SDK for the Satori RTM to create browser-based applications or server-based applications running within Node.js. The applications use the RTM to publish and subscribe.

JavaScript SDK Installation

Browser Installation

To use the JavaScript SDK from a browser-based application, include the SDK from the CDN and create an RTM client instance:

<script src="https://satori-a.akamaihd.net/satori-rtm-sdk/v1.2.2/sdk.min.js"></script>

and then

// create an RTM client instance
var rtm = new RTM("YOUR_ENDPOINT", "YOUR_APPKEY");

Note: You can find the application key and endpoint on the Appkey Info page for your app in the Dev Portal.

Node.js Installation

  1. Install the JavaScript SDK with the following command from NPM:
npm install 'satori-rtm-sdk'
  1. In your application file <app_name>.js, use the following code to create an RTM client instance:
var RTM = require("satori-rtm-sdk");

// create an RTM client instance
var rtm = new RTM("YOUR_ENDPOINT", "YOUR_APPKEY");

Note: You can find the application key and endpoint for your app in the Dev Portal.

JavaScript Sample Code

// create a new subscription with "your-channel" name
var channel = rtm.subscribe("your-channel", RTM.SubscriptionMode.SIMPLE);

// add channel data handlers

// channel receives any published message
channel.on("rtm/subscription/data", function(pdu) {
    pdu.body.messages.forEach(console.log);
});

// client enters 'connected' state
rtm.on("enter-connected", function() {
    rtm.publish("your-channel", {key: "value"});
});

// client receives any PDU and PDU is passed as a parameter
rtm.on("data", function(pdu) {
    if (pdu.action.endsWith("/error")) {
        rtm.restart();
    }
});

// start the client
rtm.start();

Documentation

You can view the latest JavaScript SDK documentation here.

Generating API docs

$ npm run docs

The generated API documentation will apear in the ./docs folder.

Assembling from sources

$ git clone https://github.com/satori-com/satori-rtm-sdk-js.git
$ cd satori-rtm-sdk
$ npm install
$ npm run build

The assembled JS output will appear in the ./dist/ directory.

Binary data support

RTM supports the CBOR subprotocol to work with binary data. Binary data is represented as Uint8Array.

var client = new RTM("YOUR_ENDPOINT", "YOUR_APPKEY", {protocol: 'cbor'});

client.on('enter-connected', function () {
  var message = {
    who: 'zebra',
    where: new Uint8Array([1,2,3,4,5])
  };
  client.publish('animals', message, function (pdu) {
    console.log('Message published:', pdu);
  });
});

client.start();

Using HTTPS Proxy (NodeJS only)

The SDK supports working through an https (not http) proxy.

When creating a new client specify proxyAgent in options like this:

var client = new RTM(endpoint, appKey, {
    proxyAgent: proxyAgent
});

Use any custom http.Agent implementation like:

NodeJS example with using https-proxy-agent:

var HttpsProxyAgent = require('https-proxy-agent');

var client = new RTM("YOUR_ENDPOINT", "YOUR_APPKEY", {
    proxyAgent: HttpsProxyAgent('http://127.0.0.1:3128')
});

Verbose logging of all incoming and outcoming PDUs

You can enable dumping of all PDUs either from your code

var RTM = require("satori-rtm-sdk");
RTM.logger.DEBUG = true;

// create an RTM client instance
var rtm = new RTM("YOUR_ENDPOINT", "YOUR_APPKEY");

or by setting DEBUG_SATORI_SDK environment variable prior to running your application

$ export DEBUG_SATORI_SDK=true
$ node myapp.js

Testing

The SDK includes an integration test suite. The tests connect to RTM, so you need to provide RTM credentials.

The credentials.json file must include the following key-value pairs:

{
  "endpoint": "YOUR_ENDPOINT",
  "appkey": "YOUR_APPKEY",
  "auth_role_name": "YOUR_ROLE",
  "auth_role_secret_key": "YOUR_SECRET",
  "auth_restricted_channel": "YOUR_RESTRICTED_CHANNEL"
}
  • endpoint is your customer-specific endpoint for RTM access.
  • appkey is your application key.
  • auth_role_name is a role name that permits to publish / subscribe to auth_restricted_channel. Must be not default.
  • auth_role_secret_key is a secret key for auth_role_name.
  • auth_restricted_channel is a channel with subscribe and publish access for auth_role_name role only.

After setting up credentials.json, just type npm test at the command line.