Event Source On Labs
Upcoming SlideShare
Loading in...5
×
 

Event Source On Labs

on

  • 2,545 views

Write future-proof Web Applications using server-sent events. The EventSource enabler provides a lightweight javascript library that allows you to use the current W3C Event Source draft API with ...

Write future-proof Web Applications using server-sent events. The EventSource enabler provides a lightweight javascript library that allows you to use the current W3C Event Source draft API with almost any web browser.

Statistics

Views

Total Views
2,545
Views on SlideShare
2,470
Embed Views
75

Actions

Likes
2
Downloads
3
Comments
0

2 Embeds 75

https://labs.ericsson.com 49
http://www.slideshare.net 26

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Event Source On Labs Event Source On Labs Presentation Transcript

  • EventSource emulation A labs.ericsson.com enabler https://labs.ericsson.com/apis/eventsource/
  • EventSource emulation EventSource is an API for receiving push messages “server- sent events” that is currently being standardized and implemented natively in browsers. The EventSource emulation enabler allows you to use the EventSource API already now in browsers that do not yet support server-sent events. Additionally, the enabler proxy allows you to set up your own server that provides a regular event-stream that will work with a native implementation of EventSource. 2
  • Why EventSource emulation? The EventSource emulation enabler provides a simple API for receiving pushed messages to web applications that you can use already today. Once more browsers implements the EventSource functionality natively, your web application will then start using the native implementation automatically. 3
  • EventSource client example To use the enabler, simply include the enabler JavaScript as such: <script src="http://eventsource.labs.ericsson.net /ESProxy/library/?key=YOUR_API_KEY"></script> Use the EventSource constructor to start receiving events from your server: var es = new EventSource(“http://example.org/event-stream”); Add an event listener to the EventSource object to handle incoming events: es.addEventListener(“server-time”, function (evt) { alert(“time on server is:” + evt.data); }, false); The EventSource specification is available here: http://dev.w3.org/html5/eventsource/ 4
  • EventSource server example A simple PHP script can be used to serve the client with an appropriate event-stream: <?php header("Content-Type:text/event-stream"); while(true) { echo "event: server-timen"; $time = time(); echo "data: $timen"; echo "n"; flush(); sleep(3); } ?> 5
  • 6