protected function onData($json)
    {
        // Decode the JSON
        $interaction = json_decode(trim($json), true);

        // If the interaction is valid, pass it to the event handler
        if ($interaction) {
            if (isset($interaction['status'])) {
                switch ($interaction['status']) {
                    case 'error':
                    case 'failure':
                        $this->onError($interaction['message']);
                        // Stop the consumer when an error is received
                        $this->stop();
                        break;
                    case 'warning':
                        $this->onWarning($interaction['message']);
                        break;
                    default:
                        $type = $interaction['status'];
                        unset($interaction['status']);
                        $this->onStatus($type, $interaction);
                        break;
                }
            } else {
                // Extract the hash and the data if present
                $hash = false;
                if (isset($interaction['hash'])) {
                    $hash = $interaction['hash'];
                    $interaction = $interaction['data'];
                }
                // Ignore ticks and handle delete requests
                if (! empty($interaction['deleted'])) {
                    $this->onDeleted($interaction, $hash);
                } elseif (! empty($interaction['interaction'])) {
                    $this->onInteraction($interaction, $hash);
                }
            }
        }
    }