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

truflux-msg

v2.1.0

Published

Message definition module for truflux

Downloads

4

Readme

Truflux Message

To install

npm install --save truflux-msg

This is the definition module for truflux https://www.npmjs.com/package/truflux

The truflux message definition is designed to be seperate from the actual messaging system to allow you to seperate protocol from implementation

New in v2.0.0

To provide better decoupling, truflux-msg now no longer supports the enforce Schema methods any more, which have been moved to a separate module, truflux-msg-schema. The prebuilt browser versions have removed to allow one to include their own specialized build if need be

Example

//In your protocol definition file lets call it protocol.js
var Message  = require('truflux-msg'),
    protocol = new Message({noThrow:true});

protocol.add('error')
        .add('echo' );

module.exports = protocol;
//Now for your implementation
var protocol = require('./protocol'),
	truflux  = require('truflux');
 
protocol.specify("echo",function(data,socket)
{
    console.log(data);
});


var Client= new truflux.Client({host:"localhost",msg:protocol}));

Client.connect()
	  .on('connected',function(sock)
	  {
		    sock.send('echo','Atreyuuuu!');
		    //Alternatively, you can reference the message ID directly which is preferable as you do not need a string lookup
		    sock.send(protocol.id.echo,'Atreyuuu');
	  });
 ...

API

In case it wasn't apparent from above , the preferred method of accessing the integer value of a message is to use msgObjectInstance.id.identifierName , this can be used to obtain values for has and call

Constructor(options)

/**
 * Creates a new TrufluxMessage
 * @param {Object}  [options] 
 * @param {Boolean} [options.noThrow] If true, we will not throw an error for unimplemented functions for "add" 
 */

add(identifier,[func])

/**
 * Adds a function handler for the provided string
 * @param  {String} identifier 
 * @param  {Function} [func]  function(data,socket)   
 * @return {TrufluxMessage}    
 */

specify(identifier,func)

    /**
     * Specifies the function to be used for the provided identifier. Used to override add
     * @param  {String|Number} identifier 
     * @param  {Function} func function(data,socket)       
     * @return {TrufluxMessage}            
     */

call(id,payload,socket)

/**
 * Calls the handler associated with the message ID. NOTE This will throw an error if there is no 
 * handler associated. It is assumed you have called "has" before hand
 * @param  {Number} id      
 * @param  {Any} payload 
 * @param  {TrufluxSocket} socket
 * @return {TrufluxMessage}   
 */

has(messageID)

/**
 * Checks to see if it has the specified message handler
 * @param  {Number}  messageID 
 * @return {Boolean}       
 */

changeMessageID(oldId,newID)

/**
 * Changes the ID of a message handler. Ideal if you need to make sure that the ID has a certain value 
 * @param  {Number|String} oldId The old identifer of the handler
 * @param  {Number} newID  The new ID value 
 * @throws {Error } If the newID is already taken
 * @return {TrufluxMessage}       
 */