GeniusesOfSymfony / WebSocketBundle

:part_alternation_mark: Websocket server for Symfony applications (powered by Ratchet), includes a Autobahn.JS based JavaScript client
MIT License
609 stars 140 forks source link

Push Notifications from Server #463

Closed LucasWerner437 closed 2 years ago

LucasWerner437 commented 2 years ago

Hi,

I'm trying to send a Notification from a Controller or Service in my Symfony 5 app to clients. I'm trying hard to use your docs but all I could figure out is that the pusher was deprecated and we should use Ratchet/Pawl and Symfony/Messenger instead, but it's pretty hard to figure out how to do that.

I finally stumbled across another issue asking pretty much the same thing, and there was an example there so I tried implementing it. See here : https://github.com/GeniusesOfSymfony/WebSocketBundle/issues/405

I cannot try anything about this right now because I get DI errors triggered :

Cannot autowire service "App\Websocket\Client\WebsocketClient": argument "$router" of method "__construct()" references class "Gos\Bundle\WebSocketBundle\Router\WampRouter" but no such service exists. You should maybe alias thi s class to the existing "gos_web_socket.router.wamp" service.

Then I define the service in the yaml file, and another error occurs :

Cannot autowire service "Gos\Bundle\WebSocketBundle\Router\WampRouter": argument "$router" of method "__construct()" references interface "Gos\Bundle\PubSubRouterBundle\Router\RouterInterface" but no such service exists. You sh ould maybe alias this interface to the existing "Gos\Bundle\PubSubRouterBundle\Router\Router" service.

Then again I define that service aswell in the yaml file, and again, another error occurs :

Cannot autowire service "Gos\Bundle\PubSubRouterBundle\Router\Router": argument "$name" of method "__construct()" is type-hinted "string", you should configure its value explicitly.

I tried defining RouterInterface service as a Router object that implements this iterface, because with the interface itself it couldn't know what object to create. But I cannot define every single construtor argument for this service as I don't know the internals of the bundle.

Anyone can help ? I've been struggling with that for 2 days now I'd like to have this working. Thanks in advance !

LucasWerner437 commented 2 years ago

Nevermind, I finally managed with the example shown in the other issue. I was actually not wiring my services properly, trying to create aliases as the Symfony error message suggested me to.

devalpha-ppap commented 1 month ago

Hello, you have any code example to send from a controller ? That would be really appreciated !