Send live notification without being repeated

0

I have a code, which I want to make a live push notification system, here's my code:

  <script>
        Notification.requestPermission();
        function requisitar(){
        var xmlhttp;
        if (window.XMLHttpRequest)
        {
             xmlhttp=new XMLHttpRequest();
        }
        else 
        {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.onreadystatechange = function()
        {
            var text=xmlhttp.responseText;
            if (xmlhttp.readyState==4 && xmlhttp.status==20)
            {
                var notification = new Notification("Site DaviDEV", {
                    icon: 'http://i.imgur.com/cWk851f.png',
                    body: text
                });
                notification.onclick = function() {
                    window.open("<?php echo $url; ?>");
                }
            }
        }
        xmlhttp.open("GET","/notificacao/notificacao.txt",true);
        xmlhttp.send();



    }

    window.setInterval(requisitar, 1000);
    </script>

More he can read the file and send the notification, but there is a problem: He sends several notifications, like a spam, I want something that is sent to each person, what can I do?     

asked by anonymous 05.03.2016 / 15:01

1 answer

0

You will need to use some logic to identify the user and if you have already sent the message to him on the server. The simplest way would be to store a list of ips and check if you are

And instead of using client-side pooling a better implementation would be to use websockets.

You can deploy the websocket yourself by using socket.io or by using elasticpush.com paid service to communicate with customers without using pooling.

    
06.03.2016 / 03:37