Feature: Broadcast custom Events on IPC #367
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a
api/broadcasting
endpoint to handle all custom events dispatched on thenativephp
channel. (See #295 (comment))Whenever a Laravel event is dispatched on the
nativephp
channel, anative-event
event will be dispached on IPC so we can both listen to these events on the frontend usingipcRenderer.on('native-event')
and using Livewire listeners without using a separate websocket server.Please also check out NativePHP/electron-plugin#37 which implements the endpoint in the Electron backend
For example, whenever the following event is dispatched:
You may listen to it within Livewire using a listener:
Or directly int the frontend using the
ipcRenderer
For your consideration
I'm using the existing
native-event
so all events are automatically forwarded to Livewire. I'm unsure about the naming of this, strictly speaking this isn't a Native event, but rather a custom one.I've looked around for a existing path to testing this, but it seems similar features (like the debug endpoint) aren't covered. If you wan't me to cover this PR with tests I'll have to do some more digging. I'm not very experienced with jest & TS
While exploring the codebase I found an existing
notifyLaravel
function in the electron plugins'utils.ts
. It looks like this function doesn't emit events to any menubar window like was recently added to the debug enpoint. Should I create a separate issue for this?Closing
I've got all this working locally without issues. If you'd like me to change anything please let me know and I'll update this asap 👍🏻