Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Allow to listen for MessageReceived event #134

Closed

Conversation

rihardsgrislis
Copy link

Hey,

Love using Reverb so far! 🚀

I would like to use the websocket server to receive non-Laravel messages from other clients as well and handle the messages in my app. I have some IoT devices that allow for outbound websocket.
The MessageReceived event is already implemented and I can just listen for it in the app. However it doesn't get executed because if the message doesn't contain the "event" key the server fails handling the message (Undefined array key "event") and sends 'event' => 'pusher:error' event to the client with message "Invalid message format".

We just need to check for the "event" key before using the Pusher or ClientEvent handler.

Update Server.php

[1.x] Allow non-Pusher and ClientEvent messages
@driesvints driesvints requested a review from joedixon April 8, 2024 08:02
@joedixon
Copy link
Collaborator

joedixon commented Apr 8, 2024

Thanks for the pull request, but right now the plan is to support solely the Pusher protocol.

There is scope within Reverb to provide support for additional protocols, so I could see a future where we ship a plain WebSocket server, but right now, the focus is on Pusher only.

@joedixon joedixon closed this Apr 8, 2024
@rihardsgrislis
Copy link
Author

rihardsgrislis commented Apr 8, 2024

Hope you reconsider. Seems like a wasted opportunity to add great general purpose tool in the Laravel toolkit. It doesn't seem to add any maintenance overhead and worked perfectly with this single change. A good trade-off to allow to receive messages and process them in the same Laravel app from various devices and clients.

@rihardsgrislis rihardsgrislis deleted the rihardsgrislis-patch-1 branch April 8, 2024 17:02
@rihardsgrislis
Copy link
Author

rihardsgrislis commented Apr 9, 2024

I would also like to point out that this change just allows the data, that is already received and parsed by the websocket server and available, to be used (listened to) by everybody.

@rihardsgrislis rihardsgrislis changed the title [1.x] Allow non-Pusher and ClientEvent messages [1.x] Allow to listen for MessageReceived event Apr 11, 2024
@rihardsgrislis
Copy link
Author

rihardsgrislis commented Apr 11, 2024

Laravel Socialite for example allows to implement your own providers along the Laravel provided ones. It should be the case for Reverb too.

@rihardsgrislis
Copy link
Author

"I have never written a single private class or method in an OS repo in my entire career

Like free speech, open source code is only truly open if someone you don't like can use and extend your code in ways that you disagree with, and you can't do anything about it" - Steve Bauman

Let developer listen to the message received event for all types of messages. There can be a new MessageHandled event for those that are handled by Reverb.

@driesvints
Copy link
Member

@rihardsgrislis feel free to fork this project and modify this entirely in the way you want 👍

@rihardsgrislis
Copy link
Author

@driesvints I rest my case now. This websocket server is too awesome. Together with FrankenPHP running one is such a delightful developer experience and I never want to go through something else. So, yeah, I'm forking it already.

websocket:
    image: ghcr.io/rihardsgrislis/my-app/app:main
    container_name: reverb_websocket
    working_dir: /app
    command: [ "php", "artisan", "reverb:start" ] # , "--debug"
    restart: unless-stopped
    ports:
      - "8080:8080"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants