wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

Event Source not working when Event-Type sent to publisher #155

Closed robodude666 closed 10 years ago

robodude666 commented 10 years ago

I have setup nginx and an example html file as described in the event_source example:

https://github.com/wandenberg/nginx-push-stream-module/blob/master/docs/examples/event_source.textile

If, for example, I try to use these headers:

Event-Id: eventid
Event-Type: eventtype

the EventSource onmessage does not get triggered. I can manually navigate to /ev/channel?... and see the content being displayed, but the console nor the innerhtml are updating with the new events. If I remove the Event-Type from the header, it works fine, but with it the javascript doesn't get triggered.

Example received when manually browsing to the /ev/channel?.. page:

id: eventid
event: eventtype
data: {"id":6,"channel":"ch1","text":"DATA!!!!", "tag":"5", "time":"Thu, 21 Aug 2014 04:19:04 GMT", "eventid":"eventid"}

Response headers for this request:

HTTP/1.1 200 OK
Server: nginx/1.2.0
Date: Thu, 21 Aug 2014 04:21:45 GMT
Content-Type: text/event-stream; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: If-Modified-Since,If-None-Match,Etag,Event-Id,Event-Type,Last-Event-Id
Expires: Thu, 01 Jan 1970 00:00:01 GMT
Cache-Control: no-cache, no-store, must-revalidate

The data looks correct, and seems to comply with the SSE standards.

I'm using the Advanced Rest Client from the Google webstore, but I've also tried curl and python's requests, and all have the same results. I've tried the provided PushStream.js and the native EventSource(); both show the same thing.

The docs suggest that Event-Type should be usable. Is that the case, or is this a known issue?

wandenberg commented 10 years ago

Hi @robodude666

the PushStream.js does not use the event type, but the server support it,respecting the RFC. you can use it with the default EventSource class like described here

Authors can separate events by using different event types. Here is a stream that has two event types, "add" and "remove":

event: add
data: 73857293

event: remove
data: 2153

event: add
data: 113411
The script to handle such a stream would look like this (where addHandler and removeHandler are functions that take one argument, the event):

var source = new EventSource('updates.cgi');
source.addEventListener('add', addHandler, false);
source.addEventListener('remove', removeHandler, false);
The default event type is "message".
robodude666 commented 10 years ago

Ah, okay. I don't recall reading that in the docs.