laravel-swoole icon indicating copy to clipboard operation
laravel-swoole copied to clipboard

Broadcasting/Channels?

Open alecpl opened this issue 6 years ago • 6 comments

I'm new to Laravel so bear with me. After reading this project's wiki and https://laravel.com/docs/5.8/broadcasting I was hoping I can easily replace Pusher with Swoole. After trying I have a feeling it's not that simple or even not supported at all.

I configured Laravel to run via swoole, including websocket. I have Echo client configured to use socket.io. However, I miss how to use Laravel's channels. More precisely:

  1. How to configure broadcasting driver? Can swoole use it at all?
  2. How to define routes (channels.php vs. websocket.php)?

Unfortunately I couldn't find anything in the internet about this subject. Any help would be appreciated.

alecpl avatar Oct 16 '19 07:10 alecpl

Similar problem... I'm able to connect to the socket but emitting when an event occurs from Laravel doesn't work. The client never receives anything. Searched online, found nothing.

paschaldev avatar Oct 20 '19 16:10 paschaldev

You can build your websocket server without broadcasting feature in Laravel at all. Please refer to https://github.com/swooletw/laravel-swoole/wiki/7.-Websocket

albertcht avatar Oct 21 '19 16:10 albertcht

@albertcht Thanks, but as I wrote I've read the docs. The point is, it would be nice laravel-swoole contained some code to make it a ready-to-use Pusher replacement. Laravel Broadcasting documentation says Pusher can be replaced by any socket.io implementation. While swoole is socket.io server it would be nice to have a implementation that does not require building something from scratch.

I think that is what is missing and what a lot of people would appreciate. I'm surprised it wasn't yet requested (at least I don't see a ticket). Imo, it is natural to use Laravel functionality that is in core already and is well documented. As I said, I'm new to Laravel, so I can't really help in writing the code.

alecpl avatar Oct 21 '19 17:10 alecpl

I guess it should be "just" a rewrite of this https://github.com/tlaverdure/laravel-echo-server

gio00 avatar Nov 02 '19 10:11 gio00

Hi, sorry for the late reply,

Laravel's broadcasting relies on a third party service to broadcast the message. For example, Laravel needs Redis as a broker to pub/sub message between Socket.io server.

However, in laravel-swoole, the client can interact with Swoole's server directly. So it's different with how it works in tradition. That's why I said you actually don't need Laravel's broadcasting feature.

albertcht avatar Dec 01 '19 05:12 albertcht

Fair enough and I understand that. However, don't you see that using Laravel's existing and well documented APIs would be better than building something from scratch? Especially for swoole new-comers.

I don't expect you to implement that, but at least acknowledge that it's a valid feature request. And maybe give some hints on how to implement that. I'm new to swoole as well as laravel, so I'll probably not do this, but maybe someone else would.

alecpl avatar Dec 01 '19 08:12 alecpl