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

lightstream

v0.4.0

Published

XMPP Framework

Downloads

9

Readme

lightstream

This module trys to implement the xmpp protocol and expose it as javascript functions. Internal it uses XPath to filter and match stanzas comming in.

npm install lightstream

example

var Lightstream = require('lightstream').Lightstream
var xep = require('lightstream/xep')

var lightstream = new Lightstream({
    backend:require('lightstream/backend/node-xmpp'),
}).use(xep.Disco, xep.Ping)
  .connect(process.argv[2], process.argv[3]) // jid, password

lightstream.on('ping', function (stanza) {
   console.log("received a ping", stanza)
})

current extensions

  • Presence
  • Disco (XEP-0030)
  • VCard (XEP-0054, XEP-0153)
  • Roster (XEP-0083, XEP-0144)
  • Ping (XEP-0199)
  • Version (XEP-0092)

API

Lightstream({options})

var lightstream = new Lightstream({
    backend: require('lightstream/backend/<favourite>'),
//  cache: {},
//  timeout: 5000, // 5sec router.request timeout
})

Creates a new Lightstream instance.

Some XEPs (disco, version) require a cache object to store data. Default is just an object.

.connect(jid, password, /*{options}*/)

lightstream.connect('[email protected]', "secret love")

Start a new XMPP connection (by triggering the backend).

.disconnect({options})

lightstream.disconnect()

Close current XMPP connection (by triggering the backend).

.send(stanza)

lightstream.send(new lightstream.xmpp.Message({type:'chat',to:'[email protected]'})
                 .c('body').t('Hello there.'))

Sends a stanza (by triggering the backend).

.use(/*extensions…*/)

var xep = require('lightstream/xep')
lightstream.use(xep.Disco, xep.VCard, xep.Presence, xep.Roster, xep.Ping, xep.Version)

Plug-in one of the extensions or your own implementation of a XEP.

The functions passed in should be constructors that get one argument, the lightstream instance.

.registerExtension(name, extension)

function MyXEP(lightstream) {
    lightstream.registerExtension('ping', this);
//  lightstream.router.match("xpath", {ns:NS.ns}, this.callback.bind(this));
};

Used by XEP implementations to expose themself, so other extensions or developer can use them as dependency for example.

.registerBackend(Backend)

Used internal to set options.backend in Lightstream constructor.

Can be used to reset backend.

.router.match("xpath", /*{namespaces}*/, callback)

lightstream.router.match("self::iq/urn:ping", {urn:'urn:xmpp:ping'}, function (stanza, match) {
    console.log("ping!")
})

Listen for a stanza comming in that matches the given xpath. The second Argument to the callback is the matching element within the Stanza.

implement XEP

if you want to implement your own XEP you get some helpful tools to your hands like ltx with xpath (ltx-xpath)

The method use ,where you'll pass in your XEP, is expecting constructors that get one argument (the lightstream instance). Your implementation can either work just in the background or expose its own api by registering itself by calling lightstream.registerExtension('name', this). You can reach your api via lightstream.extension.name.yourAPIMethod(args).

If you notice that you don't get any stanza with your xpath, a reason for that ATM might be that ltx-xpath is just simply missing the xpath feature that you're using because initially lightstream was intended to run in browser only.

TODO

  • use faster xpath implementation when using node
  • implement more xpath features in ltx-xpath
  • document each xep

Bitdeli Badge