laravel-websockets/src/WebSocketServer/Messages/RespondableMessageFactory.php

23 lines
786 B
PHP
Raw Normal View History

2018-11-21 22:47:46 +00:00
<?php
2018-11-27 14:55:30 +00:00
namespace BeyondCode\LaravelWebSockets\WebSocketServer\Messages;
2018-11-21 22:47:46 +00:00
2018-11-27 14:55:30 +00:00
use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager;
use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\PusherMessage;
2018-11-21 22:47:46 +00:00
use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface;
class RespondableMessageFactory
{
public static function createForMessage(
MessageInterface $message,
ConnectionInterface $connection,
ChannelManager $channelManager): RespondableMessage
{
$payload = json_decode($message->getPayload());
return starts_with($payload->event, 'pusher:')
? new PusherMessage($payload, $connection, $channelManager)
: new Message($payload, $connection, $channelManager);
}
}