-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
Websockets package doesn't support Laravel 11 #295
Comments
I've been doing some digging and it seems Laravel events are not handled using IPC in the same way native-events are. In my case I'm dispatching a event from the scheduler using the log broadcasting connection. This event is logged in the browser (from From Would you consider a PR adding this? |
@gwleuverink all PRs are welcome 😊 The section you link to is specific to All other events generated by Electron that we explicitly handle should be transformed into a (These are also sent to the Laravel back-end, which allows you to listen to those events wherever makes the most sense for your application) Since Laravel Reverb is out and Laravel Websockets has been archived, we may look to support Reverb. But you should be able to achieve what you need without a websocket server in most cases. If you're struggling with your specific implementation, try reaching out on Discord. |
Awesome! thanks for the detailed explanation. I've been able to achieve what I set out to do. It was actually pretty straightforward. For other folks trying to do the same: In order to listen to events dispatched with the log driver and pass it to Livewire you can do the following: Add window.ipcRenderer = require('electron').ipcRenderer // somehow has issues using import Then in your component you can do something like this <script>
document.addEventListener('livewire:navigated', () => {
ipcRenderer.on('log', (event, { level, message, context }) => {
// Listen to Laravel event (could check against regex too)
if (message.startsWith('Broadcasting [App\\Events\\MessageReceived] on channels [nativephp]')) {
// Either dispatch event to be handled by Livewire (following native-events convention)
window.Livewire.dispatch('native:App\\Events\\MessageReceived')
// Or invoke the Livewire method directly
@wire.someMethod()
}
})
})
</script> I was thinking a case can be made to handle regular Laravel events just like native-events, so this extra wiring can be skipped. But this is so little code that it is pretty manageable as is. Thanks for the assist and info @simonhamp |
Hi @simonhamp, I've got a follow up question regarding workaround I posted before. It follows the same thread as the question above, but please let me know if I should ask this somewhere else. 🙏🏻 So, as demonstrated above, I'm listening to a This workaround works great in development, but after building the app, no After some digging I've found that both the LogWatcher and the electron server log route are not registered when the app env isn't development. This is probably for good reason, but I can't help but feel I'm missing something. What's the recommended way to listen to Laravel events without using websockets? Like you said, it seems most of these type of challenges can be tackled without a websocket server. Hope you can provide some clarity! I'd be happy to contribute this back to the docs once I've got it all figured out |
I agree that we could achieve quite a lot of this without websockets.
The log watcher is explicitly only for debugging and you shouldn't really abuse it in this way. So it would be a case of building a similar solution to the As in your code, it would also need a listener on the frontend using Feels like a nice easy PR... |
Thanks Simon, I was breaking my head on this one. Thought I was missing something. It sure sounds like a great first contribution. I'll try my hand at it this week if no one beats me to it 👍 |
@simonhamp I've pushed 2 PR's. Please let me know if I need to make any changes! |
What were you trying to do?
Hi @simonhamp, thanks for this awesome project 🚀
There is one thing I came across while implementing event broadcasting with Laravel 11.
It seems that Laravel Websockets package NativePHP integrates with has been archived and doesn't work with Laravel 11.
I need to dispatch events from a scheduled command. As I understand it right now, this doesn't work with electron's IPC. It seems only native-php events are emitted this way (or am I perhaps missing something?)
It seems like in order to support event broadcasting the same way in Laravel 11 support for Reverb needs to be added.
What happened?
The Laravel websockets package can't be installed with Laravel 11.
How to reproduce the bug
composer require beyondcode/laravel-websockets
Package Versions
0.6.3
PHP Version
8.2.16
Laravel Version
11.6.0
Node Version
21.7.3
Which operating systems have you seen this occur on?
macOS
OS version
macos 14.4.1
Notes
No response
The text was updated successfully, but these errors were encountered: