src/wampy.js
/**
     * RPC registration for invocation
     * @param {string} topicURI
     * @param {function|object} callbacks - if it is a function - it will be treated as rpc itself
     *                          or it can be hash table of callbacks:
     *                          { rpc: registered procedure
     *                            onSuccess: will be called on successful registration
     *                            onError: will be called if registration would be aborted }
     * @param {object} advancedOptions - optional parameter. Must include any or all of the options:
     *                          {
     *                              match: string matching policy ("prefix"|"wildcard")
     *                              invoke: string invocation policy ("single"|"roundrobin"|"random"|"first"|"last")
     *                          }
     * @returns {Wampy}
     */
RPC registration for invocation
@param {string} topicURI
@param {function|object} callbacks - if it is a function - it will be treated as rpc itself
or it can be hash table of callbacks:
{ rpc: registered procedure
onSuccess: will be called on successful registration
onError: will be called if registration would be aborted }
@param {object} advancedOptions - optional parameter.
RPC registration for invocation @param { string } topicURI @param { function|object } callbacks - if it is a function - it will be treated as rpc itself or it can be hash table of callbacks : { rpc : registered procedure onSuccess : will be called on successful registration onError : will be called if registration would be aborted } @param { object } advancedOptions - optional parameter .
register (topicURI, callbacks, advancedOptions) {
        let reqId, patternBased = false, err = false;
        const options = {};
        if (typeof (advancedOptions) !== 'undefined') {
            if (this._isPlainObject(advancedOptions)) {
                if (Object.hasOwnProperty.call(advancedOptions, 'match')) {
                    if (/prefix|wildcard/.test(advancedOptions.match)) {
                        options.match = advancedOptions.match;
                        patternBased = true;
                    } else {
                        err = true;
                    }
                }
                if (Object.hasOwnProperty.call(advancedOptions, 'invoke')) {
                    if (/single|roundrobin|random|first|last/.test(advancedOptions.invoke)) {
                        options.invoke = advancedOptions.invoke;
                    } else {
                        err = true;
                    }
                }
            } else {
                err = true;
            }
            if (err) {
                this._cache.opStatus = WAMP_ERROR_MSG.INVALID_PARAM;
                if (this._isPlainObject(callbacks) && callbacks.onError) {
                    callbacks.onError({ error: this._cache.opStatus.description });
                }
                return this;
            }
        }
        if (!this._preReqChecks({ topic: topicURI, patternBased: patternBased, allowWAMP: false },
            'dealer',
            callbacks)) {
            return this;
        }
        if (typeof callbacks === 'function') {
            callbacks = { rpc: callbacks };
        } else if (!this._isPlainObject(callbacks) || typeof (callbacks.rpc) === 'undefined') {
            this._cache.opStatus = WAMP_ERROR_MSG.NO_CALLBACK_SPEC;
            if (this._isPlainObject(callbacks) && callbacks.onError) {
                callbacks.onError({ error: this._cache.opStatus.description });
            }
            return this;
        }
        if (!this._rpcRegs[topicURI] || !this._rpcRegs[topicURI].callbacks.length) {
            reqId = this._getReqId();
            this._requests[reqId] = {
                topic: topicURI,
                callbacks
            };
            this._send([WAMP_MSG_SPEC.REGISTER, reqId, options, topicURI]);
            this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;
            this._cache.opStatus.reqId = reqId;
        } else {    
            this._cache.opStatus = WAMP_ERROR_MSG.RPC_ALREADY_REGISTERED;
            if (this._isPlainObject(callbacks) && callbacks.onError) {
                callbacks.onError({ error: this._cache.opStatus.description });
            }
        }
        return this;
    }
register ( topicURI , callbacks , advancedOptions ) { let reqId , patternBased = false , err = false ; const options = { } ; if ( typeof ( advancedOptions ) !== 'undefined' ) { if ( this . _isPlainObject ( advancedOptions ) ) { if ( Object . hasOwnProperty . call ( advancedOptions , 'match' ) ) { if ( / prefix|wildcard / . test ( advancedOptions . match ) ) { options . match = advancedOptions . match ; patternBased = true ; } else { err = true ; } } if ( Object . hasOwnProperty . call ( advancedOptions , 'invoke' ) ) { if ( / single|roundrobin|random|first|last / . test ( advancedOptions . invoke ) ) { options . invoke = advancedOptions . invoke ; } else { err = true ; } } } else { err = true ; } if ( err ) { this . _cache . opStatus = WAMP_ERROR_MSG . INVALID_PARAM ; if ( this . _isPlainObject ( callbacks ) && callbacks . onError ) { callbacks . onError ( { error : this . _cache . opStatus . description } ) ; } return this ; } } if ( ! this . _preReqChecks ( { topic : topicURI , patternBased : patternBased , allowWAMP : false } , 'dealer' , callbacks ) ) { return this ; } if ( typeof callbacks === 'function' ) { callbacks = { rpc : callbacks } ; } else if ( ! this . _isPlainObject ( callbacks ) || typeof ( callbacks . rpc ) === 'undefined' ) { this . _cache . opStatus = WAMP_ERROR_MSG . NO_CALLBACK_SPEC ; if ( this . _isPlainObject ( callbacks ) && callbacks . onError ) { callbacks . onError ( { error : this . _cache . opStatus . description } ) ; } return this ; } if ( ! this . _rpcRegs [ topicURI ] || ! this . _rpcRegs [ topicURI ] . callbacks . length ) { reqId = this . _getReqId ( ) ; this . _requests [ reqId ] = { topic : topicURI , callbacks } ; this . _send ( [ WAMP_MSG_SPEC . REGISTER , reqId , options , topicURI ] ) ; this . _cache . opStatus = WAMP_ERROR_MSG . SUCCESS ; this . _cache . opStatus . reqId = reqId ; } else { this . _cache . opStatus = WAMP_ERROR_MSG . RPC_ALREADY_REGISTERED ; if ( this . _isPlainObject ( callbacks ) && callbacks . onError ) { callbacks . onError ( { error : this . _cache . opStatus . description } ) ; } } return this ; }
RPC registration for invocation
 @param {string} topicURI
 @param {function|object} callbacks - if it is a function - it will be treated as rpc itself
                          or it can be hash table of callbacks:
                          { rpc: registered procedure
                            onSuccess: will be called on successful registration
                            onError: will be called if registration would be aborted }
 @param {object} advancedOptions - optional parameter.
RPC registration for invocation @param { string } topicURI @param { function|object } callbacks - if it is a function - it will be treated as rpc itself or it can be hash table of callbacks : { rpc : registered procedure onSuccess : will be called on successful registration onError : will be called if registration would be aborted } @param { object } advancedOptions - optional parameter .
// no such registration or processing unregistering // WAMP SPEC: [REGISTER, Request|id, Options|dict, Procedure|uri] // already have registration with such topicURI