process websocket stream request

@param MessageEvent $event
190519
public function processStream($event)
    {
        /**
         * @var Request $event->message
         */
        
        if($event->message->isCtlFrame()) {
            if($event->message->isCloseFrame()) {
                return $this->processClose($event);
            }else if($event->message->isPingFrame()){
                return $this->processPing($event);
            }else if($event->message->isPongFrame()){
                return $this->processPong($event);
            }
            
        }else{
            return $this->processData($event);
        }
    }
483347
public function onCurlRead(Event $event)
    {
        // Stream the request body to the log if the body is not repeatable
        if ($wire = $event['request']->getParams()->get('request_wire')) {
            $wire->write($event['read']);
        }
    }
895925
public function onRequestSent(Event $event)
    {
        $request = $event['request'];
        $response = $event['response'];
        $handle = $event['handle'];

        if ($wire = $request->getParams()->get('request_wire')) {
            $request = clone $request;
            $request->setBody($wire);
        }

        if ($wire = $request->getParams()->get('response_wire')) {
            $response = clone $response;
            $response->setBody($wire);
        }

        // Send the log message to the adapter, adding a category and host
        $priority = $response && $response->isError() ? LOG_ERR : LOG_DEBUG;
        $message = $this->formatter->format($request, $response, $handle);
        $this->logAdapter->log($message, $priority, array(
            'request'  => $request,
            'response' => $response,
            'handle'   => $handle
        ));
    }
159339
public function onMessage(WebSocketTransportInterface $user, WebSocketMessageInterface $msg) {
        $this->logger->notice("Broadcasting " . strlen($msg->getData()) . " bytes");

        foreach($this->getConnections() as $client){
            $client->sendString("User {$user->getId()} said: ".$msg->getData());
        }
    }
615636
public function onRequestError(Event $event)
	{
		$e = $this->factory->fromResponse($event['request'], $event['response']);
		$event->stopPropagation();
		throw $e;
	}
482165
public function handleGhost(ServerEvent $event, Queue $queue)
    {
        if ($this->ghostNick === null) {
            return;
        }

        // Attempt to kill the ghost connection
        $queue->ircPrivmsg($this->botNick, 'GHOST ' . $this->ghostNick . ' ' . $this->password);
    }
1248639
@Override
    public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
        if (!(evt instanceof MessageEvent)) {
            ctx.sendDownstream(evt);
            return;
        }

        final MessageEvent e = (MessageEvent) evt;
        final Object originalMessage = e.getMessage();
        final Object encodedMessage = encode(ctx, e.getChannel(), originalMessage);
        if (originalMessage == encodedMessage)
            ctx.sendDownstream(evt);
        else if (encodedMessage != null)
            ctx.sendDownstream(new DownstreamMessageEvent(ctx.getChannel(), e.getFuture(), encodedMessage, e.getRemoteAddress())); // Channels.write(ctx, e.getFuture(), encodedMessage, e.getRemoteAddress());
    }
633397
public function processHookAction(Request $request)
    {
        /** @var LoggerInterface $logger */
        $logger = $this->get('logger');

        $body = $request->getContent();
        $logger->info('Received sendgrid webhook '.$body);

        $events = json_decode($body, true);

        if ($events === false || $events === null) {
            $logger->error('Unable to decode sendgrid webhook. Body: '.$body);
            throw new BadRequestHttpException('Unabled to parse request body');
        }

        /** @var EventDispatcherInterface $dispatcher */
        $dispatcher = $this->get('event_dispatcher');

        foreach ($events as $eventData) {
            $type = 'sendgrid.'.$eventData['event'];
            $dispatcher->dispatch($type, new WebHookEvent($type, $eventData));
        }

        return new Response();
    }
968818
public function handleParseDate($event)
    {
        if ($event->getResult() === null) {
            /** @var Date $dateAdapter */
            $dateAdapter = $this->framework->getAdapter(Date::class);
            $event->setResult($dateAdapter->parse($event->getFormat(), $event->getTimestamp()));
        }
    }
77326
private function receiveMessage(Message $message): void
    {
        if ($message instanceof Command) {
            $this->locator->getCommandBus()->receiveCommand($message);
            return;
        }

        if ($message instanceof Event) {
            $this->locator->getEventBus()->receiveEvent($message);
            return;
        }

        throw new BadRequestHttpException(
            'The receive endpoint cannot process requests.',
            null,
            Code::INVALID_ARGUMENT
        );
    }
