var myFeeds = {
  mine: {
    url: "server/events.php",
    eventSource: null
  },
  david: {
    url: "http://156.35.95.69/server-sent-events/server/server.php",
    eventSource: null
  }
}


function handleEventSubscription(e) {
  if (e.checked)
    newSubscription(e.name)
  else
    closeSubscription(e.name)
}


function newSubscription(name) {
  myFeeds[name].eventSource = new EventSource(myFeeds[name].url)
  var source = myFeeds[name].eventSource

  source.addEventListener('message', function(e) {
    if (e.origin != 'http://localhost' && e.origin != 'http://156.35.95.69') {
    // if (e.origin != 'http://156.35.95.75' && e.origin != 'http://156.35.95.69') {
      alert('Danger! Origin ' + e.origin + ' unknown!')
      return
    }
    var data = JSON.parse(e.data)
    console.info("New alert from '" + name + "': " + e.data)
    addFeedItem(data)
    raiseNotification(data.message)
  }, false)
  console.info("New alert subscription with '" + name + "' source.")
}


function closeSubscription(name) {
  if (myFeeds[name].eventSource) {
    myFeeds[name].eventSource.close()
    console.info("Alert source '" + name + "' was closed.")
  }
  else {
    console.info("Couldn't close alert source '" + name + "' :(")
  }
}


function addFeedItem(data) {
  $("#list").prepend("<li>" + JSON.stringify(data) + "</li>")
}

function raiseNotification(msg) {
  if (window.Notification && Notification.permission === "granted") {
    new Notification(msg)
  }
}


$(function() {

  // Ask for notification permission
  if (window.Notification && Notification.permission !== "granted") {
    Notification.requestPermission(function (status) {
      if (Notification.permission !== status) {
        Notification.permission = status;
      }
    });
  }

})

@@ -546,57 +546,17 @@
 ' &&
- e.origin != 'http://156.35.95.69') %7B%0A    // if (
+%0A        
 e.or
@@ -587,16 +587,24 @@
 5.75' &&
+%0A       
  e.origi
@@ -1398,24 +1398,32 @@
 nted%22) %7B%0A   
+ var n =
  new Notific
@@ -1433,16 +1433,56 @@
 on(msg)%0A
+    setTimeout(n.close.bind(n), 10000);%0A
   %7D%0A%7D%0A%0A%0A

Change origin check and set timeout in notifications