-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add support for steaming in Vega OS #974
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,12 @@ | |
| * 2. added onopen, onclose, onerror, onretrying functions. | ||
| * 3. modified dispatch to work with functions added in 2. | ||
| * 4. replaced all for of loops with foreach | ||
| * | ||
| * Additional changes: | ||
| * 1. separated event handling to use onprogress for data changes | ||
| * and onreadystatechange for status changes. This is to address | ||
| * an issue with Vega OS where they do not fire a readyStatechange | ||
| * event when the response is received. | ||
| */ | ||
| import type { EventSourceEvent, EventSourceListener, EventSourceOptions, EventType } from './types'; | ||
|
|
||
|
|
@@ -132,8 +138,34 @@ export default class EventSource<E extends string = never> { | |
|
|
||
| this._xhr.timeout = this._timeout; | ||
|
|
||
| this._xhr.onprogress = () => { | ||
| if (this._status === this.CLOSED || this._xhr.readyState !== XMLHttpRequest.LOADING) { | ||
| return; | ||
| } | ||
|
|
||
| this._logger?.debug( | ||
| `[EventSource][onprogress] ReadyState: ${ | ||
| XMLReadyStateMap[this._xhr.readyState] || 'Unknown' | ||
| }(${this._xhr.readyState}), status: ${this._xhr.status}`, | ||
| ); | ||
|
|
||
| if (this._xhr.status >= 200 && this._xhr.status < 400) { | ||
| this._handleEvent(this._xhr.responseText || ''); | ||
| } else { | ||
| this._status = this.ERROR; | ||
|
|
||
| this.dispatch('error', { | ||
| type: 'error', | ||
| message: this._xhr.responseText, | ||
| xhrStatus: this._xhr.status, | ||
| xhrState: this._xhr.readyState, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| this._xhr.onreadystatechange = () => { | ||
| if (this._status === this.CLOSED) { | ||
| // Do not handle this state if the status is loading as we will delegate this to the onprogress listener. | ||
| if (this._status === this.CLOSED || this._xhr.readyState === XMLHttpRequest.LOADING) { | ||
| return; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything in the code that follows that should be cleaned up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per https://xhr.spec.whatwg.org/ it looks like |
||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.