732440
protected function processClientSocket($socket): void
    {
        $connection = $this->getConnectionForClientSocket($socket);

        if (!$connection) {
            $this->logger->warning('No connection for client socket');
            return;
        }

        try {
            $this->server->notify(Server::EVENT_CLIENT_DATA, [$socket, $connection]);

            $connection->process();
        } catch (CloseException $e) {
            $this->logger->notice('Client connection closed: {exception}', [
                'exception' => $e,
            ]);
            $connection->close(Protocol::CLOSE_UNEXPECTED, $e->getMessage());
        } catch (WrenchException $e) {
            $this->logger->warning('Error on client socket: {exception}', [
                'exception' => $e,
            ]);
            $connection->close(Protocol::CLOSE_UNEXPECTED);
        } catch (InvalidArgumentException $e) {
            $this->logger->warning('Wrong input arguments: {exception}', [
                'exception' => $e,
            ]);
            $connection->close(Protocol::CLOSE_UNEXPECTED);
        }
    }
109659
public function processEvent($event)
    {
        // Pass thread control to Inbox if Page Administrators move from Done to Inbox
        if (isset($event['request_thread_control'])) {
            return $this->passToInbox();
        }

        // Handle Account Linking and Unlinking
        if (isset($event['account_linking'])) {
            return AccountLinking::process($event);
        }

        // Handle message and postback
        if (!isset($event['message']) && !isset($event['postback'])) {
            return null;
        }

        if (isset($event['message'])) {
            $this->message = $event['message'];

            // Enabling NLP
            $this->initNlp($event['message']);
        }

        if (isset($event['postback'])) {
            $this->postback = $event['postback'];
        }

        // If current message is sent from Page
        if (isset($event['message']['is_echo'])) {
            $this->conversation->set('lead_id', $event['recipient']['id']);
            $this->conversation->set('page_id', $event['sender']['id']);
        }

        $this->conversation->set('received_input', $this->getReceivedInput());

        $this->setConfigData();

        // Save lead data if not exists.
        if (!isset($event['message']['is_echo'])) {
            $lead = $this->storage->pull();
        } else {
            $lead = Lead::withTrashed()->where('user_id', $this->getLeadId())->first();
        }

        $this->conversation->set('lead', $lead);
        
        // Message was sent by page, we don't need to response.
        if (isset($event['message']) && isset($event['message']['is_echo']) && $event['message']['is_echo'] == true) {
            return null;
        }

        DynamicParser::support([
            'type' => 'callback',
            'callback' => function ($content) use ($lead) {
                return $this->resolver->bind([
                    'bot' => $this,
                    'lead' => $lead,
                    'input' => $this->getReceivedInput(),
                ])->resolve($content);
            },
        ]);

        $type_pattern = $this->request->getTypeAndPattern($event);

        // We'll check to response intended action first
        if ($this->responseIntendedAction()) {
            return;
        }

        $nodes = $this->findNodes($type_pattern['type'], $type_pattern['pattern']);

        $this->response($nodes);
    }
69410
public function onRequestSent(Event $event)
    {
        $request = $event['request'];
        $response = $event['response'];

        if ($request->getParams()->get('cache.hit') === null &&
            $this->canCache->canCacheRequest($request) &&
            $this->canCache->canCacheResponse($response)
        ) {
            $this->storage->cache($request, $response);
        }

        $this->addResponseHeaders($request, $response);
    }
483884
public function onWSClientCommand(WSEventDispatcher\WSClientEvent $event)
    {
        //$command = $event->getCommand();
        //$arguments = $event->getArguments();
        $this->data['commands'][] = array(
            'command'   => $event->getCommand(),
            'arguments' => $event->getArguments(),
            'url' => $event->getUrl(),
            'cache' => $event->getUseCache(),
            'content' => $event->getContent(),
            'key' => $event->getKey(),
            'statusCode' => $event->getStatusCode(),
            'executiontime' => $event->getTiming()
        );
    }
801299
public function handle_message(\stdClass $messagedata) {
        $this->record = $this->get_data();
        return $this->handler->process_message($this->record, $messagedata);
    }
626251
public function logEvent(EventMessage $message): void
    {
        $name = $message->payloadType()->toString();

        $this->logger->info(
            sprintf('Event dispatched {%s}', $name),
            ['message' => $message->toString()]
        );
    }
1027330
public function process(LogEvent $logEvent, array $server = [])
    {
        if ($this->isOnDemandBailOut($logEvent)) {
            return;
        }

        if (empty($server)) {
            $server = filter_input_array(INPUT_SERVER, $this->filterSetup);
        }

        foreach ($this->fields as $key => $field) {
            if (empty($server[$field])) {
                continue;
            }

            $logEvent[static::PROCESSOR_DATA_KEY][static::PROCESSOR_KEY][$key] = $server[$field];
        }
    }