protected function handleFrame(Net_Notifier_WebSocket_Frame $frame)
    {
        switch ($frame->getOpcode()) {
        case Net_Notifier_WebSocket_Frame::TYPE_BINARY:
            $this->binaryBuffer .= $frame->getUnmaskedData();
            if ($frame->isFinal()) {
                $this->binaryMessages[] = $this->binaryBuffer;
                $this->binaryBuffer = '';
            }
            break;

        case Net_Notifier_WebSocket_Frame::TYPE_TEXT:
            $this->textBuffer .= $frame->getUnmaskedData();
            if ($frame->isFinal()) {
                if (!$this->isValidUTF8($this->textBuffer)) {
                    throw new Net_Notifier_WebSocket_UTF8EncodingException(
                        'Received a text message that is invalid UTF-8.',
                        0,
                        $this->textBuffer
                    );
                }
                $this->textMessages[] = $this->textBuffer;
                $this->textBuffer = '';
            }
            break;

        case Net_Notifier_WebSocket_Frame::TYPE_CLOSE:
            if ($this->state === self::STATE_CLOSING) {
                $this->close();
            } else {
                $this->startClose();
            }
            break;

        case Net_Notifier_WebSocket_Frame::TYPE_PING:
            $this->pong($frame->getUnmaskedData());
            break;
        }
    }