web-push-libs / web-push-php

Web Push library for PHP
MIT License
1.69k stars 295 forks source link

Make sound in the push notification. Does anyone know how to issue push notification? #318

Closed marcosmarf27 closed 6 months ago

marcosmarf27 commented 3 years ago

Make sound in the push notification.

Does anyone know how to issue push notification?

8Ozymandias commented 3 years ago

I've been researching this as well and even emailed some of the contributors but nothing has come up as yet.

preciousfocus commented 6 months ago

Service Workers, for now, do not support playing of sounds. Below is the workaround I use.

In my Service Worker, when I receive the push (when the push event is fired), I post a message (instructing to play notification sound) to any open window/client being controlled by the service worker. Then, on the app side, I have a listener that should receive the posted message from the service worker. Once the message is received, I check the instruction from the service worker (I have several other kinds of instructions for other things/actions though). If the instruction is to play notification sound, I then play it from the open window (app).

Limitation: it works only when a window of your site/app is already open before the push arrives.