ad3n / ratchet-bundle
The Web Socket Bundle for Symfony
Installs: 74
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 2
Forks: 0
Open Issues: 2
Type:symfony-bundle
Requires
- php: >=7.0
- cboden/ratchet: ^0.4
- symfony/config: ~3.0|~4.0|~5.0
- symfony/console: ~3.0|~4.0|~5.0
- symfony/dependency-injection: ~3.0|~4.0|~5.0
- symfony/framework-bundle: ~3.0|~4.0|~5.0
- symfony/http-kernel: ~3.0|~4.0|~5.0
This package is auto-updated.
Last update: 2024-11-30 00:00:37 UTC
README
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 <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
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