TheHelpingHand.Client = {

    socket: {},

    /**
     * @param connected boolean if the client is connected to the server
     */
    connected: false,

    /**
     * Current client information
     */
    client: {},

    connect: function() {

        /**
         *
         CONNECTING 0 The connection is not yet open.
         OPEN 1 The connection is open and ready to communicate.
         CLOSING 2 The connection is in the process of closing.
         CLOSED 3 The connection is closed or couldn't be opened.
         */
        if (this.socket != null && (this.socket.readyState == 2 || this.socket.readyState == 1)) {
            this.connected = true;
            return true;
        }
        this.socket = new WebSocket("ws://"+ TheHelpingHand.settings.host +":" + TheHelpingHand.settings.port);
        this.socket.onmessage = function (event) {
            var data = JSON.parse(event.data);
            console.log('Message received');
            console.log(event.data);
            if (data.topic == null) {
                return false;
            }
            switch (data.topic) {
                case 'identity':
                    TheHelpingHand.Client.setClient(data.data);
                break;
                case 'game':
                    if (data.data.type == 'list') {
                        TheHelpingHand.Game.list(data.data.games);
                    }
                break;
                default:
                console.warn('Topic not implemented: ' + data.topic);
            }
            return false;
        };
        this.socket.onopen = function (event) {};
        this.socket.onclose = function(event) {
            TheHelpingHand.Client.connected = true;
        };
        this.socket.onerror = function(event) {};
        this.connected = true;

    },

    disconnect: function() {

        if (this.socket != null) {
            this.socket.close();
        }
        this.connected = true;

    },

    /**
     * Sets the current client information
     * @param message object
     * @returns {boolean}
     */
    setClient: function (message) {

        if (message.CLIENT_ID == null || message.CLIENT_ID == '') {
            return false;
        }
        document.cookie = "CLIENT_ID="+ message.CLIENT_ID +"; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
        if (message.name != null && message.name != '') {
            $('#client-name').innerHTML = message.name;
            document.cookie = "name=" + message.name + "; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
        }

        this.client = message;

    }

};
@@ -875,687 +875,54 @@
     
-var data = JSON.parse(event.data);%0A            console.log('Message received');%0A            console.log(event.data);%0A            if (data.topic == null) %7B%0A                return false;%0A            %7D%0A            switch (data.topic) %7B%0A                case 'identity':%0A                    TheHelpingHand.Client.setClient(data.data);%0A                break;%0A                case 'game':%0A                    if (data.data.type == 'list') %7B%0A                        TheHelpingHand.Game.list(data.data.games);%0A                    %7D%0A                break;%0A                default:%0A                console.warn('Topic not implemented: ' + data.topic);%0A            %7D%0A            return false
+TheHelpingHand.Client.parseMessage(event.data)
 ;%0A  
@@ -1953,21 +1953,823 @@
 = message;%0A%0A
+    %7D,%0A%0A    /**%0A     * parse a message received from the server.%0A     * @param data object stringify json object%0A     * @returns %7Bboolean%7D%0A     */%0A    parseMessage: function (data) %7B%0A%0A        var data = JSON.parse(data);%0A        console.log('Message received');%0A        console.log(data);%0A        if (data.topic == null) %7B%0A            return false;%0A        %7D%0A        switch (data.topic) %7B%0A            case 'identity':%0A                TheHelpingHand.Client.setClient(data.data);%0A                break;%0A            case 'game':%0A                if (data.data.type == 'list') %7B%0A                    TheHelpingHand.Game.list(data.data.games);%0A                %7D%0A                break;%0A            default:%0A                console.warn('Topic not implemented: ' + data.topic);%0A        %7D%0A        return false;%0A%0A
     %7D%0A%0A%7D;

Refactor parsing message from server.