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

Check for a global EventSource before deciding what to use. #389

Merged
merged 2 commits into from
Jul 26, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Only define properties if the event source instance exists.
  • Loading branch information
fnando committed Jul 26, 2019
commit 7f7e4169ca13ac2066e67f923f546682ec28969e
40 changes: 21 additions & 19 deletions src/call_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,27 @@ export class CallBuilder<

createTimeout();

es.onmessage = (message) => {
const result = message.data
? this._parseRecord(JSON.parse(message.data))
: message;
if (result.paging_token) {
this.url.setQuery("cursor", result.paging_token);
}
clearTimeout(timeout);
createTimeout();
if (typeof options.onmessage !== "undefined") {
options.onmessage(result);
}
};

es.onerror = (error) => {
if (options.onerror && error instanceof MessageEvent) {
options.onerror(error);
}
};
if (es) {
es.onmessage = (message) => {
const result = message.data
? this._parseRecord(JSON.parse(message.data))
: message;
if (result.paging_token) {
this.url.setQuery("cursor", result.paging_token);
}
clearTimeout(timeout);
createTimeout();
if (typeof options.onmessage !== "undefined") {
options.onmessage(result);
}
};

es.onerror = (error) => {
if (options.onerror && error instanceof MessageEvent) {
options.onerror(error);
}
};
}

return es;
};
Expand Down