onMessage not firing always
onOpen() event fired always, but onMessage() event not firing always. 
But the chat system will work fine sometimes, but sometimes it can't work

I can't able to find out what is problem behind this.

Server Side Code:
public function onOpen(ConnectionInterface $conn)
    {
        $this->repository->addClient($conn);
    }

```
/**
 * Called when a message is sent through the socket
 *
 * @param ConnectionInterface $conn
 * @param string              $msg
 * @return void
 */
public function onMessage(ConnectionInterface $conn, $msg)
{
    echo $msg;
    // Parse the json
    $data = $this->parseMessage($msg);
    $currClient = $this->repository->getClientByConnection($conn);

    // Distinguish between the actions
    if ($data->action === "setname")
    {
        $currClient->setName($data->username);
    }
    else if ($data->action === "message")
    {
        // We don't want to handle messages if the name isn't set
        if ($currClient->getName() === "")
            return;

        foreach ($this->repository->getClients() as $client)
        {
            // Send the message to the clients if, except for the client who sent the message originally
            if ($currClient->getName() !== $client->getName())
                $client->sendMsg($currClient->getName(), $data->msg);
        }
    }
}
```

Client Side Codes : 

setupConnectionEvents: function() {
            var self = this;

```
        self.socket.onopen = function(evt) { self.connectionOpen(evt); };
        self.socket.onmessage = function(evt) { self.connectionMessage(evt); };
        self.socket.onclose = function(evt) { self.connectionClose(evt); };
    },

    connectionOpen: function(evt) {
        this.open = true;
        this.addSystemMessage("Connected");
        this.updateUsername();
    },

    connectionMessage: function(evt) {
        alert("gi");
        if (!this.open)
            return;

        var data = JSON.parse(evt.data);
        alert(data);
        if (data.action == 'setname') {
            if (data.success)
                this.addSystemMessage("Set username to " + this.username);
            else
                this.addSystemMessage("Username " + this.username + " has been taken.");
        } else if (data.action == 'message') {
            this.addChatMessage(data.username, data.msg);
        }
    },
```

Please give me a solution
