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

socket.io-wamp

v0.1.1

Published

A simple client of PUBSUB and RPC interface for Socket.io server

Downloads

5

Readme

socket.io-wamp

A simple client of PUBSUB and RPC interface for Socket.io server

Installation

Bower

bower install socket.io-wamp

npm

npm install socket.io-wamp

# dependency
npm install socket.io-client

Usage

Include on your page

<script src="bower_components/socket.io-wamp.js" charset="utf-8"></script>

Or with Node

Install the dependency socket.io-client

npm install socket.io-client

Then, on your script:

// requires socket.io-client
var io = require('socket.io-client')('http://localhost:3000');
require("socket.io-wamp")(io);

Using the library

// call io.connect() to apply the PUBSUB and RPC interface
socket = io.connect();

socket.on('connect', function (client) {

    // PubSub

    // subscribe
    client.subscribe("chat.message", function (message) {
        // do Something
    })
    // publish
    client.publish("chat.message", "send a message here");

    // RPC
    var nickname;
    client.register("chat.nick.set", function (nick) {
        nickname = nick;
        return "new nick is: " + nick
    })

    client.call("chat.nick.set", "Batman");

}

PubSub

Subscribe a topic

client.subscribe("chat.message", function (message) {
    // do Something
    $('#messages').append($('<li>').text(message));
})
.then(function (pack) {
    console.log("The topic was registred on server", pack);
})
.catch(function(err) {
    console.error("Opss! Error", err);
});

Publish to a topic

client.publish("chat.message", "Send this message for all subscribers")
.then(function () {
    console.log("OK");
})
.catch(function(err) {
    console.error("Opss! Error", err);
});

RPC - Remote Procedure Call

Register a topic

var users = []
client.register("chat.add.user", function (username) {
    // do Something
    users.push(username);
    return "Users online: " + users.length
})
.then(function (pack) {
    console.log("The topic was registered on server", pack);
})
.catch(function(err) {
    console.error("Opss! Error", err);
});

Call to a topic

client.call("chat.add.user", "Batman")
.then(function (result) {
    console.log("How many users?" + result); // How many users? Users online: 1
})
.catch(function(err) {
    console.error("Opss! Error", err);
});

Working with Promises

The Socket.io-wamp added a promise library for support with async responses.

var q = io.Q; // promise support lib

Then, you can return a promise to call() procedures.

var users = [];
var q = io.Q; // you can use any promise library

client.register("chat.add.user", function (username) {
    var deferred = q.defer();

    db.insert({name: username, last_join_at: new Date()})
    .then(function (docs) {
        deferred.resolve("Users online: " + docs.length)
    })
    promise.catch(function (err) {
        deferred.reject(err)
    });

    return deferred.promise;
})
.then(function (pack) {
    console.log("The topic was registered on server", pack);
})
.catch(function(err) {
    console.error("Opss! Error", err);
});

Issues

On github [https://github.com/rafael-freitas/socket.io-wamp/issues]