Push Notification with Socket.io

0

I made a small application with node + socket.io to send notification. by adding the code below on the client page, the notification is displayed in the "messagebox" div.

<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script><scriptsrc="http://localhost:4555/socket.io/socket.io.js"></script>
<script>
  var socket = io('http://localhost:4555', {transports: ['websocket', 'polling', 'flashsocket']});
  socket.on('notificacao', function (data) {
    document.getElementById('messagebox').innerHTML = data;

  });
</script>

<div id="messagebox">

My question now is how to make those facebook-style notifications appear. or to be clearer just like pushcrew notifications.

I did not find anything that could help me: / does anyone have any material or do you know how I can do it?

    
asked by anonymous 30.05.2018 / 14:26

1 answer

1

I think one solution to your problem would be

var socket = io('http://localhost:4555', {transports: ['websocket', 'polling', 'flashsocket']});
socket.on('notificacao', function (data) {
    console.log(data) //VERIFIQUE OS DADOS QUE ESTÃO CHEGANDO 
    notify(data.nome,data.mensagem)
});

function notify(nome,mensagem) {
    Notification.requestPermission(function() {
        var notification = new Notification(nome, {
            icon: 'ICONE DA SUA APLICAÇÃO',
            body: mensagem
        });
        notification.onclick = function() {
            //SUA LÓGICA AQUI
        }
    });
}

Code based on: Notifications desktop in Chrome with Javascript

    
30.05.2018 / 15:11