x-dom-event-stream in Opera 10 Only Working on First Event
Posted
by Brad
on Stack Overflow
See other posts from Stack Overflow
or by Brad
Published on 2010-05-26T21:21:08Z
Indexed on
2010/05/28
12:21 UTC
Read the original article
Hit count: 452
I have a python script (in the CherryPy framework) that sends Event: and data: text as this Opera blog post describes to a client browser. The javascript that recieves the x-dom-event-stream content is almost identical to what they show in the blog post. However, the browser displays only the first event sent. Anyone know what I'm missing?
I tried a few older versions of Opera and found that it works in Opera 9.52 but not in any newer versions. What did they change?
Here is the python code:
class dumpData(object):
def index(self):
cherrypy.response.headers['Content-Type'] = "application/x-dom-event-stream"
def yieldData():
i = 0
while 1:
yield "Event: count\n"
yield "data: "
yield i
yield "\n\n"
i = i + 1
time.sleep(3);
return yieldData()
index._cp_config = {'response.stream': True}
index.exposed = True
And here is the javascript/html. Making a request to /data/ runs the python function above.
<head>
<script>
onload = function() {
document.getElementById("count").addEventListener("cout", cout, false);
}
function count(e) {
document.getElementById("stream").firstChild.nodeValue = e.data;
}
</script>
<event-source id="count" src="/data/">
</head>
<body>
<div id="stream"></div>
</body>
Opening the direct /data/ url in Firefox saves the stream to a file. So I know the output is in the correct format and that the stream works at all.
© Stack Overflow or respective owner