Use a "x-dom-event-stream" stream in javascript ?

Posted by rnaud on Stack Overflow See other posts from Stack Overflow or by rnaud
Published on 2010-04-01T16:00:14Z Indexed on 2010/04/01 16:03 UTC
Read the original article Hit count: 492

Filed under:
|
|

Hello,

HTML5 draft contains an API called EventSource to stream data (notifications) trough javascript using only one server call.

Looking it up, I found an exemple on Opera Labs of the javascript part :

document.getElementsByTagName("event-source")[0]
        .addEventListener("server-time", eventHandler, false);

function eventHandler(event)
{
    // Alert time sent by the server
    alert(event.data); 
}

and the server side part :

<?php
header("Content-Type: application/x-dom-event-stream");
while(true) {
    echo "Event: server-time\n";
    $time = time();
    echo "data: $time\n";
    echo "\n";
    flush();
    sleep(3);
}
?>

But as of today, it seems only Opera has implemented the API, neither Chrome nor Safari have a working version (Am I wrong here ?)

So my question is, is there any other way in javascript, maybe more complex, to use this one stream to get data ?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about streaming