onWS(data) {
        try {
            data = JSON.parse(data);
        } catch (e) {
            return console.error('Error parsing websocket data: ', data);
        }

        if (this.listeners('rawWS').length > 0) {
            this.emit('rawWS', data);
        }

        this.seq = data.s;

        switch (data.op) {
            case OPCodes.EVENT:
                this.handleDispatch(data);
                break;
            case OPCodes.HEARTBEAT:
                this.handleHeartBeat();
                break;
            case OPCodes.RECONNECT:
                this.emit('error', 'Reconnecting to websocket');

                this.disconnect();
                setTimeout(() => {
                    this.connect();
                }, 6000);
                this.connect();
                break;
            case OPCodes.INVALID_SESSION:
                this.emit('warn', 'Invalid session reidenifying');

                if (data.d === true && this.sessionID) {
                    this.resume();
                } else {
                    this.identify();
                }

                this.seq = 0;
                this.sessionID = null;

                this.identify();
                break;
            case OPCodes.HELLO:
                if (this.heartbeatInterval) { clearInterval(this.heartbeatInterval); }

                this.heartbeatInterval = setInterval(() => { this.handleHeartBeat(); }, data.d.heartbeat_interval);
                break;
            case OPCodes.HEARTBEAT_ACK:
                this.ping = new Date() - this.sendTime;

                if (!this.pings) { this.pings = []; }
                if (this.pings.length >= 3) { this.pings.shift(); }

                this.pings.push(this.ping);
                break;
            default:
                console.log('data', util.inspect(data, { depth: 1 }));
                break;
        }
    }
/**
     * Event to handle the data recieved from the websocket and process it properly
     *
     * @param {Object} data data object
     * @returns {void}
     * @memberof Client
     */
Event to handle the data recieved from the websocket and process it properly
@param {Object} data data object
@returns {void}
@memberof Client
Event to handle the data recieved from the websocket and process it properly @param { Object } data data object @returns { void } @memberof Client
onWS(data) {
        try {
            data = JSON.parse(data);
        } catch (e) {
            return console.error('Error parsing websocket data: ', data);
        }
        if (this.listeners('rawWS').length > 0) {
            this.emit('rawWS', data);
        }
        this.seq = data.s;
        switch (data.op) {
            case OPCodes.EVENT:
                this.handleDispatch(data);
                break;
            case OPCodes.HEARTBEAT:
                this.handleHeartBeat();
                break;
            case OPCodes.RECONNECT:
                this.emit('error', 'Reconnecting to websocket');
                this.disconnect();
                setTimeout(() => {
                    this.connect();
                }, 6000);
                this.connect();
                break;
            case OPCodes.INVALID_SESSION:
                this.emit('warn', 'Invalid session reidenifying');
                if (data.d === true && this.sessionID) {
                    this.resume();
                } else {
                    this.identify();
                }
                this.seq = 0;
                this.sessionID = null;
                this.identify();
                break;
            case OPCodes.HELLO:
                if (this.heartbeatInterval) { clearInterval(this.heartbeatInterval); }
                this.heartbeatInterval = setInterval(() => { this.handleHeartBeat(); }, data.d.heartbeat_interval);
                break;
            case OPCodes.HEARTBEAT_ACK:
                this.ping = new Date() - this.sendTime;
                if (!this.pings) { this.pings = []; }
                if (this.pings.length >= 3) { this.pings.shift(); }
                this.pings.push(this.ping);
                break;
            default:
                console.log('data', util.inspect(data, { depth: 1 }));
                break;
        }
    }
onWS ( data ) { try { data = JSON . parse ( data ) ; } catch ( e ) { return console . error ( 'Error parsing websocket data: ' , data ) ; } if ( this . listeners ( 'rawWS' ) . length > 0 ) { this . emit ( 'rawWS' , data ) ; } this . seq = data . s ; switch ( data . op ) { case OPCodes . EVENT : this . handleDispatch ( data ) ; break ; case OPCodes . HEARTBEAT : this . handleHeartBeat ( ) ; break ; case OPCodes . RECONNECT : this . emit ( 'error' , 'Reconnecting to websocket' ) ; this . disconnect ( ) ; setTimeout ( ( ) => { this . connect ( ) ; } , 6000 ) ; this . connect ( ) ; break ; case OPCodes . INVALID_SESSION : this . emit ( 'warn' , 'Invalid session reidenifying' ) ; if ( data . d === true && this . sessionID ) { this . resume ( ) ; } else { this . identify ( ) ; } this . seq = 0 ; this . sessionID = null ; this . identify ( ) ; break ; case OPCodes . HELLO : if ( this . heartbeatInterval ) { clearInterval ( this . heartbeatInterval ) ; } this . heartbeatInterval = setInterval ( ( ) => { this . handleHeartBeat ( ) ; } , data . d . heartbeat_interval ) ; break ; case OPCodes . HEARTBEAT_ACK : this . ping = new Date ( ) - this . sendTime ; if ( ! this . pings ) { this . pings = [ ] ; } if ( this . pings . length >= 3 ) { this . pings . shift ( ) ; } this . pings . push ( this . ping ) ; break ; default : console . log ( 'data' , util . inspect ( data , { depth : 1 } ) ) ; break ; } }
Event to handle the data recieved from the websocket and process it properly
 @param {Object} data data object
 @returns {void}
 @memberof Client
Event to handle the data recieved from the websocket and process it properly @param { Object } data data object @returns { void } @memberof Client