src/wampy.js
/**
     * Unsubscribe from topic
     * @param {string} topicURI
     * @param {function|object} callbacks - if it is a function - it will be treated as
     *                          published event callback to remove or it can be hash table of callbacks:
     *                          { onSuccess: will be called when unsubscribe would be confirmed
     *                            onError: will be called if unsubscribe would be aborted
     *                            onEvent: published event callback to remove }
     * @returns {Wampy}
     */
Unsubscribe from topic
@param {string} topicURI
@param {function|object} callbacks - if it is a function - it will be treated as
published event callback to remove or it can be hash table of callbacks:
{ onSuccess: will be called when unsubscribe would be confirmed
onError: will be called if unsubscribe would be aborted
onEvent: published event callback to remove }
@returns {Wampy}
Unsubscribe from topic @param { string } topicURI @param { function|object } callbacks - if it is a function - it will be treated as published event callback to remove or it can be hash table of callbacks : { onSuccess : will be called when unsubscribe would be confirmed onError : will be called if unsubscribe would be aborted onEvent : published event callback to remove } @returns { Wampy }
unsubscribe (topicURI, callbacks) {
        let reqId, i = -1;
        if (!this._preReqChecks(null, 'broker', callbacks)) {
            return this;
        }
        if (this._subscriptions[topicURI]) {
            reqId = this._getReqId();
            if (typeof (callbacks) === 'undefined') {
                this._subscriptions[topicURI].callbacks = [];
                callbacks = {};
            } else if (typeof callbacks === 'function') {
                i = this._subscriptions[topicURI].callbacks.indexOf(callbacks);
                callbacks = {};
            } else if (callbacks.onEvent && typeof callbacks.onEvent === 'function') {
                i = this._subscriptions[topicURI].callbacks.indexOf(callbacks.onEvent);
            } else {
                this._subscriptions[topicURI].callbacks = [];
            }
            if (i >= 0) {
                this._subscriptions[topicURI].callbacks.splice(i, 1);
            }
            if (this._subscriptions[topicURI].callbacks.length) {
                this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;
                return this;
            }
            this._requests[reqId] = {
                topic: topicURI,
                callbacks
            };
            this._send([WAMP_MSG_SPEC.UNSUBSCRIBE, reqId, this._subscriptions[topicURI].id]);
        } else {
            this._cache.opStatus = WAMP_ERROR_MSG.NON_EXIST_UNSUBSCRIBE;
            if (this._isPlainObject(callbacks) && callbacks.onError) {
                callbacks.onError({ error: this._cache.opStatus.description });
            }
            return this;
        }
        this._cache.opStatus = WAMP_ERROR_MSG.SUCCESS;
        this._cache.opStatus.reqId = reqId;
        return this;
    }
unsubscribe ( topicURI , callbacks ) { let reqId , i = - 1 ; if ( ! this . _preReqChecks ( null , 'broker' , callbacks ) ) { return this ; } if ( this . _subscriptions [ topicURI ] ) { reqId = this . _getReqId ( ) ; if ( typeof ( callbacks ) === 'undefined' ) { this . _subscriptions [ topicURI ] . callbacks = [ ] ; callbacks = { } ; } else if ( typeof callbacks === 'function' ) { i = this . _subscriptions [ topicURI ] . callbacks . indexOf ( callbacks ) ; callbacks = { } ; } else if ( callbacks . onEvent && typeof callbacks . onEvent === 'function' ) { i = this . _subscriptions [ topicURI ] . callbacks . indexOf ( callbacks . onEvent ) ; } else { this . _subscriptions [ topicURI ] . callbacks = [ ] ; } if ( i >= 0 ) { this . _subscriptions [ topicURI ] . callbacks . splice ( i , 1 ) ; } if ( this . _subscriptions [ topicURI ] . callbacks . length ) { this . _cache . opStatus = WAMP_ERROR_MSG . SUCCESS ; return this ; } this . _requests [ reqId ] = { topic : topicURI , callbacks } ; this . _send ( [ WAMP_MSG_SPEC . UNSUBSCRIBE , reqId , this . _subscriptions [ topicURI ] . id ] ) ; } else { this . _cache . opStatus = WAMP_ERROR_MSG . NON_EXIST_UNSUBSCRIBE ; if ( this . _isPlainObject ( callbacks ) && callbacks . onError ) { callbacks . onError ( { error : this . _cache . opStatus . description } ) ; } return this ; } this . _cache . opStatus = WAMP_ERROR_MSG . SUCCESS ; this . _cache . opStatus . reqId = reqId ; return this ; }
Unsubscribe from topic
 @param {string} topicURI
 @param {function|object} callbacks - if it is a function - it will be treated as
                          published event callback to remove or it can be hash table of callbacks:
                          { onSuccess: will be called when unsubscribe would be confirmed
                            onError: will be called if unsubscribe would be aborted
                            onEvent: published event callback to remove }
 @returns {Wampy}
Unsubscribe from topic @param { string } topicURI @param { function|object } callbacks - if it is a function - it will be treated as published event callback to remove or it can be hash table of callbacks : { onSuccess : will be called when unsubscribe would be confirmed onError : will be called if unsubscribe would be aborted onEvent : published event callback to remove } @returns { Wampy }
// There are another callbacks for this topic // WAMP_SPEC: [UNSUBSCRIBE, Request|id, SUBSCRIBED.Subscription|id]