Skip to content

Symfony Bundle to Provide Ratchet Web Socket Server

License

Notifications You must be signed in to change notification settings

ad3n/RatchetBundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ihsan Ratchet Bundle

Install

composer req ad3n/ratchet-bundle

Activating Bundle (Optional)

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

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 <[email protected]>
 */
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

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

Add Configuration Key

WEB_SOCKET_PORT=7777

or

ihsan_ratchet:
    web_socket_port: 7777

Start Server

Run php bin/console ihsan:server:start

Full Documention

Socketo.me

About

Symfony Bundle to Provide Ratchet Web Socket Server

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages