Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

agora

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agora

simple websocket communication module

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-9.09%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 20 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc