laravel
laravel copied to clipboard
Broadcasting Event with Electron IPC System not working
What happened?
Two things don't actually work or exist from the NativePHP documentation.
- There's no
ipcRenderer
exported from@electron/remote
package. There is only aipcMain
Event Emitter.
-> This could be replaced in the documentation by
import * as remote from 'electron';
remote.ipcMain.on( 'native-php', ( _, data ) => ... );
- It seems Vite externalizes all Node modules from browser compatibility. But actually, electron uses it in the node_moidules/electron/index.js` file.
Module "path" has been externalized for browser compatibility. Cannot access "path.join" in client code.
See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
Uncaught TypeError: path.join is not a function
at node_modules/electron/index.js (index.js:4:23)
at __require (chunk-UXIASGQL.js?v=7bde630a:8:50)
at electron.js?v=7bde630a:5:16
How to reproduce the bug
- Install dependency :
npm install @electron/remote
- Add in NativeAppServiceProvider :
Menu::new()->appMenu()->subMenu( 'Events', Menu::new()->label( 'Send Event' ) )->register();
- Add in Vue Component :
import * as remote from '@electron/remote';
remote.ipcMain.on( 'native-php', () => console.log( 'event listened' ) );
- Build
npm run dev
php artisan native:serve
Package Version
0.4.0
PHP Version
8.1.21
Laravel Version
10.18.0
Node Version
18.10.0
Which operating systems does with happen with?
macOS
Notes
I tried to correct the error with vite-plugin-node-polyfills
. No more warning but fs
was null
.
Can't reproduce since I can't serve my app in 0.4 version but this how I log every events. Hope it'll help somebody :)
window.addEventListener('livewire:load', () => {
// Sometimes not handled by Native with Livewire 🤷
window.Livewire.addHeaders({
'X-NativePHP-Secret': '{{ config('nativephp-internal.secret') }}',
})
window.Echo.channel('nativephp')
.subscribed(() => console.info('Subscribed to nativephp channel'))
.error((error) => console.error(error))
// Not in Echo public API but works 😉
.listenToAll((event, payload) => {
console.log(event, payload)
// See https://github.com/NativePHP/electron-plugin/blob/main/src/preload/index.ts
//window.Livewire.emit(event, payload)
})
/** @type {Electron} */
const remote = window.remote;
// Helps me to keeping track of the window load
remote.shell.beep()
remote.ipcMain.on('native-event', (_, data) => {
console.log(data);
});
})
Can't reproduce since I can't serve my app in 0.4 version but this how I log every events. Hope it'll help somebody :)
window.addEventListener('livewire:load', () => { // Sometimes not handled by Native with Livewire 🤷 window.Livewire.addHeaders({ 'X-NativePHP-Secret': '{{ config('nativephp-internal.secret') }}', }) window.Echo.channel('nativephp') .subscribed(() => console.info('Subscribed to nativephp channel')) .error((error) => console.error(error)) // Not in Echo public API but works 😉 .listenToAll((event, payload) => { console.log(event, payload) // See https://github.com/NativePHP/electron-plugin/blob/main/src/preload/index.ts //window.Livewire.emit(event, payload) }) /** @type {Electron} */ const remote = window.remote; // Helps me to keeping track of the window load remote.shell.beep() remote.ipcMain.on('native-event', (_, data) => { console.log(data); }); })
Hello, Can you help me?
I want to listen from event from livewire, But it's not working. Can you help me on this?
@mho22 I know this was from a while ago, but can you give some context around what you were trying to achieve?
@simonhamp As I remember, I wanted to catch events from clicking on a subMenu. I remember trying out what is written in this part of the documentation but it didn't work for me.
I think it was related to the DOOM Native PHP side project : I think I was trying to load different games from the menubar.
I can see that the documentation hasn't changed. But I don't know if the issue is outdated or not. I can try to reproduce the issue again in the next days if you want.
Fixed by https://github.com/NativePHP/laravel/pull/367 @simonhamp?
I think it will be. Thanks for digging through related issues @gwleuverink 😇
@mho22 @MarceauKa @Nuhel the PR that Willem linked will be released next week. Please try that out at your leisure. In the meantime, I'm going to close this issue