1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Alert/Notifications "Immediately" (push)

Discussion in 'jQuery' started by XGhozt, Mar 15, 2015.

  1. #1
    I've been toying with the HTML5 Notification API and it's really neat. But I'm struggling to find a way to use it effectively. I'm trying to figure out how to send the notification to user right when the event happens.

    I could have a script check every 2-4 seconds for notifications and if it finds one then push it to the user. I feel there must be another way to do it. I was using the Pushover.net web based interface and I noticed they only download the new messages when a notification is received.

    How do I do that without looping an ajax get request every second? Is this the only way? How can I only download new messages when new messages exist using AJAX?
     
    XGhozt, Mar 15, 2015 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Not sure how widespread you want support for (browser-wise), but you might want to just wait for the next version of Chrome which supports push notifications... although there are some pretty lame limitations right now. Like being unable to pass any data with your notification.

    A lot of good info on it here: http://updates.html5rocks.com/2015/03/push-notificatons-on-the-open-web

    On a side note, I already have it working here for this site. :)

    upload_2015-3-19_23-33-17.png
     
    digitalpoint, Mar 19, 2015 IP
    PoPSiCLe likes this.
  3. XGhozt

    XGhozt Member

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    I actually managed to get this working! I tried to post a follow up but it wouldn't post (not sure why?)

    I used SSE (https://developer.mozilla.org/en-US/docs/Web/API/EventSource) and setup a file to stream and check the database every second for new notifications. When a notification was found, the javascript would fire the HTML5 notification on the browser. It's the next best thing to using websockets and it works really well. Notifications come in "live" to all my users from the browser.

    Edit: to be clear I used this, not google's push service: http://www.w3.org/TR/notifications/
     
    XGhozt, Mar 20, 2015 IP