koolkishan / chat-app-react-nodejs

Chat Application Using React, Node.js and Socket.io with MongoDB

Home Page:https://www.youtube.com/watch?v=otaQKODEUFs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

receive notifications on new message

andremarretto opened this issue · comments

Hi,

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

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

we can use web push API
check this link