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

urban-airship-connect

v2.0.4

Published

node client for Airship's Real Time Data Streaming

Downloads

81

Readme

urban-airship-connect

Build Status npm install npm version License

A node library for Airship's Real Time Data Streaming (formerly Connect)

Example Usage

var connect = require('urban-airship-connect')

var connectStream = connect('appKey', 'authToken')

connectStream.on('data', function (data) {
  // will be called with each event
})

// write to the stream to set filters/offset/start
connectStream.write({start: 'LATEST'})

API

connect(appKey, authToken[, options]) -> duplexStream

  • appKey is your Airship app key
  • authToken is your RTDS auth token
  • options is an optional object accepting parameters:
    • uri to specify the URI to a running RTDS instance
    • parser to specify a custom JSON parser of signature: parse(String) -> Object; defaults to JSON.parse

The returned duplex stream reads and writes plain JavaScript objects. Writes are posted to RTDS (Real Time Data Streaming), and the responding events are emitted as plain JavaScript objects over time.

Notes

If an error is encountered during a request, a bad status code is encountered, or JSON parsing of an event fails, an 'error' event will be emitted with the error attached. For JSON parse errors, the blob that caused the error will be available as the blob property of the error.

It is possible for a Custom Event value to be a number that cannot be parsed by JavaScript see docs. If you suspect you might encounter this issue, you may want to provide your own JSON parser, see API.

This module will handle connecting and maintaining a connection to Airship's Real Time Data Streaming service. If its connection is ever severed, it will do its best to resume at the last seen offset.

The resume_offset is not stored externally, so if the process using this module is killed, crashes, or otherwise exits it will be lost. In general it is advisable to track this offset yourself.

Writing offset to disk

var fs = require('fs')

var connect = require('urban-airship-connect')
var lookupStream = require('dotpath-stream')
var writeFile = require('file-replace-stream')

var connectStream = connect('appKey', 'authToken')
var filters = {}

// set up our pipeline for saving offsets
connectStream
  // pull out just the `offset` property
  .pipe(lookupStream('offset'))
  // write it to `last_offset.txt`
  .pipe(writeFile('last_offset.txt'))

try {
  // try to read our offset file
  filters.resume_offset = fs.readFileSync('last_offset.txt', {encoding: 'utf8'})
} catch (err) {
  // fall back to starting at latest offset
  filters.start = 'LATEST'
}

// write the filters to RTDS to start streaming events
connectStream.write(filters)

Notes

  • writeFile could be swapped out for any writable stream for persistence.
  • If streams aren't your thing, you could alternatively listen to the data event of connectStream and persist the offset property from the passed event however you please.

Command-line Interface

A simple command-line utility ua-connect is bundled along with this module. It should be mostly used for testing your credentials or other aspects of your RTDS setup, not for anything "mission-critical".

Usage

ua-connect <app-key> <token> [options]

Where options are:

  • --uri <uri> Use a custom uri for RTDS
  • --offset <offset> Start at <offset>
  • --earliest Start at earliest offset
  • --key <app-key> Explicitly set app key
  • --token <token> Explicitly set token

License

Apache-2.0