def received_message(self, data):
        """Incomming messages"""
        data = ejson.loads(str(data))
        if not data.get('msg'):
            return

        elif data['msg'] == 'failed':
            self._ddp_version_index += 1
            self._retry_new_version = data.get('version', True)
            self.emit('failed', data)

        elif data['msg'] == 'connected':
            self._session = data.get('session')
            if self._is_reconnecting:
                self.ddpsocket._debug_log("* RECONNECTED")
                self.emit('reconnected')
                self._is_reconnecting = False
            else:
                self.ddpsocket._debug_log("* CONNECTED")
                self.emit('connected')
                self._retry_new_version = False

        # method result
        elif data['msg'] == 'result':
            # call the optional callback
            callback = self._callbacks.get(data['id'])
            if callback:
                callback(data.get('error'), data.get('result'))
                self._callbacks.pop(data['id'])

        # missing subscription
        elif data['msg'] == 'nosub':
            callback = self._callbacks.get(data['id'])
            if callback:
                callback(data.get('error'), data['id'])
                self._callbacks.pop(data['id'])

        # document added to collection
        elif data['msg'] == 'added':
            self.emit('added', data['collection'],
                      data['id'], data.get('fields', {}))

        # document changed in collection
        elif data['msg'] == 'changed':
            self.emit('changed', data['collection'], data['id'],
                       data.get('fields', {}), data.get('cleared', {}))

        # document removed from collection
        elif data['msg'] == 'removed':
            self.emit('removed', data['collection'], data['id'])

        # subcription ready
        elif data['msg'] == 'ready':
            for sub_id in data.get('subs', []):
                callback = self._callbacks.get(sub_id)
                if callback:
                    callback(data.get('error'), sub_id)
                    self._callbacks.pop(sub_id)

        elif data['msg'] == 'ping':
            msg = {'msg': 'pong'}
            id = data.get('id')
            if id is not None:
                msg['id'] = id
            self.ddpsocket.send(msg)

        else:
            pass