src/wampy.js
/**
     * Publish a event to topic
     * @param {string} topicURI
     * @param {string|number|Array|object} payload - can be either a value of any type or null.  Also it
     *                          is possible to pass array and object-like data simultaneously.
     *                          In this case pass a hash-table with next attributes:
     *                          {
     *                             argsList: array payload (may be omitted)
     *                             argsDict: object payload (may be omitted)
     *                          }
     * @param {object} [callbacks] - optional hash table of callbacks:
     *                          { onSuccess: will be called when publishing would be confirmed
     *                            onError: will be called if publishing would be aborted }
     * @param {object} advancedOptions - optional parameter. Must include any or all of the options:
     *                          { exclude: integer|array WAMP session id(s) that won't receive a published event,
     *                                      even though they may be subscribed
     *                            exclude_authid: string|array Authentication id(s) that won't receive
     *                                      a published event, even though they may be subscribed
     *                            exclude_authrole: string|array Authentication role(s) that won't receive
     *                                      a published event, even though they may be subscribed
     *                            eligible: integer|array WAMP session id(s) that are allowed
     *                                      to receive a published event
     *                            eligible_authid: string|array Authentication id(s) that are allowed
     *                                      to receive a published event
     *                            eligible_authrole: string|array Authentication role(s) that are allowed
     *                                      to receive a published event
     *                            exclude_me: bool flag of receiving publishing event by initiator
     *                            disclose_me: bool flag of disclosure of publisher identity (its WAMP session ID)
     *                                      to receivers of a published event }
     * @returns {Wampy}
     */
Publish a event to topic
@param {string} topicURI
@param {string|number|Array|object} payload - can be either a value of any type or null.  Also it
is possible to pass array and object-like data simultaneously.
Publish a event to topic @param { string } topicURI @param { string|number|Array|object } payload - can be either a value of any type or null . Also it is possible to pass array and object - like data simultaneously .
publish (topicURI, payload, callbacks, advancedOptions) {
        let reqId, msg, err = false, hasPayload = false;
        const options = {},
            _optionsConvertHelper = (option, sourceType) => {
                if (advancedOptions[option]) {
                    if (this._isArray(advancedOptions[option]) && advancedOptions[option].length) {
                        options[option] = advancedOptions[option];
                    } else if (typeof advancedOptions[option] === sourceType) {
                        options[option] = [advancedOptions[option]];
                    } else {
                        err = true;
                    }
                }
            };
        if (!this._preReqChecks({ topic: topicURI, patternBased: false, allowWAMP: false }, 'broker', callbacks)) {
            return this;
        }
        if (this._isPlainObject(callbacks)) {
            options.acknowledge = true;
        }
        if (typeof (advancedOptions) !== 'undefined') {
            if (this._isPlainObject(advancedOptions)) {
                _optionsConvertHelper('exclude', 'number');
                _optionsConvertHelper('exclude_authid', 'string');
                _optionsConvertHelper('exclude_authrole', 'string');
                _optionsConvertHelper('eligible', 'number');
                _optionsConvertHelper('eligible_authid', 'string');
                _optionsConvertHelper('eligible_authrole', 'string');
                if (Object.hasOwnProperty.call(advancedOptions, 'exclude_me')) {
                    options.exclude_me = advancedOptions.exclude_me !== false;
                }
                if (Object.hasOwnProperty.call(advancedOptions, 'disclose_me')) {
                    options.disclose_me = advancedOptions.disclose_me === 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;
            }
        }
        reqId = this._getReqId();
        switch (arguments.length) {
            case 1:
                break;
            case 2:
                hasPayload = true;
                break;
            default:
                this._requests[reqId] = {
                    topic: topicURI,
                    callbacks
                };
                hasPayload = true;
                break;
        }
        msg = [WAMP_MSG_SPEC.PUBLISH, reqId, options, topicURI];
        if (hasPayload) {
            if (this._isArray(payload)) {
                msg.push(payload);
            } else if (this._isPlainObject(payload)) {
                if (payload.argsList || payload.argsDict) {
                    if (payload.argsList) {
                        msg.push(payload.argsList);
                    }
                    if (payload.argsDict) {
                        if (msg.length === 4) {
                            msg.push([]);
                        }
                        msg.push(payload.argsDict);
                    }
                } else {
                    msg.push([], payload);
                }
            } else {    
                msg.push([payload]);
            }
        }
        this._send(msg);
        this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;
        this._cache.opStatus.reqId = reqId;
        return this;
    }
publish ( topicURI , payload , callbacks , advancedOptions ) { let reqId , msg , err = false , hasPayload = false ; const options = { } , _optionsConvertHelper = ( option , sourceType ) => { if ( advancedOptions [ option ] ) { if ( this . _isArray ( advancedOptions [ option ] ) && advancedOptions [ option ] . length ) { options [ option ] = advancedOptions [ option ] ; } else if ( typeof advancedOptions [ option ] === sourceType ) { options [ option ] = [ advancedOptions [ option ] ] ; } else { err = true ; } } } ; if ( ! this . _preReqChecks ( { topic : topicURI , patternBased : false , allowWAMP : false } , 'broker' , callbacks ) ) { return this ; } if ( this . _isPlainObject ( callbacks ) ) { options . acknowledge = true ; } if ( typeof ( advancedOptions ) !== 'undefined' ) { if ( this . _isPlainObject ( advancedOptions ) ) { _optionsConvertHelper ( 'exclude' , 'number' ) ; _optionsConvertHelper ( 'exclude_authid' , 'string' ) ; _optionsConvertHelper ( 'exclude_authrole' , 'string' ) ; _optionsConvertHelper ( 'eligible' , 'number' ) ; _optionsConvertHelper ( 'eligible_authid' , 'string' ) ; _optionsConvertHelper ( 'eligible_authrole' , 'string' ) ; if ( Object . hasOwnProperty . call ( advancedOptions , 'exclude_me' ) ) { options . exclude_me = advancedOptions . exclude_me !== false ; } if ( Object . hasOwnProperty . call ( advancedOptions , 'disclose_me' ) ) { options . disclose_me = advancedOptions . disclose_me === 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 ; } } reqId = this . _getReqId ( ) ; switch ( arguments . length ) { case 1 : break ; case 2 : hasPayload = true ; break ; default : this . _requests [ reqId ] = { topic : topicURI , callbacks } ; hasPayload = true ; break ; } msg = [ WAMP_MSG_SPEC . PUBLISH , reqId , options , topicURI ] ; if ( hasPayload ) { if ( this . _isArray ( payload ) ) { msg . push ( payload ) ; } else if ( this . _isPlainObject ( payload ) ) { if ( payload . argsList || payload . argsDict ) { if ( payload . argsList ) { msg . push ( payload . argsList ) ; } if ( payload . argsDict ) { if ( msg . length === 4 ) { msg . push ( [ ] ) ; } msg . push ( payload . argsDict ) ; } } else { msg . push ( [ ] , payload ) ; } } else { msg . push ( [ payload ] ) ; } } this . _send ( msg ) ; this . _cache . opStatus = WAMP_ERROR_MSG . SUCCESS ; this . _cache . opStatus . reqId = reqId ; return this ; }
Publish a event to topic
 @param {string} topicURI
 @param {string|number|Array|object} payload - can be either a value of any type or null.
Publish a event to topic @param { string } topicURI @param { string|number|Array|object } payload - can be either a value of any type or null .
// WAMP_SPEC: [PUBLISH, Request|id, Options|dict, Topic|uri] // WAMP_SPEC: [PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list (, ArgumentsKw|dict)] // It's a wampy unified form of payload passing // assume it's a single value