Support the ongoing development of Laravel.io →
posted 4 years ago
Last updated 1 year ago.

jamieconnor liked this thread

1

Ok, so it is possible to put Echo in a service worker, just import it as you normally would

import Echo from 'laravel-echo';

importScripts(

'pusher.worker.min.js',

)

const echo = new Echo({

broadcaster: 'pusher',

key: process.env.MIX_PUSHER_APP_KEY,

cluster: process.env.MIX_PUSHER_APP_CLUSTER,

encrypted: true

});

you'll need to tell webpack to compile it as well. Note: it is best to have the service worker compiled to the root directory.

I'm using mix so my webpack.mix.js has this in it

mix.js('resources/js/app.js', 'public/js') .js('resources/js/service-worker.js', 'public') .sass('resources/sass/app.scss', 'public/css');

Last updated 4 years ago.
0

I don't think you will be able to do what your wanting, because you will find the service worker will become 'activated and stopped' after a few minutes of the site being closed, so it will not be listening for push events.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.