2017 © Pedro Peláez
 

symfony-bundle ratchet-bundle

The Web Socket Bundle for Symfony

image

ad3n/ratchet-bundle

The Web Socket Bundle for Symfony

  • Tuesday, October 3, 2017
  • by ad3n
  • Repository
  • 1 Watchers
  • 6 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Ihsan Ratchet Bundle

Install

composer req ad3n/ratchet-bundle, (*1)

Activating Bundle (Optional)

Add new Ihsan\RatchetBundle\IhsanRatchetBundle() in your AppKernel.php, (*2)

Create Your Message Processor

<?php

namespace YourBundle\Message\Processor;

use Ihsan\RatchetBundle\Message\Message;
use Ihsan\RatchetBundle\Processor\MessageProcessorInterface;
use Ratchet\ConnectionInterface;

/**
 * @author Muhamad Surya Iksanudin <surya.kejawen@gmail.com>
 */
class MyOwnMessageProcessor implements MessageProcessorInterface
{
    /**
     * @param ConnectionInterface $connection
     * @param Message $message
     *
     * @return Message
     */
    public function process(ConnectionInterface $connection, Message $message): Message
    {
        //$message is message send by the client
        //Your Own Logic

        return $message;//return original message or

        //return new Message(json_encode(['message' => 'Hello', 'more_data_to_expose' => $data]));
    }
}

Create Service

You must add tag ihsan_ratchet.message_processor to register your own message processor, (*3)

    YourBundle\Message\Processor\MyOwnMessageProcessor:
        tags:
            - { name: 'ihsan_ratchet.message_processor' }

Add Configuration Key

WEB_SOCKET_PORT=7777

or, (*4)

ihsan_ratchet:
    web_socket_port: 7777

Start Server

Run php bin/console ihsan:server:start, (*5)

Full Documention

Socketo.me, (*6)

The Versions