Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture empty events #157

Open
jdetomasi opened this issue Apr 28, 2021 · 3 comments
Open

Capture empty events #157

jdetomasi opened this issue Apr 28, 2021 · 3 comments

Comments

@jdetomasi
Copy link

Hi, I'm working on a node app that connects a Bloomberg API. Bloomberg uses SEE for notifications and periodically sends out empty notifications that do not have any content as heartbeat.

I need to capture these empty notifications to know if the connection is alive but seems that these notifications are being ignored by the client. I wonder if there is any way to handle this type of event.

@piranna
Copy link
Member

piranna commented Apr 28, 2021

In theory, if connection goes down it would get closed or reconnect, I'm not sure why they are sending that, there's no need of it at all... If so, maybe is due to prevent connection being closed by some intermediary server, like AWS dows after two minutes (it gives a lot of problems with WebSockets...). Do you really need to listen to this notifications? If so, you could listen to the message event, but if not, it's something I would not worry about.

@franciscopaglia
Copy link

I think what he is pointing out is that empty strings do not emit the 'message' event. I read the specs. regarding this case and I couldn't figure whether if it should or it shouldn't (the return in step 2 throws me off).

If the line is empty (a blank line) dispatch the event, as defined below:

...

1. Set the last event ID string of the event source to the value of the last event ID buffer. The buffer does not get reset, so the last event ID string of the event source remains set to this value until the next time it is set by the server.

2. If the data buffer is an empty string, set the data buffer and the event type buffer to the empty string and return.

3. If the data buffer's last character is a U+000A LINE FEED (LF) character, then remove the last character from the data buffer.

4. Let event be the result of creating an event using MessageEvent, in the relevant Realm of the EventSource object.

5. Initialize event's type attribute to message, its data attribute to data, its origin attribute to the serialization of the origin of the event stream's final URL (i.e., the URL after redirects), and its lastEventId attribute to the last event ID string of the event source.

6. If the event type buffer has a value other than the empty string, change the type of the newly created event to equal the value of the event type buffer.

7. Set the data buffer and the event type buffer to the empty string.

8. Queue a task which, if the readyState attribute is set to a value other than CLOSED, dispatches the newly created event at the EventSource object.

function parseEventStreamLine (buf, pos, fieldLength, lineLength) {
if (lineLength === 0) {
if (data.length > 0) {
var type = eventName || 'message'
_emit(type, new MessageEvent(type, {
data: data.slice(0, -1), // remove trailing newline
lastEventId: lastEventId,
origin: original(url)
}))
data = ''
}
eventName = void 0
} else if (fieldLength > 0) {

@piranna
Copy link
Member

piranna commented Apr 29, 2021

  1. If the data buffer is an empty string, set the data buffer and the event type buffer to the empty string and return.

Seems like it just only reset the data buffer and the event type buffer, but doesn't emit an event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants