Skip to content

Commit

Permalink
0.1.8: Adding support for streaming COMET-style hanging GETs to Simpl…
Browse files Browse the repository at this point in the history
…eWebRequest
  • Loading branch information
David de Regt committed Aug 2, 2018
1 parent f7e57ef commit 43f7349
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simplerestclients",
"version": "0.1.7",
"version": "0.1.8",
"description": "A library of components for accessing RESTful services with javascript/typescript.",
"author": "David de Regt <David.de.Regt@microsoft.com>",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/SimpleWebRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export interface WebRequestOptions {
// Overrides all other headers.
augmentHeaders?: Headers;

streamingDownloadProgress?: (responseText: string) => void;

onProgress?: (progressEvent: XMLHttpRequestProgressEvent) => void;

customErrorHandler?: (webRequest: SimpleWebRequestBase, errorResponse: WebErrorResponse) => ErrorHandlingType;
Expand Down Expand Up @@ -274,6 +276,10 @@ export abstract class SimpleWebRequestBase<TOptions extends WebRequestOptions =
onLoadErrorSupportStatus = FeatureSupportStatus.Detecting;
}
this._xhr.onreadystatechange = (e) => {
if (this._xhr!!!.readyState === 3 && this._options.streamingDownloadProgress) {
this._options.streamingDownloadProgress(this._xhr!!!.responseText);
}

if (this._xhr!!!.readyState !== 4) {
// Wait for it to finish
return;
Expand Down

0 comments on commit 43f7349

Please sign in to comment.