@sanity/client 5.4.0 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs +19 -12
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +19 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +20 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/data/listen.ts +21 -6
- package/umd/sanityClient.js +1170 -1138
- package/umd/sanityClient.min.js +3 -3
package/umd/sanityClient.js
CHANGED
|
@@ -4,6 +4,21 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SanityClient = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
+
function _mergeNamespaces(n, m) {
|
|
8
|
+
m.forEach(function (e) {
|
|
9
|
+
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default' && !(k in n)) {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
const isReactNative = typeof navigator === "undefined" ? false : navigator.product === "ReactNative";
|
|
8
23
|
const defaultOptions$1 = {
|
|
9
24
|
timeout: isReactNative ? 6e4 : 12e4
|
|
@@ -447,7 +462,7 @@
|
|
|
447
462
|
const environment = "browser";
|
|
448
463
|
|
|
449
464
|
var browserExports = {};
|
|
450
|
-
var browser$
|
|
465
|
+
var browser$2 = {
|
|
451
466
|
get exports(){ return browserExports; },
|
|
452
467
|
set exports(v){ browserExports = v; },
|
|
453
468
|
};
|
|
@@ -1167,7 +1182,7 @@
|
|
|
1167
1182
|
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
1168
1183
|
}
|
|
1169
1184
|
};
|
|
1170
|
-
} (browser$
|
|
1185
|
+
} (browser$2, browserExports));
|
|
1171
1186
|
|
|
1172
1187
|
/*!
|
|
1173
1188
|
* is-plain-object <https://github.com/jonschlinkert/is-plain-object>
|
|
@@ -2039,1137 +2054,83 @@
|
|
|
2039
2054
|
});
|
|
2040
2055
|
}
|
|
2041
2056
|
|
|
2042
|
-
var
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
status: response.status,
|
|
2120
|
-
statusText: response.statusText,
|
|
2121
|
-
headers: response.headers,
|
|
2122
|
-
body: {
|
|
2123
|
-
getReader: function () {
|
|
2124
|
-
return reader;
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
};
|
|
2128
|
-
});
|
|
2129
|
-
};
|
|
2130
|
-
AbortController = function () {
|
|
2131
|
-
this.signal = {
|
|
2132
|
-
_reader: null,
|
|
2133
|
-
_aborted: false
|
|
2134
|
-
};
|
|
2135
|
-
this.abort = function () {
|
|
2136
|
-
if (this.signal._reader != null) {
|
|
2137
|
-
this.signal._reader.cancel();
|
|
2138
|
-
}
|
|
2139
|
-
this.signal._aborted = true;
|
|
2140
|
-
};
|
|
2141
|
-
};
|
|
2142
|
-
}
|
|
2143
|
-
|
|
2144
|
-
function TextDecoderPolyfill() {
|
|
2145
|
-
this.bitsNeeded = 0;
|
|
2146
|
-
this.codePoint = 0;
|
|
2147
|
-
}
|
|
2148
|
-
|
|
2149
|
-
TextDecoderPolyfill.prototype.decode = function (octets) {
|
|
2150
|
-
function valid(codePoint, shift, octetsCount) {
|
|
2151
|
-
if (octetsCount === 1) {
|
|
2152
|
-
return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
|
|
2153
|
-
}
|
|
2154
|
-
if (octetsCount === 2) {
|
|
2155
|
-
return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
|
|
2156
|
-
}
|
|
2157
|
-
if (octetsCount === 3) {
|
|
2158
|
-
return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
|
|
2159
|
-
}
|
|
2160
|
-
throw new Error();
|
|
2161
|
-
}
|
|
2162
|
-
function octetsCount(bitsNeeded, codePoint) {
|
|
2163
|
-
if (bitsNeeded === 6 * 1) {
|
|
2164
|
-
return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
|
|
2165
|
-
}
|
|
2166
|
-
if (bitsNeeded === 6 * 2) {
|
|
2167
|
-
return codePoint > 15 ? 3 : 2;
|
|
2168
|
-
}
|
|
2169
|
-
if (bitsNeeded === 6 * 3) {
|
|
2170
|
-
return 3;
|
|
2171
|
-
}
|
|
2172
|
-
throw new Error();
|
|
2173
|
-
}
|
|
2174
|
-
var REPLACER = 0xFFFD;
|
|
2175
|
-
var string = "";
|
|
2176
|
-
var bitsNeeded = this.bitsNeeded;
|
|
2177
|
-
var codePoint = this.codePoint;
|
|
2178
|
-
for (var i = 0; i < octets.length; i += 1) {
|
|
2179
|
-
var octet = octets[i];
|
|
2180
|
-
if (bitsNeeded !== 0) {
|
|
2181
|
-
if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
|
|
2182
|
-
bitsNeeded = 0;
|
|
2183
|
-
codePoint = REPLACER;
|
|
2184
|
-
string += String.fromCharCode(codePoint);
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
if (bitsNeeded === 0) {
|
|
2188
|
-
if (octet >= 0 && octet <= 127) {
|
|
2189
|
-
bitsNeeded = 0;
|
|
2190
|
-
codePoint = octet;
|
|
2191
|
-
} else if (octet >= 192 && octet <= 223) {
|
|
2192
|
-
bitsNeeded = 6 * 1;
|
|
2193
|
-
codePoint = octet & 31;
|
|
2194
|
-
} else if (octet >= 224 && octet <= 239) {
|
|
2195
|
-
bitsNeeded = 6 * 2;
|
|
2196
|
-
codePoint = octet & 15;
|
|
2197
|
-
} else if (octet >= 240 && octet <= 247) {
|
|
2198
|
-
bitsNeeded = 6 * 3;
|
|
2199
|
-
codePoint = octet & 7;
|
|
2200
|
-
} else {
|
|
2201
|
-
bitsNeeded = 0;
|
|
2202
|
-
codePoint = REPLACER;
|
|
2203
|
-
}
|
|
2204
|
-
if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
|
|
2205
|
-
bitsNeeded = 0;
|
|
2206
|
-
codePoint = REPLACER;
|
|
2207
|
-
}
|
|
2208
|
-
} else {
|
|
2209
|
-
bitsNeeded -= 6;
|
|
2210
|
-
codePoint = codePoint << 6 | octet & 63;
|
|
2211
|
-
}
|
|
2212
|
-
if (bitsNeeded === 0) {
|
|
2213
|
-
if (codePoint <= 0xFFFF) {
|
|
2214
|
-
string += String.fromCharCode(codePoint);
|
|
2215
|
-
} else {
|
|
2216
|
-
string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
|
|
2217
|
-
string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
this.bitsNeeded = bitsNeeded;
|
|
2222
|
-
this.codePoint = codePoint;
|
|
2223
|
-
return string;
|
|
2224
|
-
};
|
|
2225
|
-
|
|
2226
|
-
// Firefox < 38 throws an error with stream option
|
|
2227
|
-
var supportsStreamOption = function () {
|
|
2228
|
-
try {
|
|
2229
|
-
return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
|
|
2230
|
-
} catch (error) {
|
|
2231
|
-
console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
|
|
2232
|
-
}
|
|
2233
|
-
return false;
|
|
2234
|
-
};
|
|
2235
|
-
|
|
2236
|
-
// IE, Edge
|
|
2237
|
-
if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
|
|
2238
|
-
TextDecoder = TextDecoderPolyfill;
|
|
2239
|
-
}
|
|
2240
|
-
|
|
2241
|
-
var k = function () {
|
|
2242
|
-
};
|
|
2243
|
-
|
|
2244
|
-
function XHRWrapper(xhr) {
|
|
2245
|
-
this.withCredentials = false;
|
|
2246
|
-
this.readyState = 0;
|
|
2247
|
-
this.status = 0;
|
|
2248
|
-
this.statusText = "";
|
|
2249
|
-
this.responseText = "";
|
|
2250
|
-
this.onprogress = k;
|
|
2251
|
-
this.onload = k;
|
|
2252
|
-
this.onerror = k;
|
|
2253
|
-
this.onreadystatechange = k;
|
|
2254
|
-
this._contentType = "";
|
|
2255
|
-
this._xhr = xhr;
|
|
2256
|
-
this._sendTimeout = 0;
|
|
2257
|
-
this._abort = k;
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
|
-
XHRWrapper.prototype.open = function (method, url) {
|
|
2261
|
-
this._abort(true);
|
|
2262
|
-
|
|
2263
|
-
var that = this;
|
|
2264
|
-
var xhr = this._xhr;
|
|
2265
|
-
var state = 1;
|
|
2266
|
-
var timeout = 0;
|
|
2267
|
-
|
|
2268
|
-
this._abort = function (silent) {
|
|
2269
|
-
if (that._sendTimeout !== 0) {
|
|
2270
|
-
clearTimeout(that._sendTimeout);
|
|
2271
|
-
that._sendTimeout = 0;
|
|
2272
|
-
}
|
|
2273
|
-
if (state === 1 || state === 2 || state === 3) {
|
|
2274
|
-
state = 4;
|
|
2275
|
-
xhr.onload = k;
|
|
2276
|
-
xhr.onerror = k;
|
|
2277
|
-
xhr.onabort = k;
|
|
2278
|
-
xhr.onprogress = k;
|
|
2279
|
-
xhr.onreadystatechange = k;
|
|
2280
|
-
// IE 8 - 9: XDomainRequest#abort() does not fire any event
|
|
2281
|
-
// Opera < 10: XMLHttpRequest#abort() does not fire any event
|
|
2282
|
-
xhr.abort();
|
|
2283
|
-
if (timeout !== 0) {
|
|
2284
|
-
clearTimeout(timeout);
|
|
2285
|
-
timeout = 0;
|
|
2286
|
-
}
|
|
2287
|
-
if (!silent) {
|
|
2288
|
-
that.readyState = 4;
|
|
2289
|
-
that.onabort(null);
|
|
2290
|
-
that.onreadystatechange();
|
|
2291
|
-
}
|
|
2292
|
-
}
|
|
2293
|
-
state = 0;
|
|
2294
|
-
};
|
|
2295
|
-
|
|
2296
|
-
var onStart = function () {
|
|
2297
|
-
if (state === 1) {
|
|
2298
|
-
//state = 2;
|
|
2299
|
-
var status = 0;
|
|
2300
|
-
var statusText = "";
|
|
2301
|
-
var contentType = undefined;
|
|
2302
|
-
if (!("contentType" in xhr)) {
|
|
2303
|
-
try {
|
|
2304
|
-
status = xhr.status;
|
|
2305
|
-
statusText = xhr.statusText;
|
|
2306
|
-
contentType = xhr.getResponseHeader("Content-Type");
|
|
2307
|
-
} catch (error) {
|
|
2308
|
-
// IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
|
|
2309
|
-
// Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
|
|
2310
|
-
// https://bugs.webkit.org/show_bug.cgi?id=29121
|
|
2311
|
-
status = 0;
|
|
2312
|
-
statusText = "";
|
|
2313
|
-
contentType = undefined;
|
|
2314
|
-
// Firefox < 14, Chrome ?, Safari ?
|
|
2315
|
-
// https://bugs.webkit.org/show_bug.cgi?id=29658
|
|
2316
|
-
// https://bugs.webkit.org/show_bug.cgi?id=77854
|
|
2317
|
-
}
|
|
2318
|
-
} else {
|
|
2319
|
-
status = 200;
|
|
2320
|
-
statusText = "OK";
|
|
2321
|
-
contentType = xhr.contentType;
|
|
2322
|
-
}
|
|
2323
|
-
if (status !== 0) {
|
|
2324
|
-
state = 2;
|
|
2325
|
-
that.readyState = 2;
|
|
2326
|
-
that.status = status;
|
|
2327
|
-
that.statusText = statusText;
|
|
2328
|
-
that._contentType = contentType;
|
|
2329
|
-
that.onreadystatechange();
|
|
2330
|
-
}
|
|
2331
|
-
}
|
|
2332
|
-
};
|
|
2333
|
-
var onProgress = function () {
|
|
2334
|
-
onStart();
|
|
2335
|
-
if (state === 2 || state === 3) {
|
|
2336
|
-
state = 3;
|
|
2337
|
-
var responseText = "";
|
|
2338
|
-
try {
|
|
2339
|
-
responseText = xhr.responseText;
|
|
2340
|
-
} catch (error) {
|
|
2341
|
-
// IE 8 - 9 with XMLHttpRequest
|
|
2342
|
-
}
|
|
2343
|
-
that.readyState = 3;
|
|
2344
|
-
that.responseText = responseText;
|
|
2345
|
-
that.onprogress();
|
|
2346
|
-
}
|
|
2347
|
-
};
|
|
2348
|
-
var onFinish = function (type, event) {
|
|
2349
|
-
if (event == null || event.preventDefault == null) {
|
|
2350
|
-
event = {
|
|
2351
|
-
preventDefault: k
|
|
2352
|
-
};
|
|
2353
|
-
}
|
|
2354
|
-
// Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
|
|
2355
|
-
// IE 8 fires "onload" without "onprogress"
|
|
2356
|
-
onProgress();
|
|
2357
|
-
if (state === 1 || state === 2 || state === 3) {
|
|
2358
|
-
state = 4;
|
|
2359
|
-
if (timeout !== 0) {
|
|
2360
|
-
clearTimeout(timeout);
|
|
2361
|
-
timeout = 0;
|
|
2362
|
-
}
|
|
2363
|
-
that.readyState = 4;
|
|
2364
|
-
if (type === "load") {
|
|
2365
|
-
that.onload(event);
|
|
2366
|
-
} else if (type === "error") {
|
|
2367
|
-
that.onerror(event);
|
|
2368
|
-
} else if (type === "abort") {
|
|
2369
|
-
that.onabort(event);
|
|
2370
|
-
} else {
|
|
2371
|
-
throw new TypeError();
|
|
2372
|
-
}
|
|
2373
|
-
that.onreadystatechange();
|
|
2374
|
-
}
|
|
2375
|
-
};
|
|
2376
|
-
var onReadyStateChange = function (event) {
|
|
2377
|
-
if (xhr != undefined) { // Opera 12
|
|
2378
|
-
if (xhr.readyState === 4) {
|
|
2379
|
-
if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
|
|
2380
|
-
onFinish(xhr.responseText === "" ? "error" : "load", event);
|
|
2381
|
-
}
|
|
2382
|
-
} else if (xhr.readyState === 3) {
|
|
2383
|
-
if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
|
|
2384
|
-
// and in Firefox 3.6
|
|
2385
|
-
onProgress();
|
|
2386
|
-
}
|
|
2387
|
-
} else if (xhr.readyState === 2) {
|
|
2388
|
-
onStart();
|
|
2389
|
-
}
|
|
2390
|
-
}
|
|
2391
|
-
};
|
|
2392
|
-
var onTimeout = function () {
|
|
2393
|
-
timeout = setTimeout(function () {
|
|
2394
|
-
onTimeout();
|
|
2395
|
-
}, 500);
|
|
2396
|
-
if (xhr.readyState === 3) {
|
|
2397
|
-
onProgress();
|
|
2398
|
-
}
|
|
2399
|
-
};
|
|
2400
|
-
|
|
2401
|
-
// XDomainRequest#abort removes onprogress, onerror, onload
|
|
2402
|
-
if ("onload" in xhr) {
|
|
2403
|
-
xhr.onload = function (event) {
|
|
2404
|
-
onFinish("load", event);
|
|
2405
|
-
};
|
|
2406
|
-
}
|
|
2407
|
-
if ("onerror" in xhr) {
|
|
2408
|
-
xhr.onerror = function (event) {
|
|
2409
|
-
onFinish("error", event);
|
|
2410
|
-
};
|
|
2411
|
-
}
|
|
2412
|
-
// improper fix to match Firefox behaviour, but it is better than just ignore abort
|
|
2413
|
-
// see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
|
|
2414
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=880200
|
|
2415
|
-
// https://code.google.com/p/chromium/issues/detail?id=153570
|
|
2416
|
-
// IE 8 fires "onload" without "onprogress
|
|
2417
|
-
if ("onabort" in xhr) {
|
|
2418
|
-
xhr.onabort = function (event) {
|
|
2419
|
-
onFinish("abort", event);
|
|
2420
|
-
};
|
|
2421
|
-
}
|
|
2422
|
-
|
|
2423
|
-
if ("onprogress" in xhr) {
|
|
2424
|
-
xhr.onprogress = onProgress;
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
// IE 8 - 9 (XMLHTTPRequest)
|
|
2428
|
-
// Opera < 12
|
|
2429
|
-
// Firefox < 3.5
|
|
2430
|
-
// Firefox 3.5 - 3.6 - ? < 9.0
|
|
2431
|
-
// onprogress is not fired sometimes or delayed
|
|
2432
|
-
// see also #64 (significant lag in IE 11)
|
|
2433
|
-
if ("onreadystatechange" in xhr) {
|
|
2434
|
-
xhr.onreadystatechange = function (event) {
|
|
2435
|
-
onReadyStateChange(event);
|
|
2436
|
-
};
|
|
2437
|
-
}
|
|
2438
|
-
|
|
2439
|
-
if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
|
|
2440
|
-
url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
|
|
2441
|
-
}
|
|
2442
|
-
xhr.open(method, url, true);
|
|
2443
|
-
|
|
2444
|
-
if ("readyState" in xhr) {
|
|
2445
|
-
// workaround for Opera 12 issue with "progress" events
|
|
2446
|
-
// #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
|
|
2447
|
-
timeout = setTimeout(function () {
|
|
2448
|
-
onTimeout();
|
|
2449
|
-
}, 0);
|
|
2450
|
-
}
|
|
2451
|
-
};
|
|
2452
|
-
XHRWrapper.prototype.abort = function () {
|
|
2453
|
-
this._abort(false);
|
|
2454
|
-
};
|
|
2455
|
-
XHRWrapper.prototype.getResponseHeader = function (name) {
|
|
2456
|
-
return this._contentType;
|
|
2457
|
-
};
|
|
2458
|
-
XHRWrapper.prototype.setRequestHeader = function (name, value) {
|
|
2459
|
-
var xhr = this._xhr;
|
|
2460
|
-
if ("setRequestHeader" in xhr) {
|
|
2461
|
-
xhr.setRequestHeader(name, value);
|
|
2462
|
-
}
|
|
2463
|
-
};
|
|
2464
|
-
XHRWrapper.prototype.getAllResponseHeaders = function () {
|
|
2465
|
-
// XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
|
|
2466
|
-
return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
|
|
2467
|
-
};
|
|
2468
|
-
XHRWrapper.prototype.send = function () {
|
|
2469
|
-
// loading indicator in Safari < ? (6), Chrome < 14, Firefox
|
|
2470
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=736723
|
|
2471
|
-
if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
|
|
2472
|
-
document != undefined &&
|
|
2473
|
-
document.readyState != undefined &&
|
|
2474
|
-
document.readyState !== "complete") {
|
|
2475
|
-
var that = this;
|
|
2476
|
-
that._sendTimeout = setTimeout(function () {
|
|
2477
|
-
that._sendTimeout = 0;
|
|
2478
|
-
that.send();
|
|
2479
|
-
}, 4);
|
|
2480
|
-
return;
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
var xhr = this._xhr;
|
|
2484
|
-
// withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
|
|
2485
|
-
if ("withCredentials" in xhr) {
|
|
2486
|
-
xhr.withCredentials = this.withCredentials;
|
|
2487
|
-
}
|
|
2488
|
-
try {
|
|
2489
|
-
// xhr.send(); throws "Not enough arguments" in Firefox 3.0
|
|
2490
|
-
xhr.send(undefined);
|
|
2491
|
-
} catch (error1) {
|
|
2492
|
-
// Safari 5.1.7, Opera 12
|
|
2493
|
-
throw error1;
|
|
2494
|
-
}
|
|
2495
|
-
};
|
|
2496
|
-
|
|
2497
|
-
function toLowerCase(name) {
|
|
2498
|
-
return name.replace(/[A-Z]/g, function (c) {
|
|
2499
|
-
return String.fromCharCode(c.charCodeAt(0) + 0x20);
|
|
2500
|
-
});
|
|
2501
|
-
}
|
|
2502
|
-
|
|
2503
|
-
function HeadersPolyfill(all) {
|
|
2504
|
-
// Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
|
|
2505
|
-
var map = Object.create(null);
|
|
2506
|
-
var array = all.split("\r\n");
|
|
2507
|
-
for (var i = 0; i < array.length; i += 1) {
|
|
2508
|
-
var line = array[i];
|
|
2509
|
-
var parts = line.split(": ");
|
|
2510
|
-
var name = parts.shift();
|
|
2511
|
-
var value = parts.join(": ");
|
|
2512
|
-
map[toLowerCase(name)] = value;
|
|
2513
|
-
}
|
|
2514
|
-
this._map = map;
|
|
2515
|
-
}
|
|
2516
|
-
HeadersPolyfill.prototype.get = function (name) {
|
|
2517
|
-
return this._map[toLowerCase(name)];
|
|
2518
|
-
};
|
|
2519
|
-
|
|
2520
|
-
if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
|
|
2521
|
-
XMLHttpRequest.HEADERS_RECEIVED = 2;
|
|
2522
|
-
}
|
|
2523
|
-
|
|
2524
|
-
function XHRTransport() {
|
|
2525
|
-
}
|
|
2526
|
-
|
|
2527
|
-
XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
2528
|
-
xhr.open("GET", url);
|
|
2529
|
-
var offset = 0;
|
|
2530
|
-
xhr.onprogress = function () {
|
|
2531
|
-
var responseText = xhr.responseText;
|
|
2532
|
-
var chunk = responseText.slice(offset);
|
|
2533
|
-
offset += chunk.length;
|
|
2534
|
-
onProgressCallback(chunk);
|
|
2535
|
-
};
|
|
2536
|
-
xhr.onerror = function (event) {
|
|
2537
|
-
event.preventDefault();
|
|
2538
|
-
onFinishCallback(new Error("NetworkError"));
|
|
2539
|
-
};
|
|
2540
|
-
xhr.onload = function () {
|
|
2541
|
-
onFinishCallback(null);
|
|
2542
|
-
};
|
|
2543
|
-
xhr.onabort = function () {
|
|
2544
|
-
onFinishCallback(null);
|
|
2545
|
-
};
|
|
2546
|
-
xhr.onreadystatechange = function () {
|
|
2547
|
-
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
|
2548
|
-
var status = xhr.status;
|
|
2549
|
-
var statusText = xhr.statusText;
|
|
2550
|
-
var contentType = xhr.getResponseHeader("Content-Type");
|
|
2551
|
-
var headers = xhr.getAllResponseHeaders();
|
|
2552
|
-
onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
|
|
2553
|
-
}
|
|
2554
|
-
};
|
|
2555
|
-
xhr.withCredentials = withCredentials;
|
|
2556
|
-
for (var name in headers) {
|
|
2557
|
-
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
2558
|
-
xhr.setRequestHeader(name, headers[name]);
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
xhr.send();
|
|
2562
|
-
return xhr;
|
|
2563
|
-
};
|
|
2564
|
-
|
|
2565
|
-
function HeadersWrapper(headers) {
|
|
2566
|
-
this._headers = headers;
|
|
2567
|
-
}
|
|
2568
|
-
HeadersWrapper.prototype.get = function (name) {
|
|
2569
|
-
return this._headers.get(name);
|
|
2570
|
-
};
|
|
2571
|
-
|
|
2572
|
-
function FetchTransport() {
|
|
2573
|
-
}
|
|
2574
|
-
|
|
2575
|
-
FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
2576
|
-
var reader = null;
|
|
2577
|
-
var controller = new AbortController();
|
|
2578
|
-
var signal = controller.signal;
|
|
2579
|
-
var textDecoder = new TextDecoder();
|
|
2580
|
-
fetch(url, {
|
|
2581
|
-
headers: headers,
|
|
2582
|
-
credentials: withCredentials ? "include" : "same-origin",
|
|
2583
|
-
signal: signal,
|
|
2584
|
-
cache: "no-store"
|
|
2585
|
-
}).then(function (response) {
|
|
2586
|
-
reader = response.body.getReader();
|
|
2587
|
-
onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
|
|
2588
|
-
// see https://github.com/promises-aplus/promises-spec/issues/179
|
|
2589
|
-
return new Promise(function (resolve, reject) {
|
|
2590
|
-
var readNextChunk = function () {
|
|
2591
|
-
reader.read().then(function (result) {
|
|
2592
|
-
if (result.done) {
|
|
2593
|
-
//Note: bytes in textDecoder are ignored
|
|
2594
|
-
resolve(undefined);
|
|
2595
|
-
} else {
|
|
2596
|
-
var chunk = textDecoder.decode(result.value, {stream: true});
|
|
2597
|
-
onProgressCallback(chunk);
|
|
2598
|
-
readNextChunk();
|
|
2599
|
-
}
|
|
2600
|
-
})["catch"](function (error) {
|
|
2601
|
-
reject(error);
|
|
2602
|
-
});
|
|
2603
|
-
};
|
|
2604
|
-
readNextChunk();
|
|
2605
|
-
});
|
|
2606
|
-
})["catch"](function (error) {
|
|
2607
|
-
if (error.name === "AbortError") {
|
|
2608
|
-
return undefined;
|
|
2609
|
-
} else {
|
|
2610
|
-
return error;
|
|
2611
|
-
}
|
|
2612
|
-
}).then(function (error) {
|
|
2613
|
-
onFinishCallback(error);
|
|
2614
|
-
});
|
|
2615
|
-
return {
|
|
2616
|
-
abort: function () {
|
|
2617
|
-
if (reader != null) {
|
|
2618
|
-
reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
|
|
2619
|
-
}
|
|
2620
|
-
controller.abort();
|
|
2621
|
-
}
|
|
2622
|
-
};
|
|
2623
|
-
};
|
|
2624
|
-
|
|
2625
|
-
function EventTarget() {
|
|
2626
|
-
this._listeners = Object.create(null);
|
|
2627
|
-
}
|
|
2628
|
-
|
|
2629
|
-
function throwError(e) {
|
|
2630
|
-
setTimeout(function () {
|
|
2631
|
-
throw e;
|
|
2632
|
-
}, 0);
|
|
2633
|
-
}
|
|
2634
|
-
|
|
2635
|
-
EventTarget.prototype.dispatchEvent = function (event) {
|
|
2636
|
-
event.target = this;
|
|
2637
|
-
var typeListeners = this._listeners[event.type];
|
|
2638
|
-
if (typeListeners != undefined) {
|
|
2639
|
-
var length = typeListeners.length;
|
|
2640
|
-
for (var i = 0; i < length; i += 1) {
|
|
2641
|
-
var listener = typeListeners[i];
|
|
2642
|
-
try {
|
|
2643
|
-
if (typeof listener.handleEvent === "function") {
|
|
2644
|
-
listener.handleEvent(event);
|
|
2645
|
-
} else {
|
|
2646
|
-
listener.call(this, event);
|
|
2647
|
-
}
|
|
2648
|
-
} catch (e) {
|
|
2649
|
-
throwError(e);
|
|
2650
|
-
}
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
};
|
|
2654
|
-
EventTarget.prototype.addEventListener = function (type, listener) {
|
|
2655
|
-
type = String(type);
|
|
2656
|
-
var listeners = this._listeners;
|
|
2657
|
-
var typeListeners = listeners[type];
|
|
2658
|
-
if (typeListeners == undefined) {
|
|
2659
|
-
typeListeners = [];
|
|
2660
|
-
listeners[type] = typeListeners;
|
|
2661
|
-
}
|
|
2662
|
-
var found = false;
|
|
2663
|
-
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
2664
|
-
if (typeListeners[i] === listener) {
|
|
2665
|
-
found = true;
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
if (!found) {
|
|
2669
|
-
typeListeners.push(listener);
|
|
2670
|
-
}
|
|
2671
|
-
};
|
|
2672
|
-
EventTarget.prototype.removeEventListener = function (type, listener) {
|
|
2673
|
-
type = String(type);
|
|
2674
|
-
var listeners = this._listeners;
|
|
2675
|
-
var typeListeners = listeners[type];
|
|
2676
|
-
if (typeListeners != undefined) {
|
|
2677
|
-
var filtered = [];
|
|
2678
|
-
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
2679
|
-
if (typeListeners[i] !== listener) {
|
|
2680
|
-
filtered.push(typeListeners[i]);
|
|
2681
|
-
}
|
|
2682
|
-
}
|
|
2683
|
-
if (filtered.length === 0) {
|
|
2684
|
-
delete listeners[type];
|
|
2685
|
-
} else {
|
|
2686
|
-
listeners[type] = filtered;
|
|
2687
|
-
}
|
|
2688
|
-
}
|
|
2689
|
-
};
|
|
2690
|
-
|
|
2691
|
-
function Event(type) {
|
|
2692
|
-
this.type = type;
|
|
2693
|
-
this.target = undefined;
|
|
2694
|
-
}
|
|
2695
|
-
|
|
2696
|
-
function MessageEvent(type, options) {
|
|
2697
|
-
Event.call(this, type);
|
|
2698
|
-
this.data = options.data;
|
|
2699
|
-
this.lastEventId = options.lastEventId;
|
|
2700
|
-
}
|
|
2701
|
-
|
|
2702
|
-
MessageEvent.prototype = Object.create(Event.prototype);
|
|
2703
|
-
|
|
2704
|
-
function ConnectionEvent(type, options) {
|
|
2705
|
-
Event.call(this, type);
|
|
2706
|
-
this.status = options.status;
|
|
2707
|
-
this.statusText = options.statusText;
|
|
2708
|
-
this.headers = options.headers;
|
|
2709
|
-
}
|
|
2710
|
-
|
|
2711
|
-
ConnectionEvent.prototype = Object.create(Event.prototype);
|
|
2712
|
-
|
|
2713
|
-
function ErrorEvent(type, options) {
|
|
2714
|
-
Event.call(this, type);
|
|
2715
|
-
this.error = options.error;
|
|
2716
|
-
}
|
|
2717
|
-
|
|
2718
|
-
ErrorEvent.prototype = Object.create(Event.prototype);
|
|
2719
|
-
|
|
2720
|
-
var WAITING = -1;
|
|
2721
|
-
var CONNECTING = 0;
|
|
2722
|
-
var OPEN = 1;
|
|
2723
|
-
var CLOSED = 2;
|
|
2724
|
-
|
|
2725
|
-
var AFTER_CR = -1;
|
|
2726
|
-
var FIELD_START = 0;
|
|
2727
|
-
var FIELD = 1;
|
|
2728
|
-
var VALUE_START = 2;
|
|
2729
|
-
var VALUE = 3;
|
|
2730
|
-
|
|
2731
|
-
var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
|
|
2732
|
-
|
|
2733
|
-
var MINIMUM_DURATION = 1000;
|
|
2734
|
-
var MAXIMUM_DURATION = 18000000;
|
|
2735
|
-
|
|
2736
|
-
var parseDuration = function (value, def) {
|
|
2737
|
-
var n = value == null ? def : parseInt(value, 10);
|
|
2738
|
-
if (n !== n) {
|
|
2739
|
-
n = def;
|
|
2740
|
-
}
|
|
2741
|
-
return clampDuration(n);
|
|
2742
|
-
};
|
|
2743
|
-
var clampDuration = function (n) {
|
|
2744
|
-
return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
|
|
2745
|
-
};
|
|
2746
|
-
|
|
2747
|
-
var fire = function (that, f, event) {
|
|
2748
|
-
try {
|
|
2749
|
-
if (typeof f === "function") {
|
|
2750
|
-
f.call(that, event);
|
|
2751
|
-
}
|
|
2752
|
-
} catch (e) {
|
|
2753
|
-
throwError(e);
|
|
2754
|
-
}
|
|
2755
|
-
};
|
|
2756
|
-
|
|
2757
|
-
function EventSourcePolyfill(url, options) {
|
|
2758
|
-
EventTarget.call(this);
|
|
2759
|
-
options = options || {};
|
|
2760
|
-
|
|
2761
|
-
this.onopen = undefined;
|
|
2762
|
-
this.onmessage = undefined;
|
|
2763
|
-
this.onerror = undefined;
|
|
2764
|
-
|
|
2765
|
-
this.url = undefined;
|
|
2766
|
-
this.readyState = undefined;
|
|
2767
|
-
this.withCredentials = undefined;
|
|
2768
|
-
this.headers = undefined;
|
|
2769
|
-
|
|
2770
|
-
this._close = undefined;
|
|
2771
|
-
|
|
2772
|
-
start(this, url, options);
|
|
2773
|
-
}
|
|
2774
|
-
|
|
2775
|
-
function getBestXHRTransport() {
|
|
2776
|
-
return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
|
|
2777
|
-
? new XMLHttpRequest()
|
|
2778
|
-
: new XDomainRequest();
|
|
2779
|
-
}
|
|
2780
|
-
|
|
2781
|
-
var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
|
|
2782
|
-
|
|
2783
|
-
function start(es, url, options) {
|
|
2784
|
-
url = String(url);
|
|
2785
|
-
var withCredentials = Boolean(options.withCredentials);
|
|
2786
|
-
var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
|
|
2787
|
-
|
|
2788
|
-
var initialRetry = clampDuration(1000);
|
|
2789
|
-
var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
|
|
2790
|
-
|
|
2791
|
-
var lastEventId = "";
|
|
2792
|
-
var retry = initialRetry;
|
|
2793
|
-
var wasActivity = false;
|
|
2794
|
-
var textLength = 0;
|
|
2795
|
-
var headers = options.headers || {};
|
|
2796
|
-
var TransportOption = options.Transport;
|
|
2797
|
-
var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
|
|
2798
|
-
var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
|
|
2799
|
-
var abortController = undefined;
|
|
2800
|
-
var timeout = 0;
|
|
2801
|
-
var currentState = WAITING;
|
|
2802
|
-
var dataBuffer = "";
|
|
2803
|
-
var lastEventIdBuffer = "";
|
|
2804
|
-
var eventTypeBuffer = "";
|
|
2805
|
-
|
|
2806
|
-
var textBuffer = "";
|
|
2807
|
-
var state = FIELD_START;
|
|
2808
|
-
var fieldStart = 0;
|
|
2809
|
-
var valueStart = 0;
|
|
2810
|
-
|
|
2811
|
-
var onStart = function (status, statusText, contentType, headers) {
|
|
2812
|
-
if (currentState === CONNECTING) {
|
|
2813
|
-
if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
|
|
2814
|
-
currentState = OPEN;
|
|
2815
|
-
wasActivity = Date.now();
|
|
2816
|
-
retry = initialRetry;
|
|
2817
|
-
es.readyState = OPEN;
|
|
2818
|
-
var event = new ConnectionEvent("open", {
|
|
2819
|
-
status: status,
|
|
2820
|
-
statusText: statusText,
|
|
2821
|
-
headers: headers
|
|
2822
|
-
});
|
|
2823
|
-
es.dispatchEvent(event);
|
|
2824
|
-
fire(es, es.onopen, event);
|
|
2825
|
-
} else {
|
|
2826
|
-
var message = "";
|
|
2827
|
-
if (status !== 200) {
|
|
2828
|
-
if (statusText) {
|
|
2829
|
-
statusText = statusText.replace(/\s+/g, " ");
|
|
2830
|
-
}
|
|
2831
|
-
message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
|
|
2832
|
-
} else {
|
|
2833
|
-
message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
|
|
2834
|
-
}
|
|
2835
|
-
close();
|
|
2836
|
-
var event = new ConnectionEvent("error", {
|
|
2837
|
-
status: status,
|
|
2838
|
-
statusText: statusText,
|
|
2839
|
-
headers: headers
|
|
2840
|
-
});
|
|
2841
|
-
es.dispatchEvent(event);
|
|
2842
|
-
fire(es, es.onerror, event);
|
|
2843
|
-
console.error(message);
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
};
|
|
2847
|
-
|
|
2848
|
-
var onProgress = function (textChunk) {
|
|
2849
|
-
if (currentState === OPEN) {
|
|
2850
|
-
var n = -1;
|
|
2851
|
-
for (var i = 0; i < textChunk.length; i += 1) {
|
|
2852
|
-
var c = textChunk.charCodeAt(i);
|
|
2853
|
-
if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
|
|
2854
|
-
n = i;
|
|
2855
|
-
}
|
|
2856
|
-
}
|
|
2857
|
-
var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
|
|
2858
|
-
textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
|
|
2859
|
-
if (textChunk !== "") {
|
|
2860
|
-
wasActivity = Date.now();
|
|
2861
|
-
textLength += textChunk.length;
|
|
2862
|
-
}
|
|
2863
|
-
for (var position = 0; position < chunk.length; position += 1) {
|
|
2864
|
-
var c = chunk.charCodeAt(position);
|
|
2865
|
-
if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
|
|
2866
|
-
state = FIELD_START;
|
|
2867
|
-
} else {
|
|
2868
|
-
if (state === AFTER_CR) {
|
|
2869
|
-
state = FIELD_START;
|
|
2870
|
-
}
|
|
2871
|
-
if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
|
|
2872
|
-
if (state !== FIELD_START) {
|
|
2873
|
-
if (state === FIELD) {
|
|
2874
|
-
valueStart = position + 1;
|
|
2875
|
-
}
|
|
2876
|
-
var field = chunk.slice(fieldStart, valueStart - 1);
|
|
2877
|
-
var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
|
|
2878
|
-
if (field === "data") {
|
|
2879
|
-
dataBuffer += "\n";
|
|
2880
|
-
dataBuffer += value;
|
|
2881
|
-
} else if (field === "id") {
|
|
2882
|
-
lastEventIdBuffer = value;
|
|
2883
|
-
} else if (field === "event") {
|
|
2884
|
-
eventTypeBuffer = value;
|
|
2885
|
-
} else if (field === "retry") {
|
|
2886
|
-
initialRetry = parseDuration(value, initialRetry);
|
|
2887
|
-
retry = initialRetry;
|
|
2888
|
-
} else if (field === "heartbeatTimeout") {
|
|
2889
|
-
heartbeatTimeout = parseDuration(value, heartbeatTimeout);
|
|
2890
|
-
if (timeout !== 0) {
|
|
2891
|
-
clearTimeout(timeout);
|
|
2892
|
-
timeout = setTimeout(function () {
|
|
2893
|
-
onTimeout();
|
|
2894
|
-
}, heartbeatTimeout);
|
|
2895
|
-
}
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
if (state === FIELD_START) {
|
|
2899
|
-
if (dataBuffer !== "") {
|
|
2900
|
-
lastEventId = lastEventIdBuffer;
|
|
2901
|
-
if (eventTypeBuffer === "") {
|
|
2902
|
-
eventTypeBuffer = "message";
|
|
2903
|
-
}
|
|
2904
|
-
var event = new MessageEvent(eventTypeBuffer, {
|
|
2905
|
-
data: dataBuffer.slice(1),
|
|
2906
|
-
lastEventId: lastEventIdBuffer
|
|
2907
|
-
});
|
|
2908
|
-
es.dispatchEvent(event);
|
|
2909
|
-
if (eventTypeBuffer === "open") {
|
|
2910
|
-
fire(es, es.onopen, event);
|
|
2911
|
-
} else if (eventTypeBuffer === "message") {
|
|
2912
|
-
fire(es, es.onmessage, event);
|
|
2913
|
-
} else if (eventTypeBuffer === "error") {
|
|
2914
|
-
fire(es, es.onerror, event);
|
|
2915
|
-
}
|
|
2916
|
-
if (currentState === CLOSED) {
|
|
2917
|
-
return;
|
|
2918
|
-
}
|
|
2919
|
-
}
|
|
2920
|
-
dataBuffer = "";
|
|
2921
|
-
eventTypeBuffer = "";
|
|
2922
|
-
}
|
|
2923
|
-
state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
|
|
2924
|
-
} else {
|
|
2925
|
-
if (state === FIELD_START) {
|
|
2926
|
-
fieldStart = position;
|
|
2927
|
-
state = FIELD;
|
|
2928
|
-
}
|
|
2929
|
-
if (state === FIELD) {
|
|
2930
|
-
if (c === ":".charCodeAt(0)) {
|
|
2931
|
-
valueStart = position + 1;
|
|
2932
|
-
state = VALUE_START;
|
|
2933
|
-
}
|
|
2934
|
-
} else if (state === VALUE_START) {
|
|
2935
|
-
state = VALUE;
|
|
2936
|
-
}
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
}
|
|
2940
|
-
}
|
|
2941
|
-
};
|
|
2942
|
-
|
|
2943
|
-
var onFinish = function (error) {
|
|
2944
|
-
if (currentState === OPEN || currentState === CONNECTING) {
|
|
2945
|
-
currentState = WAITING;
|
|
2946
|
-
if (timeout !== 0) {
|
|
2947
|
-
clearTimeout(timeout);
|
|
2948
|
-
timeout = 0;
|
|
2949
|
-
}
|
|
2950
|
-
timeout = setTimeout(function () {
|
|
2951
|
-
onTimeout();
|
|
2952
|
-
}, retry);
|
|
2953
|
-
retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
|
|
2954
|
-
|
|
2955
|
-
es.readyState = CONNECTING;
|
|
2956
|
-
var event = new ErrorEvent("error", {error: error});
|
|
2957
|
-
es.dispatchEvent(event);
|
|
2958
|
-
fire(es, es.onerror, event);
|
|
2959
|
-
if (error != undefined) {
|
|
2960
|
-
console.error(error);
|
|
2961
|
-
}
|
|
2962
|
-
}
|
|
2963
|
-
};
|
|
2964
|
-
|
|
2965
|
-
var close = function () {
|
|
2966
|
-
currentState = CLOSED;
|
|
2967
|
-
if (abortController != undefined) {
|
|
2968
|
-
abortController.abort();
|
|
2969
|
-
abortController = undefined;
|
|
2970
|
-
}
|
|
2971
|
-
if (timeout !== 0) {
|
|
2972
|
-
clearTimeout(timeout);
|
|
2973
|
-
timeout = 0;
|
|
2974
|
-
}
|
|
2975
|
-
es.readyState = CLOSED;
|
|
2976
|
-
};
|
|
2977
|
-
|
|
2978
|
-
var onTimeout = function () {
|
|
2979
|
-
timeout = 0;
|
|
2980
|
-
|
|
2981
|
-
if (currentState !== WAITING) {
|
|
2982
|
-
if (!wasActivity && abortController != undefined) {
|
|
2983
|
-
onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
|
|
2984
|
-
if (abortController != undefined) {
|
|
2985
|
-
abortController.abort();
|
|
2986
|
-
abortController = undefined;
|
|
2987
|
-
}
|
|
2988
|
-
} else {
|
|
2989
|
-
var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
|
|
2990
|
-
wasActivity = false;
|
|
2991
|
-
timeout = setTimeout(function () {
|
|
2992
|
-
onTimeout();
|
|
2993
|
-
}, nextHeartbeat);
|
|
2994
|
-
}
|
|
2995
|
-
return;
|
|
2996
|
-
}
|
|
2997
|
-
|
|
2998
|
-
wasActivity = false;
|
|
2999
|
-
textLength = 0;
|
|
3000
|
-
timeout = setTimeout(function () {
|
|
3001
|
-
onTimeout();
|
|
3002
|
-
}, heartbeatTimeout);
|
|
3003
|
-
|
|
3004
|
-
currentState = CONNECTING;
|
|
3005
|
-
dataBuffer = "";
|
|
3006
|
-
eventTypeBuffer = "";
|
|
3007
|
-
lastEventIdBuffer = lastEventId;
|
|
3008
|
-
textBuffer = "";
|
|
3009
|
-
fieldStart = 0;
|
|
3010
|
-
valueStart = 0;
|
|
3011
|
-
state = FIELD_START;
|
|
3012
|
-
|
|
3013
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=428916
|
|
3014
|
-
// Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
|
|
3015
|
-
var requestURL = url;
|
|
3016
|
-
if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
|
|
3017
|
-
if (lastEventId !== "") {
|
|
3018
|
-
// Remove the lastEventId parameter if it's already part of the request URL.
|
|
3019
|
-
var i = url.indexOf("?");
|
|
3020
|
-
requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
|
|
3021
|
-
return paramName === lastEventIdQueryParameterName ? '' : p;
|
|
3022
|
-
});
|
|
3023
|
-
// Append the current lastEventId to the request URL.
|
|
3024
|
-
requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
|
|
3025
|
-
}
|
|
3026
|
-
}
|
|
3027
|
-
var withCredentials = es.withCredentials;
|
|
3028
|
-
var requestHeaders = {};
|
|
3029
|
-
requestHeaders["Accept"] = "text/event-stream";
|
|
3030
|
-
var headers = es.headers;
|
|
3031
|
-
if (headers != undefined) {
|
|
3032
|
-
for (var name in headers) {
|
|
3033
|
-
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
3034
|
-
requestHeaders[name] = headers[name];
|
|
3035
|
-
}
|
|
3036
|
-
}
|
|
3037
|
-
}
|
|
3038
|
-
try {
|
|
3039
|
-
abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
|
|
3040
|
-
} catch (error) {
|
|
3041
|
-
close();
|
|
3042
|
-
throw error;
|
|
3043
|
-
}
|
|
3044
|
-
};
|
|
3045
|
-
|
|
3046
|
-
es.url = url;
|
|
3047
|
-
es.readyState = CONNECTING;
|
|
3048
|
-
es.withCredentials = withCredentials;
|
|
3049
|
-
es.headers = headers;
|
|
3050
|
-
es._close = close;
|
|
3051
|
-
|
|
3052
|
-
onTimeout();
|
|
3053
|
-
}
|
|
3054
|
-
|
|
3055
|
-
EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
|
|
3056
|
-
EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
|
|
3057
|
-
EventSourcePolyfill.prototype.OPEN = OPEN;
|
|
3058
|
-
EventSourcePolyfill.prototype.CLOSED = CLOSED;
|
|
3059
|
-
EventSourcePolyfill.prototype.close = function () {
|
|
3060
|
-
this._close();
|
|
3061
|
-
};
|
|
3062
|
-
|
|
3063
|
-
EventSourcePolyfill.CONNECTING = CONNECTING;
|
|
3064
|
-
EventSourcePolyfill.OPEN = OPEN;
|
|
3065
|
-
EventSourcePolyfill.CLOSED = CLOSED;
|
|
3066
|
-
EventSourcePolyfill.prototype.withCredentials = undefined;
|
|
3067
|
-
|
|
3068
|
-
var R = NativeEventSource;
|
|
3069
|
-
if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
|
|
3070
|
-
// Why replace a native EventSource ?
|
|
3071
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=444328
|
|
3072
|
-
// https://bugzilla.mozilla.org/show_bug.cgi?id=831392
|
|
3073
|
-
// https://code.google.com/p/chromium/issues/detail?id=260144
|
|
3074
|
-
// https://code.google.com/p/chromium/issues/detail?id=225654
|
|
3075
|
-
// ...
|
|
3076
|
-
R = EventSourcePolyfill;
|
|
3077
|
-
}
|
|
3078
|
-
|
|
3079
|
-
(function (factory) {
|
|
3080
|
-
{
|
|
3081
|
-
var v = factory(exports);
|
|
3082
|
-
if (v !== undefined) module.exports = v;
|
|
3083
|
-
}
|
|
3084
|
-
})(function (exports) {
|
|
3085
|
-
exports.EventSourcePolyfill = EventSourcePolyfill;
|
|
3086
|
-
exports.NativeEventSource = NativeEventSource;
|
|
3087
|
-
exports.EventSource = R;
|
|
3088
|
-
});
|
|
3089
|
-
}(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : commonjsGlobal) : globalThis));
|
|
3090
|
-
} (eventsource, eventsourceExports));
|
|
3091
|
-
|
|
3092
|
-
var browser = eventsourceExports.EventSourcePolyfill;
|
|
3093
|
-
|
|
3094
|
-
var polyfilledEventSource = browser;
|
|
3095
|
-
|
|
3096
|
-
var envMiddleware = [];
|
|
3097
|
-
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
3098
|
-
class ClientError extends Error {
|
|
3099
|
-
constructor(res) {
|
|
3100
|
-
const props = extractErrorProps(res);
|
|
3101
|
-
super(props.message);
|
|
3102
|
-
this.statusCode = 400;
|
|
3103
|
-
Object.assign(this, props);
|
|
3104
|
-
}
|
|
3105
|
-
}
|
|
3106
|
-
class ServerError extends Error {
|
|
3107
|
-
constructor(res) {
|
|
3108
|
-
const props = extractErrorProps(res);
|
|
3109
|
-
super(props.message);
|
|
3110
|
-
this.statusCode = 500;
|
|
3111
|
-
Object.assign(this, props);
|
|
3112
|
-
}
|
|
3113
|
-
}
|
|
3114
|
-
function extractErrorProps(res) {
|
|
3115
|
-
const body = res.body;
|
|
3116
|
-
const props = {
|
|
3117
|
-
response: res,
|
|
3118
|
-
statusCode: res.statusCode,
|
|
3119
|
-
responseBody: stringifyBody(body, res),
|
|
3120
|
-
message: "",
|
|
3121
|
-
details: void 0
|
|
3122
|
-
};
|
|
3123
|
-
if (body.error && body.message) {
|
|
3124
|
-
props.message = "".concat(body.error, " - ").concat(body.message);
|
|
3125
|
-
return props;
|
|
3126
|
-
}
|
|
3127
|
-
if (isMutationError(body)) {
|
|
3128
|
-
const allItems = body.error.items || [];
|
|
3129
|
-
const items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map(item => {
|
|
3130
|
-
var _a;
|
|
3131
|
-
return (_a = item.error) == null ? void 0 : _a.description;
|
|
3132
|
-
}).filter(Boolean);
|
|
3133
|
-
let itemsStr = items.length ? ":\n- ".concat(items.join("\n- ")) : "";
|
|
3134
|
-
if (allItems.length > MAX_ITEMS_IN_ERROR_MESSAGE) {
|
|
3135
|
-
itemsStr += "\n...and ".concat(allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE, " more");
|
|
3136
|
-
}
|
|
3137
|
-
props.message = "".concat(body.error.description).concat(itemsStr);
|
|
3138
|
-
props.details = body.error;
|
|
3139
|
-
return props;
|
|
3140
|
-
}
|
|
3141
|
-
if (body.error && body.error.description) {
|
|
3142
|
-
props.message = body.error.description;
|
|
3143
|
-
props.details = body.error;
|
|
3144
|
-
return props;
|
|
3145
|
-
}
|
|
3146
|
-
props.message = body.error || body.message || httpErrorMessage(res);
|
|
3147
|
-
return props;
|
|
3148
|
-
}
|
|
3149
|
-
function isMutationError(body) {
|
|
3150
|
-
return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "mutationError" && typeof body.error.description === "string";
|
|
3151
|
-
}
|
|
3152
|
-
function isPlainObject(obj) {
|
|
3153
|
-
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
3154
|
-
}
|
|
3155
|
-
function httpErrorMessage(res) {
|
|
3156
|
-
const statusMessage = res.statusMessage ? " ".concat(res.statusMessage) : "";
|
|
3157
|
-
return "".concat(res.method, "-request to ").concat(res.url, " resulted in HTTP ").concat(res.statusCode).concat(statusMessage);
|
|
3158
|
-
}
|
|
3159
|
-
function stringifyBody(body, res) {
|
|
3160
|
-
const contentType = (res.headers["content-type"] || "").toLowerCase();
|
|
3161
|
-
const isJson = contentType.indexOf("application/json") !== -1;
|
|
3162
|
-
return isJson ? JSON.stringify(body, null, 2) : body;
|
|
3163
|
-
}
|
|
3164
|
-
const httpError = {
|
|
3165
|
-
onResponse: res => {
|
|
3166
|
-
if (res.statusCode >= 500) {
|
|
3167
|
-
throw new ServerError(res);
|
|
3168
|
-
} else if (res.statusCode >= 400) {
|
|
3169
|
-
throw new ClientError(res);
|
|
3170
|
-
}
|
|
3171
|
-
return res;
|
|
3172
|
-
}
|
|
2057
|
+
var envMiddleware = [];
|
|
2058
|
+
const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
|
|
2059
|
+
class ClientError extends Error {
|
|
2060
|
+
constructor(res) {
|
|
2061
|
+
const props = extractErrorProps(res);
|
|
2062
|
+
super(props.message);
|
|
2063
|
+
this.statusCode = 400;
|
|
2064
|
+
Object.assign(this, props);
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
class ServerError extends Error {
|
|
2068
|
+
constructor(res) {
|
|
2069
|
+
const props = extractErrorProps(res);
|
|
2070
|
+
super(props.message);
|
|
2071
|
+
this.statusCode = 500;
|
|
2072
|
+
Object.assign(this, props);
|
|
2073
|
+
}
|
|
2074
|
+
}
|
|
2075
|
+
function extractErrorProps(res) {
|
|
2076
|
+
const body = res.body;
|
|
2077
|
+
const props = {
|
|
2078
|
+
response: res,
|
|
2079
|
+
statusCode: res.statusCode,
|
|
2080
|
+
responseBody: stringifyBody(body, res),
|
|
2081
|
+
message: "",
|
|
2082
|
+
details: void 0
|
|
2083
|
+
};
|
|
2084
|
+
if (body.error && body.message) {
|
|
2085
|
+
props.message = "".concat(body.error, " - ").concat(body.message);
|
|
2086
|
+
return props;
|
|
2087
|
+
}
|
|
2088
|
+
if (isMutationError(body)) {
|
|
2089
|
+
const allItems = body.error.items || [];
|
|
2090
|
+
const items = allItems.slice(0, MAX_ITEMS_IN_ERROR_MESSAGE).map(item => {
|
|
2091
|
+
var _a;
|
|
2092
|
+
return (_a = item.error) == null ? void 0 : _a.description;
|
|
2093
|
+
}).filter(Boolean);
|
|
2094
|
+
let itemsStr = items.length ? ":\n- ".concat(items.join("\n- ")) : "";
|
|
2095
|
+
if (allItems.length > MAX_ITEMS_IN_ERROR_MESSAGE) {
|
|
2096
|
+
itemsStr += "\n...and ".concat(allItems.length - MAX_ITEMS_IN_ERROR_MESSAGE, " more");
|
|
2097
|
+
}
|
|
2098
|
+
props.message = "".concat(body.error.description).concat(itemsStr);
|
|
2099
|
+
props.details = body.error;
|
|
2100
|
+
return props;
|
|
2101
|
+
}
|
|
2102
|
+
if (body.error && body.error.description) {
|
|
2103
|
+
props.message = body.error.description;
|
|
2104
|
+
props.details = body.error;
|
|
2105
|
+
return props;
|
|
2106
|
+
}
|
|
2107
|
+
props.message = body.error || body.message || httpErrorMessage(res);
|
|
2108
|
+
return props;
|
|
2109
|
+
}
|
|
2110
|
+
function isMutationError(body) {
|
|
2111
|
+
return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "mutationError" && typeof body.error.description === "string";
|
|
2112
|
+
}
|
|
2113
|
+
function isPlainObject(obj) {
|
|
2114
|
+
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
2115
|
+
}
|
|
2116
|
+
function httpErrorMessage(res) {
|
|
2117
|
+
const statusMessage = res.statusMessage ? " ".concat(res.statusMessage) : "";
|
|
2118
|
+
return "".concat(res.method, "-request to ").concat(res.url, " resulted in HTTP ").concat(res.statusCode).concat(statusMessage);
|
|
2119
|
+
}
|
|
2120
|
+
function stringifyBody(body, res) {
|
|
2121
|
+
const contentType = (res.headers["content-type"] || "").toLowerCase();
|
|
2122
|
+
const isJson = contentType.indexOf("application/json") !== -1;
|
|
2123
|
+
return isJson ? JSON.stringify(body, null, 2) : body;
|
|
2124
|
+
}
|
|
2125
|
+
const httpError = {
|
|
2126
|
+
onResponse: res => {
|
|
2127
|
+
if (res.statusCode >= 500) {
|
|
2128
|
+
throw new ServerError(res);
|
|
2129
|
+
} else if (res.statusCode >= 400) {
|
|
2130
|
+
throw new ClientError(res);
|
|
2131
|
+
}
|
|
2132
|
+
return res;
|
|
2133
|
+
}
|
|
3173
2134
|
};
|
|
3174
2135
|
const printWarnings = {
|
|
3175
2136
|
onResponse: res => {
|
|
@@ -4151,7 +3112,6 @@
|
|
|
4151
3112
|
return selection;
|
|
4152
3113
|
}, {});
|
|
4153
3114
|
const MAX_URL_LENGTH = 16e3 - 1200;
|
|
4154
|
-
const EventSource = polyfilledEventSource;
|
|
4155
3115
|
const possibleOptions = ["includePreviousRevision", "includeResult", "visibility", "effectFormat", "tag"];
|
|
4156
3116
|
const defaultOptions = {
|
|
4157
3117
|
includeResult: true
|
|
@@ -4194,7 +3154,13 @@
|
|
|
4194
3154
|
};
|
|
4195
3155
|
}
|
|
4196
3156
|
return new Observable(observer => {
|
|
4197
|
-
let es
|
|
3157
|
+
let es;
|
|
3158
|
+
getEventSource().then(eventSource => {
|
|
3159
|
+
es = eventSource;
|
|
3160
|
+
}).catch(reason => {
|
|
3161
|
+
observer.error(reason);
|
|
3162
|
+
stop();
|
|
3163
|
+
});
|
|
4198
3164
|
let reconnectTimer;
|
|
4199
3165
|
let stopped = false;
|
|
4200
3166
|
function onError() {
|
|
@@ -4205,7 +3171,7 @@
|
|
|
4205
3171
|
if (stopped) {
|
|
4206
3172
|
return;
|
|
4207
3173
|
}
|
|
4208
|
-
if (es.readyState ===
|
|
3174
|
+
if (es.readyState === es.CLOSED) {
|
|
4209
3175
|
unsubscribe();
|
|
4210
3176
|
clearTimeout(reconnectTimer);
|
|
4211
3177
|
reconnectTimer = setTimeout(open, 100);
|
|
@@ -4224,6 +3190,7 @@
|
|
|
4224
3190
|
observer.complete();
|
|
4225
3191
|
}
|
|
4226
3192
|
function unsubscribe() {
|
|
3193
|
+
if (!es) return;
|
|
4227
3194
|
es.removeEventListener("error", onError);
|
|
4228
3195
|
es.removeEventListener("channelError", onChannelError);
|
|
4229
3196
|
es.removeEventListener("disconnect", onDisconnect);
|
|
@@ -4237,7 +3204,10 @@
|
|
|
4237
3204
|
});
|
|
4238
3205
|
}
|
|
4239
3206
|
}
|
|
4240
|
-
function getEventSource() {
|
|
3207
|
+
async function getEventSource() {
|
|
3208
|
+
const {
|
|
3209
|
+
default: EventSource
|
|
3210
|
+
} = await Promise.resolve().then(function () { return browser$1; });
|
|
4241
3211
|
const evs = new EventSource(uri, esOptions);
|
|
4242
3212
|
evs.addEventListener("error", onError);
|
|
4243
3213
|
evs.addEventListener("channelError", onChannelError);
|
|
@@ -4246,7 +3216,12 @@
|
|
|
4246
3216
|
return evs;
|
|
4247
3217
|
}
|
|
4248
3218
|
function open() {
|
|
4249
|
-
|
|
3219
|
+
getEventSource().then(eventSource => {
|
|
3220
|
+
es = eventSource;
|
|
3221
|
+
}).catch(reason => {
|
|
3222
|
+
observer.error(reason);
|
|
3223
|
+
stop();
|
|
3224
|
+
});
|
|
4250
3225
|
}
|
|
4251
3226
|
function stop() {
|
|
4252
3227
|
stopped = true;
|
|
@@ -4836,6 +3811,1063 @@
|
|
|
4836
3811
|
return new SanityClient(httpRequest, config);
|
|
4837
3812
|
}
|
|
4838
3813
|
|
|
3814
|
+
var eventsourceExports = {};
|
|
3815
|
+
var eventsource = {
|
|
3816
|
+
get exports(){ return eventsourceExports; },
|
|
3817
|
+
set exports(v){ eventsourceExports = v; },
|
|
3818
|
+
};
|
|
3819
|
+
|
|
3820
|
+
/** @license
|
|
3821
|
+
* eventsource.js
|
|
3822
|
+
* Available under MIT License (MIT)
|
|
3823
|
+
* https://github.com/Yaffle/EventSource/
|
|
3824
|
+
*/
|
|
3825
|
+
|
|
3826
|
+
(function (module, exports) {
|
|
3827
|
+
/*jslint indent: 2, vars: true, plusplus: true */
|
|
3828
|
+
/*global setTimeout, clearTimeout */
|
|
3829
|
+
|
|
3830
|
+
(function (global) {
|
|
3831
|
+
|
|
3832
|
+
var setTimeout = global.setTimeout;
|
|
3833
|
+
var clearTimeout = global.clearTimeout;
|
|
3834
|
+
var XMLHttpRequest = global.XMLHttpRequest;
|
|
3835
|
+
var XDomainRequest = global.XDomainRequest;
|
|
3836
|
+
var ActiveXObject = global.ActiveXObject;
|
|
3837
|
+
var NativeEventSource = global.EventSource;
|
|
3838
|
+
|
|
3839
|
+
var document = global.document;
|
|
3840
|
+
var Promise = global.Promise;
|
|
3841
|
+
var fetch = global.fetch;
|
|
3842
|
+
var Response = global.Response;
|
|
3843
|
+
var TextDecoder = global.TextDecoder;
|
|
3844
|
+
var TextEncoder = global.TextEncoder;
|
|
3845
|
+
var AbortController = global.AbortController;
|
|
3846
|
+
|
|
3847
|
+
if (typeof window !== "undefined" && typeof document !== "undefined" && !("readyState" in document) && document.body == null) { // Firefox 2
|
|
3848
|
+
document.readyState = "loading";
|
|
3849
|
+
window.addEventListener("load", function (event) {
|
|
3850
|
+
document.readyState = "complete";
|
|
3851
|
+
}, false);
|
|
3852
|
+
}
|
|
3853
|
+
|
|
3854
|
+
if (XMLHttpRequest == null && ActiveXObject != null) { // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest_in_IE6
|
|
3855
|
+
XMLHttpRequest = function () {
|
|
3856
|
+
return new ActiveXObject("Microsoft.XMLHTTP");
|
|
3857
|
+
};
|
|
3858
|
+
}
|
|
3859
|
+
|
|
3860
|
+
if (Object.create == undefined) {
|
|
3861
|
+
Object.create = function (C) {
|
|
3862
|
+
function F(){}
|
|
3863
|
+
F.prototype = C;
|
|
3864
|
+
return new F();
|
|
3865
|
+
};
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
|
+
if (!Date.now) {
|
|
3869
|
+
Date.now = function now() {
|
|
3870
|
+
return new Date().getTime();
|
|
3871
|
+
};
|
|
3872
|
+
}
|
|
3873
|
+
|
|
3874
|
+
// see #118 (Promise#finally with polyfilled Promise)
|
|
3875
|
+
// see #123 (data URLs crash Edge)
|
|
3876
|
+
// see #125 (CSP violations)
|
|
3877
|
+
// see pull/#138
|
|
3878
|
+
// => No way to polyfill Promise#finally
|
|
3879
|
+
|
|
3880
|
+
if (AbortController == undefined) {
|
|
3881
|
+
var originalFetch2 = fetch;
|
|
3882
|
+
fetch = function (url, options) {
|
|
3883
|
+
var signal = options.signal;
|
|
3884
|
+
return originalFetch2(url, {headers: options.headers, credentials: options.credentials, cache: options.cache}).then(function (response) {
|
|
3885
|
+
var reader = response.body.getReader();
|
|
3886
|
+
signal._reader = reader;
|
|
3887
|
+
if (signal._aborted) {
|
|
3888
|
+
signal._reader.cancel();
|
|
3889
|
+
}
|
|
3890
|
+
return {
|
|
3891
|
+
status: response.status,
|
|
3892
|
+
statusText: response.statusText,
|
|
3893
|
+
headers: response.headers,
|
|
3894
|
+
body: {
|
|
3895
|
+
getReader: function () {
|
|
3896
|
+
return reader;
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
};
|
|
3900
|
+
});
|
|
3901
|
+
};
|
|
3902
|
+
AbortController = function () {
|
|
3903
|
+
this.signal = {
|
|
3904
|
+
_reader: null,
|
|
3905
|
+
_aborted: false
|
|
3906
|
+
};
|
|
3907
|
+
this.abort = function () {
|
|
3908
|
+
if (this.signal._reader != null) {
|
|
3909
|
+
this.signal._reader.cancel();
|
|
3910
|
+
}
|
|
3911
|
+
this.signal._aborted = true;
|
|
3912
|
+
};
|
|
3913
|
+
};
|
|
3914
|
+
}
|
|
3915
|
+
|
|
3916
|
+
function TextDecoderPolyfill() {
|
|
3917
|
+
this.bitsNeeded = 0;
|
|
3918
|
+
this.codePoint = 0;
|
|
3919
|
+
}
|
|
3920
|
+
|
|
3921
|
+
TextDecoderPolyfill.prototype.decode = function (octets) {
|
|
3922
|
+
function valid(codePoint, shift, octetsCount) {
|
|
3923
|
+
if (octetsCount === 1) {
|
|
3924
|
+
return codePoint >= 0x0080 >> shift && codePoint << shift <= 0x07FF;
|
|
3925
|
+
}
|
|
3926
|
+
if (octetsCount === 2) {
|
|
3927
|
+
return codePoint >= 0x0800 >> shift && codePoint << shift <= 0xD7FF || codePoint >= 0xE000 >> shift && codePoint << shift <= 0xFFFF;
|
|
3928
|
+
}
|
|
3929
|
+
if (octetsCount === 3) {
|
|
3930
|
+
return codePoint >= 0x010000 >> shift && codePoint << shift <= 0x10FFFF;
|
|
3931
|
+
}
|
|
3932
|
+
throw new Error();
|
|
3933
|
+
}
|
|
3934
|
+
function octetsCount(bitsNeeded, codePoint) {
|
|
3935
|
+
if (bitsNeeded === 6 * 1) {
|
|
3936
|
+
return codePoint >> 6 > 15 ? 3 : codePoint > 31 ? 2 : 1;
|
|
3937
|
+
}
|
|
3938
|
+
if (bitsNeeded === 6 * 2) {
|
|
3939
|
+
return codePoint > 15 ? 3 : 2;
|
|
3940
|
+
}
|
|
3941
|
+
if (bitsNeeded === 6 * 3) {
|
|
3942
|
+
return 3;
|
|
3943
|
+
}
|
|
3944
|
+
throw new Error();
|
|
3945
|
+
}
|
|
3946
|
+
var REPLACER = 0xFFFD;
|
|
3947
|
+
var string = "";
|
|
3948
|
+
var bitsNeeded = this.bitsNeeded;
|
|
3949
|
+
var codePoint = this.codePoint;
|
|
3950
|
+
for (var i = 0; i < octets.length; i += 1) {
|
|
3951
|
+
var octet = octets[i];
|
|
3952
|
+
if (bitsNeeded !== 0) {
|
|
3953
|
+
if (octet < 128 || octet > 191 || !valid(codePoint << 6 | octet & 63, bitsNeeded - 6, octetsCount(bitsNeeded, codePoint))) {
|
|
3954
|
+
bitsNeeded = 0;
|
|
3955
|
+
codePoint = REPLACER;
|
|
3956
|
+
string += String.fromCharCode(codePoint);
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3959
|
+
if (bitsNeeded === 0) {
|
|
3960
|
+
if (octet >= 0 && octet <= 127) {
|
|
3961
|
+
bitsNeeded = 0;
|
|
3962
|
+
codePoint = octet;
|
|
3963
|
+
} else if (octet >= 192 && octet <= 223) {
|
|
3964
|
+
bitsNeeded = 6 * 1;
|
|
3965
|
+
codePoint = octet & 31;
|
|
3966
|
+
} else if (octet >= 224 && octet <= 239) {
|
|
3967
|
+
bitsNeeded = 6 * 2;
|
|
3968
|
+
codePoint = octet & 15;
|
|
3969
|
+
} else if (octet >= 240 && octet <= 247) {
|
|
3970
|
+
bitsNeeded = 6 * 3;
|
|
3971
|
+
codePoint = octet & 7;
|
|
3972
|
+
} else {
|
|
3973
|
+
bitsNeeded = 0;
|
|
3974
|
+
codePoint = REPLACER;
|
|
3975
|
+
}
|
|
3976
|
+
if (bitsNeeded !== 0 && !valid(codePoint, bitsNeeded, octetsCount(bitsNeeded, codePoint))) {
|
|
3977
|
+
bitsNeeded = 0;
|
|
3978
|
+
codePoint = REPLACER;
|
|
3979
|
+
}
|
|
3980
|
+
} else {
|
|
3981
|
+
bitsNeeded -= 6;
|
|
3982
|
+
codePoint = codePoint << 6 | octet & 63;
|
|
3983
|
+
}
|
|
3984
|
+
if (bitsNeeded === 0) {
|
|
3985
|
+
if (codePoint <= 0xFFFF) {
|
|
3986
|
+
string += String.fromCharCode(codePoint);
|
|
3987
|
+
} else {
|
|
3988
|
+
string += String.fromCharCode(0xD800 + (codePoint - 0xFFFF - 1 >> 10));
|
|
3989
|
+
string += String.fromCharCode(0xDC00 + (codePoint - 0xFFFF - 1 & 0x3FF));
|
|
3990
|
+
}
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
this.bitsNeeded = bitsNeeded;
|
|
3994
|
+
this.codePoint = codePoint;
|
|
3995
|
+
return string;
|
|
3996
|
+
};
|
|
3997
|
+
|
|
3998
|
+
// Firefox < 38 throws an error with stream option
|
|
3999
|
+
var supportsStreamOption = function () {
|
|
4000
|
+
try {
|
|
4001
|
+
return new TextDecoder().decode(new TextEncoder().encode("test"), {stream: true}) === "test";
|
|
4002
|
+
} catch (error) {
|
|
4003
|
+
console.debug("TextDecoder does not support streaming option. Using polyfill instead: " + error);
|
|
4004
|
+
}
|
|
4005
|
+
return false;
|
|
4006
|
+
};
|
|
4007
|
+
|
|
4008
|
+
// IE, Edge
|
|
4009
|
+
if (TextDecoder == undefined || TextEncoder == undefined || !supportsStreamOption()) {
|
|
4010
|
+
TextDecoder = TextDecoderPolyfill;
|
|
4011
|
+
}
|
|
4012
|
+
|
|
4013
|
+
var k = function () {
|
|
4014
|
+
};
|
|
4015
|
+
|
|
4016
|
+
function XHRWrapper(xhr) {
|
|
4017
|
+
this.withCredentials = false;
|
|
4018
|
+
this.readyState = 0;
|
|
4019
|
+
this.status = 0;
|
|
4020
|
+
this.statusText = "";
|
|
4021
|
+
this.responseText = "";
|
|
4022
|
+
this.onprogress = k;
|
|
4023
|
+
this.onload = k;
|
|
4024
|
+
this.onerror = k;
|
|
4025
|
+
this.onreadystatechange = k;
|
|
4026
|
+
this._contentType = "";
|
|
4027
|
+
this._xhr = xhr;
|
|
4028
|
+
this._sendTimeout = 0;
|
|
4029
|
+
this._abort = k;
|
|
4030
|
+
}
|
|
4031
|
+
|
|
4032
|
+
XHRWrapper.prototype.open = function (method, url) {
|
|
4033
|
+
this._abort(true);
|
|
4034
|
+
|
|
4035
|
+
var that = this;
|
|
4036
|
+
var xhr = this._xhr;
|
|
4037
|
+
var state = 1;
|
|
4038
|
+
var timeout = 0;
|
|
4039
|
+
|
|
4040
|
+
this._abort = function (silent) {
|
|
4041
|
+
if (that._sendTimeout !== 0) {
|
|
4042
|
+
clearTimeout(that._sendTimeout);
|
|
4043
|
+
that._sendTimeout = 0;
|
|
4044
|
+
}
|
|
4045
|
+
if (state === 1 || state === 2 || state === 3) {
|
|
4046
|
+
state = 4;
|
|
4047
|
+
xhr.onload = k;
|
|
4048
|
+
xhr.onerror = k;
|
|
4049
|
+
xhr.onabort = k;
|
|
4050
|
+
xhr.onprogress = k;
|
|
4051
|
+
xhr.onreadystatechange = k;
|
|
4052
|
+
// IE 8 - 9: XDomainRequest#abort() does not fire any event
|
|
4053
|
+
// Opera < 10: XMLHttpRequest#abort() does not fire any event
|
|
4054
|
+
xhr.abort();
|
|
4055
|
+
if (timeout !== 0) {
|
|
4056
|
+
clearTimeout(timeout);
|
|
4057
|
+
timeout = 0;
|
|
4058
|
+
}
|
|
4059
|
+
if (!silent) {
|
|
4060
|
+
that.readyState = 4;
|
|
4061
|
+
that.onabort(null);
|
|
4062
|
+
that.onreadystatechange();
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
state = 0;
|
|
4066
|
+
};
|
|
4067
|
+
|
|
4068
|
+
var onStart = function () {
|
|
4069
|
+
if (state === 1) {
|
|
4070
|
+
//state = 2;
|
|
4071
|
+
var status = 0;
|
|
4072
|
+
var statusText = "";
|
|
4073
|
+
var contentType = undefined;
|
|
4074
|
+
if (!("contentType" in xhr)) {
|
|
4075
|
+
try {
|
|
4076
|
+
status = xhr.status;
|
|
4077
|
+
statusText = xhr.statusText;
|
|
4078
|
+
contentType = xhr.getResponseHeader("Content-Type");
|
|
4079
|
+
} catch (error) {
|
|
4080
|
+
// IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
|
|
4081
|
+
// Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
|
|
4082
|
+
// https://bugs.webkit.org/show_bug.cgi?id=29121
|
|
4083
|
+
status = 0;
|
|
4084
|
+
statusText = "";
|
|
4085
|
+
contentType = undefined;
|
|
4086
|
+
// Firefox < 14, Chrome ?, Safari ?
|
|
4087
|
+
// https://bugs.webkit.org/show_bug.cgi?id=29658
|
|
4088
|
+
// https://bugs.webkit.org/show_bug.cgi?id=77854
|
|
4089
|
+
}
|
|
4090
|
+
} else {
|
|
4091
|
+
status = 200;
|
|
4092
|
+
statusText = "OK";
|
|
4093
|
+
contentType = xhr.contentType;
|
|
4094
|
+
}
|
|
4095
|
+
if (status !== 0) {
|
|
4096
|
+
state = 2;
|
|
4097
|
+
that.readyState = 2;
|
|
4098
|
+
that.status = status;
|
|
4099
|
+
that.statusText = statusText;
|
|
4100
|
+
that._contentType = contentType;
|
|
4101
|
+
that.onreadystatechange();
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
};
|
|
4105
|
+
var onProgress = function () {
|
|
4106
|
+
onStart();
|
|
4107
|
+
if (state === 2 || state === 3) {
|
|
4108
|
+
state = 3;
|
|
4109
|
+
var responseText = "";
|
|
4110
|
+
try {
|
|
4111
|
+
responseText = xhr.responseText;
|
|
4112
|
+
} catch (error) {
|
|
4113
|
+
// IE 8 - 9 with XMLHttpRequest
|
|
4114
|
+
}
|
|
4115
|
+
that.readyState = 3;
|
|
4116
|
+
that.responseText = responseText;
|
|
4117
|
+
that.onprogress();
|
|
4118
|
+
}
|
|
4119
|
+
};
|
|
4120
|
+
var onFinish = function (type, event) {
|
|
4121
|
+
if (event == null || event.preventDefault == null) {
|
|
4122
|
+
event = {
|
|
4123
|
+
preventDefault: k
|
|
4124
|
+
};
|
|
4125
|
+
}
|
|
4126
|
+
// Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
|
|
4127
|
+
// IE 8 fires "onload" without "onprogress"
|
|
4128
|
+
onProgress();
|
|
4129
|
+
if (state === 1 || state === 2 || state === 3) {
|
|
4130
|
+
state = 4;
|
|
4131
|
+
if (timeout !== 0) {
|
|
4132
|
+
clearTimeout(timeout);
|
|
4133
|
+
timeout = 0;
|
|
4134
|
+
}
|
|
4135
|
+
that.readyState = 4;
|
|
4136
|
+
if (type === "load") {
|
|
4137
|
+
that.onload(event);
|
|
4138
|
+
} else if (type === "error") {
|
|
4139
|
+
that.onerror(event);
|
|
4140
|
+
} else if (type === "abort") {
|
|
4141
|
+
that.onabort(event);
|
|
4142
|
+
} else {
|
|
4143
|
+
throw new TypeError();
|
|
4144
|
+
}
|
|
4145
|
+
that.onreadystatechange();
|
|
4146
|
+
}
|
|
4147
|
+
};
|
|
4148
|
+
var onReadyStateChange = function (event) {
|
|
4149
|
+
if (xhr != undefined) { // Opera 12
|
|
4150
|
+
if (xhr.readyState === 4) {
|
|
4151
|
+
if (!("onload" in xhr) || !("onerror" in xhr) || !("onabort" in xhr)) {
|
|
4152
|
+
onFinish(xhr.responseText === "" ? "error" : "load", event);
|
|
4153
|
+
}
|
|
4154
|
+
} else if (xhr.readyState === 3) {
|
|
4155
|
+
if (!("onprogress" in xhr)) { // testing XMLHttpRequest#responseText too many times is too slow in IE 11
|
|
4156
|
+
// and in Firefox 3.6
|
|
4157
|
+
onProgress();
|
|
4158
|
+
}
|
|
4159
|
+
} else if (xhr.readyState === 2) {
|
|
4160
|
+
onStart();
|
|
4161
|
+
}
|
|
4162
|
+
}
|
|
4163
|
+
};
|
|
4164
|
+
var onTimeout = function () {
|
|
4165
|
+
timeout = setTimeout(function () {
|
|
4166
|
+
onTimeout();
|
|
4167
|
+
}, 500);
|
|
4168
|
+
if (xhr.readyState === 3) {
|
|
4169
|
+
onProgress();
|
|
4170
|
+
}
|
|
4171
|
+
};
|
|
4172
|
+
|
|
4173
|
+
// XDomainRequest#abort removes onprogress, onerror, onload
|
|
4174
|
+
if ("onload" in xhr) {
|
|
4175
|
+
xhr.onload = function (event) {
|
|
4176
|
+
onFinish("load", event);
|
|
4177
|
+
};
|
|
4178
|
+
}
|
|
4179
|
+
if ("onerror" in xhr) {
|
|
4180
|
+
xhr.onerror = function (event) {
|
|
4181
|
+
onFinish("error", event);
|
|
4182
|
+
};
|
|
4183
|
+
}
|
|
4184
|
+
// improper fix to match Firefox behaviour, but it is better than just ignore abort
|
|
4185
|
+
// see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
|
|
4186
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=880200
|
|
4187
|
+
// https://code.google.com/p/chromium/issues/detail?id=153570
|
|
4188
|
+
// IE 8 fires "onload" without "onprogress
|
|
4189
|
+
if ("onabort" in xhr) {
|
|
4190
|
+
xhr.onabort = function (event) {
|
|
4191
|
+
onFinish("abort", event);
|
|
4192
|
+
};
|
|
4193
|
+
}
|
|
4194
|
+
|
|
4195
|
+
if ("onprogress" in xhr) {
|
|
4196
|
+
xhr.onprogress = onProgress;
|
|
4197
|
+
}
|
|
4198
|
+
|
|
4199
|
+
// IE 8 - 9 (XMLHTTPRequest)
|
|
4200
|
+
// Opera < 12
|
|
4201
|
+
// Firefox < 3.5
|
|
4202
|
+
// Firefox 3.5 - 3.6 - ? < 9.0
|
|
4203
|
+
// onprogress is not fired sometimes or delayed
|
|
4204
|
+
// see also #64 (significant lag in IE 11)
|
|
4205
|
+
if ("onreadystatechange" in xhr) {
|
|
4206
|
+
xhr.onreadystatechange = function (event) {
|
|
4207
|
+
onReadyStateChange(event);
|
|
4208
|
+
};
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
if ("contentType" in xhr || !("ontimeout" in XMLHttpRequest.prototype)) {
|
|
4212
|
+
url += (url.indexOf("?") === -1 ? "?" : "&") + "padding=true";
|
|
4213
|
+
}
|
|
4214
|
+
xhr.open(method, url, true);
|
|
4215
|
+
|
|
4216
|
+
if ("readyState" in xhr) {
|
|
4217
|
+
// workaround for Opera 12 issue with "progress" events
|
|
4218
|
+
// #91 (XMLHttpRequest onprogress not fired for streaming response in Edge 14-15-?)
|
|
4219
|
+
timeout = setTimeout(function () {
|
|
4220
|
+
onTimeout();
|
|
4221
|
+
}, 0);
|
|
4222
|
+
}
|
|
4223
|
+
};
|
|
4224
|
+
XHRWrapper.prototype.abort = function () {
|
|
4225
|
+
this._abort(false);
|
|
4226
|
+
};
|
|
4227
|
+
XHRWrapper.prototype.getResponseHeader = function (name) {
|
|
4228
|
+
return this._contentType;
|
|
4229
|
+
};
|
|
4230
|
+
XHRWrapper.prototype.setRequestHeader = function (name, value) {
|
|
4231
|
+
var xhr = this._xhr;
|
|
4232
|
+
if ("setRequestHeader" in xhr) {
|
|
4233
|
+
xhr.setRequestHeader(name, value);
|
|
4234
|
+
}
|
|
4235
|
+
};
|
|
4236
|
+
XHRWrapper.prototype.getAllResponseHeaders = function () {
|
|
4237
|
+
// XMLHttpRequest#getAllResponseHeaders returns null for CORS requests in Firefox 3.6.28
|
|
4238
|
+
return this._xhr.getAllResponseHeaders != undefined ? this._xhr.getAllResponseHeaders() || "" : "";
|
|
4239
|
+
};
|
|
4240
|
+
XHRWrapper.prototype.send = function () {
|
|
4241
|
+
// loading indicator in Safari < ? (6), Chrome < 14, Firefox
|
|
4242
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=736723
|
|
4243
|
+
if ((!("ontimeout" in XMLHttpRequest.prototype) || (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype))) &&
|
|
4244
|
+
document != undefined &&
|
|
4245
|
+
document.readyState != undefined &&
|
|
4246
|
+
document.readyState !== "complete") {
|
|
4247
|
+
var that = this;
|
|
4248
|
+
that._sendTimeout = setTimeout(function () {
|
|
4249
|
+
that._sendTimeout = 0;
|
|
4250
|
+
that.send();
|
|
4251
|
+
}, 4);
|
|
4252
|
+
return;
|
|
4253
|
+
}
|
|
4254
|
+
|
|
4255
|
+
var xhr = this._xhr;
|
|
4256
|
+
// withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
|
|
4257
|
+
if ("withCredentials" in xhr) {
|
|
4258
|
+
xhr.withCredentials = this.withCredentials;
|
|
4259
|
+
}
|
|
4260
|
+
try {
|
|
4261
|
+
// xhr.send(); throws "Not enough arguments" in Firefox 3.0
|
|
4262
|
+
xhr.send(undefined);
|
|
4263
|
+
} catch (error1) {
|
|
4264
|
+
// Safari 5.1.7, Opera 12
|
|
4265
|
+
throw error1;
|
|
4266
|
+
}
|
|
4267
|
+
};
|
|
4268
|
+
|
|
4269
|
+
function toLowerCase(name) {
|
|
4270
|
+
return name.replace(/[A-Z]/g, function (c) {
|
|
4271
|
+
return String.fromCharCode(c.charCodeAt(0) + 0x20);
|
|
4272
|
+
});
|
|
4273
|
+
}
|
|
4274
|
+
|
|
4275
|
+
function HeadersPolyfill(all) {
|
|
4276
|
+
// Get headers: implemented according to mozilla's example code: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/getAllResponseHeaders#Example
|
|
4277
|
+
var map = Object.create(null);
|
|
4278
|
+
var array = all.split("\r\n");
|
|
4279
|
+
for (var i = 0; i < array.length; i += 1) {
|
|
4280
|
+
var line = array[i];
|
|
4281
|
+
var parts = line.split(": ");
|
|
4282
|
+
var name = parts.shift();
|
|
4283
|
+
var value = parts.join(": ");
|
|
4284
|
+
map[toLowerCase(name)] = value;
|
|
4285
|
+
}
|
|
4286
|
+
this._map = map;
|
|
4287
|
+
}
|
|
4288
|
+
HeadersPolyfill.prototype.get = function (name) {
|
|
4289
|
+
return this._map[toLowerCase(name)];
|
|
4290
|
+
};
|
|
4291
|
+
|
|
4292
|
+
if (XMLHttpRequest != null && XMLHttpRequest.HEADERS_RECEIVED == null) { // IE < 9, Firefox 3.6
|
|
4293
|
+
XMLHttpRequest.HEADERS_RECEIVED = 2;
|
|
4294
|
+
}
|
|
4295
|
+
|
|
4296
|
+
function XHRTransport() {
|
|
4297
|
+
}
|
|
4298
|
+
|
|
4299
|
+
XHRTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
4300
|
+
xhr.open("GET", url);
|
|
4301
|
+
var offset = 0;
|
|
4302
|
+
xhr.onprogress = function () {
|
|
4303
|
+
var responseText = xhr.responseText;
|
|
4304
|
+
var chunk = responseText.slice(offset);
|
|
4305
|
+
offset += chunk.length;
|
|
4306
|
+
onProgressCallback(chunk);
|
|
4307
|
+
};
|
|
4308
|
+
xhr.onerror = function (event) {
|
|
4309
|
+
event.preventDefault();
|
|
4310
|
+
onFinishCallback(new Error("NetworkError"));
|
|
4311
|
+
};
|
|
4312
|
+
xhr.onload = function () {
|
|
4313
|
+
onFinishCallback(null);
|
|
4314
|
+
};
|
|
4315
|
+
xhr.onabort = function () {
|
|
4316
|
+
onFinishCallback(null);
|
|
4317
|
+
};
|
|
4318
|
+
xhr.onreadystatechange = function () {
|
|
4319
|
+
if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
|
|
4320
|
+
var status = xhr.status;
|
|
4321
|
+
var statusText = xhr.statusText;
|
|
4322
|
+
var contentType = xhr.getResponseHeader("Content-Type");
|
|
4323
|
+
var headers = xhr.getAllResponseHeaders();
|
|
4324
|
+
onStartCallback(status, statusText, contentType, new HeadersPolyfill(headers));
|
|
4325
|
+
}
|
|
4326
|
+
};
|
|
4327
|
+
xhr.withCredentials = withCredentials;
|
|
4328
|
+
for (var name in headers) {
|
|
4329
|
+
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
4330
|
+
xhr.setRequestHeader(name, headers[name]);
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
xhr.send();
|
|
4334
|
+
return xhr;
|
|
4335
|
+
};
|
|
4336
|
+
|
|
4337
|
+
function HeadersWrapper(headers) {
|
|
4338
|
+
this._headers = headers;
|
|
4339
|
+
}
|
|
4340
|
+
HeadersWrapper.prototype.get = function (name) {
|
|
4341
|
+
return this._headers.get(name);
|
|
4342
|
+
};
|
|
4343
|
+
|
|
4344
|
+
function FetchTransport() {
|
|
4345
|
+
}
|
|
4346
|
+
|
|
4347
|
+
FetchTransport.prototype.open = function (xhr, onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
|
|
4348
|
+
var reader = null;
|
|
4349
|
+
var controller = new AbortController();
|
|
4350
|
+
var signal = controller.signal;
|
|
4351
|
+
var textDecoder = new TextDecoder();
|
|
4352
|
+
fetch(url, {
|
|
4353
|
+
headers: headers,
|
|
4354
|
+
credentials: withCredentials ? "include" : "same-origin",
|
|
4355
|
+
signal: signal,
|
|
4356
|
+
cache: "no-store"
|
|
4357
|
+
}).then(function (response) {
|
|
4358
|
+
reader = response.body.getReader();
|
|
4359
|
+
onStartCallback(response.status, response.statusText, response.headers.get("Content-Type"), new HeadersWrapper(response.headers));
|
|
4360
|
+
// see https://github.com/promises-aplus/promises-spec/issues/179
|
|
4361
|
+
return new Promise(function (resolve, reject) {
|
|
4362
|
+
var readNextChunk = function () {
|
|
4363
|
+
reader.read().then(function (result) {
|
|
4364
|
+
if (result.done) {
|
|
4365
|
+
//Note: bytes in textDecoder are ignored
|
|
4366
|
+
resolve(undefined);
|
|
4367
|
+
} else {
|
|
4368
|
+
var chunk = textDecoder.decode(result.value, {stream: true});
|
|
4369
|
+
onProgressCallback(chunk);
|
|
4370
|
+
readNextChunk();
|
|
4371
|
+
}
|
|
4372
|
+
})["catch"](function (error) {
|
|
4373
|
+
reject(error);
|
|
4374
|
+
});
|
|
4375
|
+
};
|
|
4376
|
+
readNextChunk();
|
|
4377
|
+
});
|
|
4378
|
+
})["catch"](function (error) {
|
|
4379
|
+
if (error.name === "AbortError") {
|
|
4380
|
+
return undefined;
|
|
4381
|
+
} else {
|
|
4382
|
+
return error;
|
|
4383
|
+
}
|
|
4384
|
+
}).then(function (error) {
|
|
4385
|
+
onFinishCallback(error);
|
|
4386
|
+
});
|
|
4387
|
+
return {
|
|
4388
|
+
abort: function () {
|
|
4389
|
+
if (reader != null) {
|
|
4390
|
+
reader.cancel(); // https://bugzilla.mozilla.org/show_bug.cgi?id=1583815
|
|
4391
|
+
}
|
|
4392
|
+
controller.abort();
|
|
4393
|
+
}
|
|
4394
|
+
};
|
|
4395
|
+
};
|
|
4396
|
+
|
|
4397
|
+
function EventTarget() {
|
|
4398
|
+
this._listeners = Object.create(null);
|
|
4399
|
+
}
|
|
4400
|
+
|
|
4401
|
+
function throwError(e) {
|
|
4402
|
+
setTimeout(function () {
|
|
4403
|
+
throw e;
|
|
4404
|
+
}, 0);
|
|
4405
|
+
}
|
|
4406
|
+
|
|
4407
|
+
EventTarget.prototype.dispatchEvent = function (event) {
|
|
4408
|
+
event.target = this;
|
|
4409
|
+
var typeListeners = this._listeners[event.type];
|
|
4410
|
+
if (typeListeners != undefined) {
|
|
4411
|
+
var length = typeListeners.length;
|
|
4412
|
+
for (var i = 0; i < length; i += 1) {
|
|
4413
|
+
var listener = typeListeners[i];
|
|
4414
|
+
try {
|
|
4415
|
+
if (typeof listener.handleEvent === "function") {
|
|
4416
|
+
listener.handleEvent(event);
|
|
4417
|
+
} else {
|
|
4418
|
+
listener.call(this, event);
|
|
4419
|
+
}
|
|
4420
|
+
} catch (e) {
|
|
4421
|
+
throwError(e);
|
|
4422
|
+
}
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
};
|
|
4426
|
+
EventTarget.prototype.addEventListener = function (type, listener) {
|
|
4427
|
+
type = String(type);
|
|
4428
|
+
var listeners = this._listeners;
|
|
4429
|
+
var typeListeners = listeners[type];
|
|
4430
|
+
if (typeListeners == undefined) {
|
|
4431
|
+
typeListeners = [];
|
|
4432
|
+
listeners[type] = typeListeners;
|
|
4433
|
+
}
|
|
4434
|
+
var found = false;
|
|
4435
|
+
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
4436
|
+
if (typeListeners[i] === listener) {
|
|
4437
|
+
found = true;
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
if (!found) {
|
|
4441
|
+
typeListeners.push(listener);
|
|
4442
|
+
}
|
|
4443
|
+
};
|
|
4444
|
+
EventTarget.prototype.removeEventListener = function (type, listener) {
|
|
4445
|
+
type = String(type);
|
|
4446
|
+
var listeners = this._listeners;
|
|
4447
|
+
var typeListeners = listeners[type];
|
|
4448
|
+
if (typeListeners != undefined) {
|
|
4449
|
+
var filtered = [];
|
|
4450
|
+
for (var i = 0; i < typeListeners.length; i += 1) {
|
|
4451
|
+
if (typeListeners[i] !== listener) {
|
|
4452
|
+
filtered.push(typeListeners[i]);
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
if (filtered.length === 0) {
|
|
4456
|
+
delete listeners[type];
|
|
4457
|
+
} else {
|
|
4458
|
+
listeners[type] = filtered;
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
};
|
|
4462
|
+
|
|
4463
|
+
function Event(type) {
|
|
4464
|
+
this.type = type;
|
|
4465
|
+
this.target = undefined;
|
|
4466
|
+
}
|
|
4467
|
+
|
|
4468
|
+
function MessageEvent(type, options) {
|
|
4469
|
+
Event.call(this, type);
|
|
4470
|
+
this.data = options.data;
|
|
4471
|
+
this.lastEventId = options.lastEventId;
|
|
4472
|
+
}
|
|
4473
|
+
|
|
4474
|
+
MessageEvent.prototype = Object.create(Event.prototype);
|
|
4475
|
+
|
|
4476
|
+
function ConnectionEvent(type, options) {
|
|
4477
|
+
Event.call(this, type);
|
|
4478
|
+
this.status = options.status;
|
|
4479
|
+
this.statusText = options.statusText;
|
|
4480
|
+
this.headers = options.headers;
|
|
4481
|
+
}
|
|
4482
|
+
|
|
4483
|
+
ConnectionEvent.prototype = Object.create(Event.prototype);
|
|
4484
|
+
|
|
4485
|
+
function ErrorEvent(type, options) {
|
|
4486
|
+
Event.call(this, type);
|
|
4487
|
+
this.error = options.error;
|
|
4488
|
+
}
|
|
4489
|
+
|
|
4490
|
+
ErrorEvent.prototype = Object.create(Event.prototype);
|
|
4491
|
+
|
|
4492
|
+
var WAITING = -1;
|
|
4493
|
+
var CONNECTING = 0;
|
|
4494
|
+
var OPEN = 1;
|
|
4495
|
+
var CLOSED = 2;
|
|
4496
|
+
|
|
4497
|
+
var AFTER_CR = -1;
|
|
4498
|
+
var FIELD_START = 0;
|
|
4499
|
+
var FIELD = 1;
|
|
4500
|
+
var VALUE_START = 2;
|
|
4501
|
+
var VALUE = 3;
|
|
4502
|
+
|
|
4503
|
+
var contentTypeRegExp = /^text\/event\-stream(;.*)?$/i;
|
|
4504
|
+
|
|
4505
|
+
var MINIMUM_DURATION = 1000;
|
|
4506
|
+
var MAXIMUM_DURATION = 18000000;
|
|
4507
|
+
|
|
4508
|
+
var parseDuration = function (value, def) {
|
|
4509
|
+
var n = value == null ? def : parseInt(value, 10);
|
|
4510
|
+
if (n !== n) {
|
|
4511
|
+
n = def;
|
|
4512
|
+
}
|
|
4513
|
+
return clampDuration(n);
|
|
4514
|
+
};
|
|
4515
|
+
var clampDuration = function (n) {
|
|
4516
|
+
return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
|
|
4517
|
+
};
|
|
4518
|
+
|
|
4519
|
+
var fire = function (that, f, event) {
|
|
4520
|
+
try {
|
|
4521
|
+
if (typeof f === "function") {
|
|
4522
|
+
f.call(that, event);
|
|
4523
|
+
}
|
|
4524
|
+
} catch (e) {
|
|
4525
|
+
throwError(e);
|
|
4526
|
+
}
|
|
4527
|
+
};
|
|
4528
|
+
|
|
4529
|
+
function EventSourcePolyfill(url, options) {
|
|
4530
|
+
EventTarget.call(this);
|
|
4531
|
+
options = options || {};
|
|
4532
|
+
|
|
4533
|
+
this.onopen = undefined;
|
|
4534
|
+
this.onmessage = undefined;
|
|
4535
|
+
this.onerror = undefined;
|
|
4536
|
+
|
|
4537
|
+
this.url = undefined;
|
|
4538
|
+
this.readyState = undefined;
|
|
4539
|
+
this.withCredentials = undefined;
|
|
4540
|
+
this.headers = undefined;
|
|
4541
|
+
|
|
4542
|
+
this._close = undefined;
|
|
4543
|
+
|
|
4544
|
+
start(this, url, options);
|
|
4545
|
+
}
|
|
4546
|
+
|
|
4547
|
+
function getBestXHRTransport() {
|
|
4548
|
+
return (XMLHttpRequest != undefined && ("withCredentials" in XMLHttpRequest.prototype)) || XDomainRequest == undefined
|
|
4549
|
+
? new XMLHttpRequest()
|
|
4550
|
+
: new XDomainRequest();
|
|
4551
|
+
}
|
|
4552
|
+
|
|
4553
|
+
var isFetchSupported = fetch != undefined && Response != undefined && "body" in Response.prototype;
|
|
4554
|
+
|
|
4555
|
+
function start(es, url, options) {
|
|
4556
|
+
url = String(url);
|
|
4557
|
+
var withCredentials = Boolean(options.withCredentials);
|
|
4558
|
+
var lastEventIdQueryParameterName = options.lastEventIdQueryParameterName || "lastEventId";
|
|
4559
|
+
|
|
4560
|
+
var initialRetry = clampDuration(1000);
|
|
4561
|
+
var heartbeatTimeout = parseDuration(options.heartbeatTimeout, 45000);
|
|
4562
|
+
|
|
4563
|
+
var lastEventId = "";
|
|
4564
|
+
var retry = initialRetry;
|
|
4565
|
+
var wasActivity = false;
|
|
4566
|
+
var textLength = 0;
|
|
4567
|
+
var headers = options.headers || {};
|
|
4568
|
+
var TransportOption = options.Transport;
|
|
4569
|
+
var xhr = isFetchSupported && TransportOption == undefined ? undefined : new XHRWrapper(TransportOption != undefined ? new TransportOption() : getBestXHRTransport());
|
|
4570
|
+
var transport = TransportOption != null && typeof TransportOption !== "string" ? new TransportOption() : (xhr == undefined ? new FetchTransport() : new XHRTransport());
|
|
4571
|
+
var abortController = undefined;
|
|
4572
|
+
var timeout = 0;
|
|
4573
|
+
var currentState = WAITING;
|
|
4574
|
+
var dataBuffer = "";
|
|
4575
|
+
var lastEventIdBuffer = "";
|
|
4576
|
+
var eventTypeBuffer = "";
|
|
4577
|
+
|
|
4578
|
+
var textBuffer = "";
|
|
4579
|
+
var state = FIELD_START;
|
|
4580
|
+
var fieldStart = 0;
|
|
4581
|
+
var valueStart = 0;
|
|
4582
|
+
|
|
4583
|
+
var onStart = function (status, statusText, contentType, headers) {
|
|
4584
|
+
if (currentState === CONNECTING) {
|
|
4585
|
+
if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
|
|
4586
|
+
currentState = OPEN;
|
|
4587
|
+
wasActivity = Date.now();
|
|
4588
|
+
retry = initialRetry;
|
|
4589
|
+
es.readyState = OPEN;
|
|
4590
|
+
var event = new ConnectionEvent("open", {
|
|
4591
|
+
status: status,
|
|
4592
|
+
statusText: statusText,
|
|
4593
|
+
headers: headers
|
|
4594
|
+
});
|
|
4595
|
+
es.dispatchEvent(event);
|
|
4596
|
+
fire(es, es.onopen, event);
|
|
4597
|
+
} else {
|
|
4598
|
+
var message = "";
|
|
4599
|
+
if (status !== 200) {
|
|
4600
|
+
if (statusText) {
|
|
4601
|
+
statusText = statusText.replace(/\s+/g, " ");
|
|
4602
|
+
}
|
|
4603
|
+
message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
|
|
4604
|
+
} else {
|
|
4605
|
+
message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
|
|
4606
|
+
}
|
|
4607
|
+
close();
|
|
4608
|
+
var event = new ConnectionEvent("error", {
|
|
4609
|
+
status: status,
|
|
4610
|
+
statusText: statusText,
|
|
4611
|
+
headers: headers
|
|
4612
|
+
});
|
|
4613
|
+
es.dispatchEvent(event);
|
|
4614
|
+
fire(es, es.onerror, event);
|
|
4615
|
+
console.error(message);
|
|
4616
|
+
}
|
|
4617
|
+
}
|
|
4618
|
+
};
|
|
4619
|
+
|
|
4620
|
+
var onProgress = function (textChunk) {
|
|
4621
|
+
if (currentState === OPEN) {
|
|
4622
|
+
var n = -1;
|
|
4623
|
+
for (var i = 0; i < textChunk.length; i += 1) {
|
|
4624
|
+
var c = textChunk.charCodeAt(i);
|
|
4625
|
+
if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
|
|
4626
|
+
n = i;
|
|
4627
|
+
}
|
|
4628
|
+
}
|
|
4629
|
+
var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
|
|
4630
|
+
textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
|
|
4631
|
+
if (textChunk !== "") {
|
|
4632
|
+
wasActivity = Date.now();
|
|
4633
|
+
textLength += textChunk.length;
|
|
4634
|
+
}
|
|
4635
|
+
for (var position = 0; position < chunk.length; position += 1) {
|
|
4636
|
+
var c = chunk.charCodeAt(position);
|
|
4637
|
+
if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
|
|
4638
|
+
state = FIELD_START;
|
|
4639
|
+
} else {
|
|
4640
|
+
if (state === AFTER_CR) {
|
|
4641
|
+
state = FIELD_START;
|
|
4642
|
+
}
|
|
4643
|
+
if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
|
|
4644
|
+
if (state !== FIELD_START) {
|
|
4645
|
+
if (state === FIELD) {
|
|
4646
|
+
valueStart = position + 1;
|
|
4647
|
+
}
|
|
4648
|
+
var field = chunk.slice(fieldStart, valueStart - 1);
|
|
4649
|
+
var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
|
|
4650
|
+
if (field === "data") {
|
|
4651
|
+
dataBuffer += "\n";
|
|
4652
|
+
dataBuffer += value;
|
|
4653
|
+
} else if (field === "id") {
|
|
4654
|
+
lastEventIdBuffer = value;
|
|
4655
|
+
} else if (field === "event") {
|
|
4656
|
+
eventTypeBuffer = value;
|
|
4657
|
+
} else if (field === "retry") {
|
|
4658
|
+
initialRetry = parseDuration(value, initialRetry);
|
|
4659
|
+
retry = initialRetry;
|
|
4660
|
+
} else if (field === "heartbeatTimeout") {
|
|
4661
|
+
heartbeatTimeout = parseDuration(value, heartbeatTimeout);
|
|
4662
|
+
if (timeout !== 0) {
|
|
4663
|
+
clearTimeout(timeout);
|
|
4664
|
+
timeout = setTimeout(function () {
|
|
4665
|
+
onTimeout();
|
|
4666
|
+
}, heartbeatTimeout);
|
|
4667
|
+
}
|
|
4668
|
+
}
|
|
4669
|
+
}
|
|
4670
|
+
if (state === FIELD_START) {
|
|
4671
|
+
if (dataBuffer !== "") {
|
|
4672
|
+
lastEventId = lastEventIdBuffer;
|
|
4673
|
+
if (eventTypeBuffer === "") {
|
|
4674
|
+
eventTypeBuffer = "message";
|
|
4675
|
+
}
|
|
4676
|
+
var event = new MessageEvent(eventTypeBuffer, {
|
|
4677
|
+
data: dataBuffer.slice(1),
|
|
4678
|
+
lastEventId: lastEventIdBuffer
|
|
4679
|
+
});
|
|
4680
|
+
es.dispatchEvent(event);
|
|
4681
|
+
if (eventTypeBuffer === "open") {
|
|
4682
|
+
fire(es, es.onopen, event);
|
|
4683
|
+
} else if (eventTypeBuffer === "message") {
|
|
4684
|
+
fire(es, es.onmessage, event);
|
|
4685
|
+
} else if (eventTypeBuffer === "error") {
|
|
4686
|
+
fire(es, es.onerror, event);
|
|
4687
|
+
}
|
|
4688
|
+
if (currentState === CLOSED) {
|
|
4689
|
+
return;
|
|
4690
|
+
}
|
|
4691
|
+
}
|
|
4692
|
+
dataBuffer = "";
|
|
4693
|
+
eventTypeBuffer = "";
|
|
4694
|
+
}
|
|
4695
|
+
state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
|
|
4696
|
+
} else {
|
|
4697
|
+
if (state === FIELD_START) {
|
|
4698
|
+
fieldStart = position;
|
|
4699
|
+
state = FIELD;
|
|
4700
|
+
}
|
|
4701
|
+
if (state === FIELD) {
|
|
4702
|
+
if (c === ":".charCodeAt(0)) {
|
|
4703
|
+
valueStart = position + 1;
|
|
4704
|
+
state = VALUE_START;
|
|
4705
|
+
}
|
|
4706
|
+
} else if (state === VALUE_START) {
|
|
4707
|
+
state = VALUE;
|
|
4708
|
+
}
|
|
4709
|
+
}
|
|
4710
|
+
}
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4713
|
+
};
|
|
4714
|
+
|
|
4715
|
+
var onFinish = function (error) {
|
|
4716
|
+
if (currentState === OPEN || currentState === CONNECTING) {
|
|
4717
|
+
currentState = WAITING;
|
|
4718
|
+
if (timeout !== 0) {
|
|
4719
|
+
clearTimeout(timeout);
|
|
4720
|
+
timeout = 0;
|
|
4721
|
+
}
|
|
4722
|
+
timeout = setTimeout(function () {
|
|
4723
|
+
onTimeout();
|
|
4724
|
+
}, retry);
|
|
4725
|
+
retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
|
|
4726
|
+
|
|
4727
|
+
es.readyState = CONNECTING;
|
|
4728
|
+
var event = new ErrorEvent("error", {error: error});
|
|
4729
|
+
es.dispatchEvent(event);
|
|
4730
|
+
fire(es, es.onerror, event);
|
|
4731
|
+
if (error != undefined) {
|
|
4732
|
+
console.error(error);
|
|
4733
|
+
}
|
|
4734
|
+
}
|
|
4735
|
+
};
|
|
4736
|
+
|
|
4737
|
+
var close = function () {
|
|
4738
|
+
currentState = CLOSED;
|
|
4739
|
+
if (abortController != undefined) {
|
|
4740
|
+
abortController.abort();
|
|
4741
|
+
abortController = undefined;
|
|
4742
|
+
}
|
|
4743
|
+
if (timeout !== 0) {
|
|
4744
|
+
clearTimeout(timeout);
|
|
4745
|
+
timeout = 0;
|
|
4746
|
+
}
|
|
4747
|
+
es.readyState = CLOSED;
|
|
4748
|
+
};
|
|
4749
|
+
|
|
4750
|
+
var onTimeout = function () {
|
|
4751
|
+
timeout = 0;
|
|
4752
|
+
|
|
4753
|
+
if (currentState !== WAITING) {
|
|
4754
|
+
if (!wasActivity && abortController != undefined) {
|
|
4755
|
+
onFinish(new Error("No activity within " + heartbeatTimeout + " milliseconds." + " " + (currentState === CONNECTING ? "No response received." : textLength + " chars received.") + " " + "Reconnecting."));
|
|
4756
|
+
if (abortController != undefined) {
|
|
4757
|
+
abortController.abort();
|
|
4758
|
+
abortController = undefined;
|
|
4759
|
+
}
|
|
4760
|
+
} else {
|
|
4761
|
+
var nextHeartbeat = Math.max((wasActivity || Date.now()) + heartbeatTimeout - Date.now(), 1);
|
|
4762
|
+
wasActivity = false;
|
|
4763
|
+
timeout = setTimeout(function () {
|
|
4764
|
+
onTimeout();
|
|
4765
|
+
}, nextHeartbeat);
|
|
4766
|
+
}
|
|
4767
|
+
return;
|
|
4768
|
+
}
|
|
4769
|
+
|
|
4770
|
+
wasActivity = false;
|
|
4771
|
+
textLength = 0;
|
|
4772
|
+
timeout = setTimeout(function () {
|
|
4773
|
+
onTimeout();
|
|
4774
|
+
}, heartbeatTimeout);
|
|
4775
|
+
|
|
4776
|
+
currentState = CONNECTING;
|
|
4777
|
+
dataBuffer = "";
|
|
4778
|
+
eventTypeBuffer = "";
|
|
4779
|
+
lastEventIdBuffer = lastEventId;
|
|
4780
|
+
textBuffer = "";
|
|
4781
|
+
fieldStart = 0;
|
|
4782
|
+
valueStart = 0;
|
|
4783
|
+
state = FIELD_START;
|
|
4784
|
+
|
|
4785
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=428916
|
|
4786
|
+
// Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
|
|
4787
|
+
var requestURL = url;
|
|
4788
|
+
if (url.slice(0, 5) !== "data:" && url.slice(0, 5) !== "blob:") {
|
|
4789
|
+
if (lastEventId !== "") {
|
|
4790
|
+
// Remove the lastEventId parameter if it's already part of the request URL.
|
|
4791
|
+
var i = url.indexOf("?");
|
|
4792
|
+
requestURL = i === -1 ? url : url.slice(0, i + 1) + url.slice(i + 1).replace(/(?:^|&)([^=&]*)(?:=[^&]*)?/g, function (p, paramName) {
|
|
4793
|
+
return paramName === lastEventIdQueryParameterName ? '' : p;
|
|
4794
|
+
});
|
|
4795
|
+
// Append the current lastEventId to the request URL.
|
|
4796
|
+
requestURL += (url.indexOf("?") === -1 ? "?" : "&") + lastEventIdQueryParameterName +"=" + encodeURIComponent(lastEventId);
|
|
4797
|
+
}
|
|
4798
|
+
}
|
|
4799
|
+
var withCredentials = es.withCredentials;
|
|
4800
|
+
var requestHeaders = {};
|
|
4801
|
+
requestHeaders["Accept"] = "text/event-stream";
|
|
4802
|
+
var headers = es.headers;
|
|
4803
|
+
if (headers != undefined) {
|
|
4804
|
+
for (var name in headers) {
|
|
4805
|
+
if (Object.prototype.hasOwnProperty.call(headers, name)) {
|
|
4806
|
+
requestHeaders[name] = headers[name];
|
|
4807
|
+
}
|
|
4808
|
+
}
|
|
4809
|
+
}
|
|
4810
|
+
try {
|
|
4811
|
+
abortController = transport.open(xhr, onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
|
|
4812
|
+
} catch (error) {
|
|
4813
|
+
close();
|
|
4814
|
+
throw error;
|
|
4815
|
+
}
|
|
4816
|
+
};
|
|
4817
|
+
|
|
4818
|
+
es.url = url;
|
|
4819
|
+
es.readyState = CONNECTING;
|
|
4820
|
+
es.withCredentials = withCredentials;
|
|
4821
|
+
es.headers = headers;
|
|
4822
|
+
es._close = close;
|
|
4823
|
+
|
|
4824
|
+
onTimeout();
|
|
4825
|
+
}
|
|
4826
|
+
|
|
4827
|
+
EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
|
|
4828
|
+
EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
|
|
4829
|
+
EventSourcePolyfill.prototype.OPEN = OPEN;
|
|
4830
|
+
EventSourcePolyfill.prototype.CLOSED = CLOSED;
|
|
4831
|
+
EventSourcePolyfill.prototype.close = function () {
|
|
4832
|
+
this._close();
|
|
4833
|
+
};
|
|
4834
|
+
|
|
4835
|
+
EventSourcePolyfill.CONNECTING = CONNECTING;
|
|
4836
|
+
EventSourcePolyfill.OPEN = OPEN;
|
|
4837
|
+
EventSourcePolyfill.CLOSED = CLOSED;
|
|
4838
|
+
EventSourcePolyfill.prototype.withCredentials = undefined;
|
|
4839
|
+
|
|
4840
|
+
var R = NativeEventSource;
|
|
4841
|
+
if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
|
|
4842
|
+
// Why replace a native EventSource ?
|
|
4843
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=444328
|
|
4844
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=831392
|
|
4845
|
+
// https://code.google.com/p/chromium/issues/detail?id=260144
|
|
4846
|
+
// https://code.google.com/p/chromium/issues/detail?id=225654
|
|
4847
|
+
// ...
|
|
4848
|
+
R = EventSourcePolyfill;
|
|
4849
|
+
}
|
|
4850
|
+
|
|
4851
|
+
(function (factory) {
|
|
4852
|
+
{
|
|
4853
|
+
var v = factory(exports);
|
|
4854
|
+
if (v !== undefined) module.exports = v;
|
|
4855
|
+
}
|
|
4856
|
+
})(function (exports) {
|
|
4857
|
+
exports.EventSourcePolyfill = EventSourcePolyfill;
|
|
4858
|
+
exports.NativeEventSource = NativeEventSource;
|
|
4859
|
+
exports.EventSource = R;
|
|
4860
|
+
});
|
|
4861
|
+
}(typeof globalThis === 'undefined' ? (typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : commonjsGlobal) : globalThis));
|
|
4862
|
+
} (eventsource, eventsourceExports));
|
|
4863
|
+
|
|
4864
|
+
var browser = eventsourceExports.EventSourcePolyfill;
|
|
4865
|
+
|
|
4866
|
+
var browser$1 = /*#__PURE__*/_mergeNamespaces({
|
|
4867
|
+
__proto__: null,
|
|
4868
|
+
default: browser
|
|
4869
|
+
}, [browser]);
|
|
4870
|
+
|
|
4839
4871
|
exports.BasePatch = BasePatch;
|
|
4840
4872
|
exports.BaseTransaction = BaseTransaction;
|
|
4841
4873
|
exports.ClientError = ClientError;
|