Neurologically Paralyzing Mouseovers
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    musherpublic

    muhser.js

    NPM Version Build Status Dependencies

    Musher is a javascript and node.js library based on mqtt.

    Build

    npm install
    grunt

    Usage

    Subscribe with a handler.

    var musher = require('../');
     
    var socket = musher.connect({host: 'localhost'});
     
    socket.on('connected', function () {
        console.log('connected');
    });
    socket.on('reconnect', function () {
        console.log('reconnect');
    });
    socket.on('offline', function () {
        console.log('offline');
    });
    socket.on('error', function (err) {
        console.error(err);
    });
     
    socket.subscribe('/users/:userid/message/:messageid/*', function (data, route) {
        console.log(data);            // { hello: 'world' }
        console.log(route.topic);     // '/users/ty/message/4321/ping'
        console.log(route.params);    // { userid: 'ty', messageid: 4321 }
        console.log(route.splats);    // [ 'ping' ]
        console.log(route.path);      // '/users/:userid/message/:messageid/:method'
        console.log(route.event);     // 'message'
    });
     
    socket.publish('/users/ty/message/4321/ping', {hello: 'world'});

    Subscribe with event.

    var musher = require('../');
     
    var socket = musher.connect({host: 'localhost'});
     
    socket.on('connected', function () {
        console.log('connected');
    });
    socket.on('reconnect', function () {
        console.log('reconnect');
    });
    socket.on('offline', function () {
        console.log('offline');
    });
    socket.on('error', function (err) {
        console.error(err);
    });
     
    var channel = socket.subscribe('/users/:userid/message/:messageid/*');
    channel.on('data', function (data, route) {
        console.log(data);            // { hello: 'world' }
        console.log(route.topic);     // '/users/ty/message/4321/ping'
        console.log(route.params);    // { userid: 'ty', messageid: 4321 }
        console.log(route.splats);    // [ 'ping' ]
        console.log(route.path);      // '/users/:userid/message/:messageid/:method'
        console.log(route.event);     // 'data'
    });
     
    socket.publish('/users/ty/message/4321/ping', 'data', {hello: 'world'});
     

    The built libraries will be in build directory

    install

    npm i musher

    Downloadsweekly downloads

    42

    version

    0.3.0

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar