js/clients/SparkCore.js
function (name, uri, token, callback, once) {
        var tokenHex = (token) ? utilities.toHexString(token) : null;
        var beVerbose = settings.showVerboseCoreLogs;

        //TODO: failWatch?  What kind of timeout do we want here?

        //adds a one time event
        var that = this,
            evtName = ('msg_' + name).toLowerCase(),
            handler = function (msg) {

                if (uri && (msg.getUriPath().indexOf(uri) != 0)) {
                    if (beVerbose) {
                        logger.log("uri filter did not match", uri, msg.getUriPath(), { coreID: that.getHexCoreID() });
                    }
                    return;
                }

                if (tokenHex && (tokenHex != msg.getTokenString())) {
                    if (beVerbose) {
                        logger.log("Tokens did not match ", tokenHex, msg.getTokenString(), { coreID: that.getHexCoreID() });
                    }
                    return;
                }

                if (once) {
                    that.removeListener(evtName, handler);
                }

                process.nextTick(function () {
                    try {
                        if (beVerbose) {
                            logger.log('heard ', name, { coreID: that.coreID });
                        }
                        callback(msg);
                    }
                    catch (ex) {
                        logger.error("listenFor - caught error: ", ex, ex.stack, { coreID: that.getHexCoreID() });
                    }
                });
            };

        //logger.log('listening for ', evtName);
        this.on(evtName, handler);

        return handler;
    }
function (name, uri, token, callback, once) {
        var tokenHex = (token) ? utilities.toHexString(token) : null;
        var beVerbose = settings.showVerboseCoreLogs;

        //TODO: failWatch?  What kind of timeout do we want here?

        //adds a one time event
        var that = this,
            evtName = ('msg_' + name).toLowerCase(),
            handler = function (msg) {

                if (uri && (msg.getUriPath().indexOf(uri) != 0)) {
                    if (beVerbose) {
                        logger.log("uri filter did not match", uri, msg.getUriPath(), { coreID: that.getHexCoreID() });
                    }
                    return;
                }

                if (tokenHex && (tokenHex != msg.getTokenString())) {
                    if (beVerbose) {
                        logger.log("Tokens did not match ", tokenHex, msg.getTokenString(), { coreID: that.getHexCoreID() });
                    }
                    return;
                }

                if (once) {
                    that.removeListener(evtName, handler);
                }

                process.nextTick(function () {
                    try {
                        if (beVerbose) {
                            logger.log('heard ', name, { coreID: that.coreID });
                        }
                        callback(msg);
                    }
                    catch (ex) {
                        logger.error("listenFor - caught error: ", ex, ex.stack, { coreID: that.getHexCoreID() });
                    }
                });
            };

        //logger.log('listening for ', evtName);
        this.on(evtName, handler);

        return handler;
    }
function ( name , uri , token , callback , once ) { var tokenHex = ( token ) ? utilities . toHexString ( token ) : null ; var beVerbose = settings . showVerboseCoreLogs ; //TODO: failWatch?  What kind of timeout do we want here? //adds a one time event var that = this , evtName = ( 'msg_' + name ) . toLowerCase ( ) , handler = function ( msg ) { if ( uri && ( msg . getUriPath ( ) . indexOf ( uri ) != 0 ) ) { if ( beVerbose ) { logger . log ( "uri filter did not match" , uri , msg . getUriPath ( ) , { coreID : that . getHexCoreID ( ) } ) ; } return ; } if ( tokenHex && ( tokenHex != msg . getTokenString ( ) ) ) { if ( beVerbose ) { logger . log ( "Tokens did not match " , tokenHex , msg . getTokenString ( ) , { coreID : that . getHexCoreID ( ) } ) ; } return ; } if ( once ) { that . removeListener ( evtName , handler ) ; } process . nextTick ( function ( ) { try { if ( beVerbose ) { logger . log ( 'heard ' , name , { coreID : that . coreID } ) ; } callback ( msg ) ; } catch ( ex ) { logger . error ( "listenFor - caught error: " , ex , ex . stack , { coreID : that . getHexCoreID ( ) } ) ; } } ) ; } ; //logger.log('listening for ', evtName); this . on ( evtName , handler ) ; return handler ; }
Adds a listener to our secure message stream
@param name the message type we're waiting on
@param uri - a particular function / variable?
@param token - what message does this go with? (should come from sendMessage)
@param callback what we should call when we're done
@param [once] whether or not we should keep the listener after we've had a match
Adds a listener to our secure message stream