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

22 lines
720 B
PHP
Raw Normal View History

2018-11-21 22:47:46 +00:00
<?php
2018-11-27 15:11:12 +00:00
namespace BeyondCode\LaravelWebSockets\WebSockets\Messages;
2018-11-21 22:47:46 +00:00
2018-11-27 15:35:28 +00:00
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
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,
2018-12-01 14:09:05 +00:00
ChannelManager $channelManager): PusherMessage
2018-11-21 22:47:46 +00:00
{
$payload = json_decode($message->getPayload());
return starts_with($payload->event, 'pusher:')
2018-12-01 13:56:16 +00:00
? new PusherChannelProtocolMessage($payload, $connection, $channelManager)
: new PusherClientMessage($payload, $connection, $channelManager);
2018-11-21 22:47:46 +00:00
}
}