chat-app-react-nodejs icon indicating copy to clipboard operation
chat-app-react-nodejs copied to clipboard

receive notifications on new message

Open andremarretto opened this issue 2 years ago • 2 comments

Hi,

How can I get a notification when I receive a new message, there´s a way to activate this feat.?

andremarretto avatar May 12 '23 13:05 andremarretto

I´ve tried to use: useEffect(() => { if (socket.current) { socket.current.on('msg-receive', (msg) => { setArrivalMessage({ fromSelf: false, message: msg }); // play notification sound const audio = new Audio('/notification.mp3'); audio.play(); }); } }, []); but It only works if the tab is active

andremarretto avatar May 15 '23 23:05 andremarretto

we can use web push API check this link

krabhi1 avatar Jul 04 '23 04:07 krabhi1