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

agora

v0.0.2

Published

simple websocket communication module

Downloads

33

Readme

agora Build Status

dead simple websocket communication module.

Stream JSON data easily with events between clients and server. You can broadcast to all clients, or just one.

runs in node and in the browser with browserify!

It's basically a simple wrapper built around the awesome module emit.io

install

npm install agora

server example

var Server = require('agora').Server;

var server = new Server({
    port: 8000
});

server.on('connection', function (conn) {

    var id = conn.id;

    /* returned inStream is an emitter */
    var inStream = conn.inStream;

    /* you can emit to the outStream and data will
     * be piped off to the client */
    var outStream = conn.outStream;

    /*
     * listen on a per client basis
     * in this case, we listen for the 'addOne' event from the client,
     * and we can wrangle it, then send it back with an 'addResult' event
     */
    inStream.on('addOne', function (data) {
        server.emitTo(outStream, 'addResult', data += 1);
    });

    /* emit to one client */
    server.emitTo(outStream, 'ready', id);
});

/* or emit to everyone! */
setInterval(function () {
    server.emit('serverTime', new Date());
}, 1000);

client example

var Client = require('agora').Client;
var client = new Client();

/*
 * once we get the ready event from the server,
 * we're good to go! we can now start emitting
 * and the server will hear the events!
 */
client.on('ready', function (id) {
    client.id = id;
    client.emit('addOne', 1);
});

/*
 * once you've built your server API, you can
 * listen to events. Here we've set up
 * an addResult event.
 */
client.on('addResult', function (data) {
    var div = document.getElementById('#someDiv');
    div.innerHTML = data;

    setTimeout(function () {
        client.emit('addOne', data);
    }, 5000);
});

client.on('serverTime', function (date) {
    console.log(date);
});

/* connect the client! */
client.connect('ws://localhost:8000');

methods

var Signals = require('agora');

var server = new Signals.Server(opts)

Creates a new instance of a websocket server.

opts.port | specify the port number int

var client = new Signals.Client()

Creates a new instance of a websocket client.

client.connect(address)

Connects to the websocket server at the provided address | String.

license

MIT