|
@@ -11,7 +11,7 @@ import ProgressEvent from './ProgressEvent.js'
|
11
|
11
|
const log = new Log('XMLHttpRequest')
|
12
|
12
|
|
13
|
13
|
log.disable()
|
14
|
|
-// log.level(2)
|
|
14
|
+// log.level(3)
|
15
|
15
|
|
16
|
16
|
const UNSENT = 0
|
17
|
17
|
const OPENED = 1
|
|
@@ -30,8 +30,9 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
30
|
30
|
|
31
|
31
|
// readonly
|
32
|
32
|
_readyState : number = UNSENT;
|
|
33
|
+ _uriType : 'net' | 'file' = 'net';
|
33
|
34
|
_response : any = '';
|
34
|
|
- _responseText : any = null;
|
|
35
|
+ _responseText : any = '';
|
35
|
36
|
_responseHeaders : any = {};
|
36
|
37
|
_responseType : '' | 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' = '';
|
37
|
38
|
// TODO : not suppoted ATM
|
|
@@ -42,6 +43,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
42
|
43
|
_timeout : number = 60000;
|
43
|
44
|
_sendFlag : boolean = false;
|
44
|
45
|
_uploadStarted : boolean = false;
|
|
46
|
+ _increment : boolean = false;
|
45
|
47
|
|
46
|
48
|
// RNFetchBlob compatible data structure
|
47
|
49
|
_config : RNFetchBlobConfig = {};
|
|
@@ -122,7 +124,10 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
122
|
124
|
this._method = method
|
123
|
125
|
this._url = url
|
124
|
126
|
this._headers = {}
|
|
127
|
+ this._increment = /^JSONStream\:\/\//.test(this._url)
|
|
128
|
+ this._url = this._url.replace(/^JSONStream\:\/\//, '')
|
125
|
129
|
this._dispatchReadStateChange(XMLHttpRequest.OPENED)
|
|
130
|
+
|
126
|
131
|
}
|
127
|
132
|
|
128
|
133
|
/**
|
|
@@ -130,7 +135,9 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
130
|
135
|
* @param {any} body Body in RNfetchblob flavor
|
131
|
136
|
*/
|
132
|
137
|
send(body) {
|
|
138
|
+
|
133
|
139
|
this._body = body
|
|
140
|
+
|
134
|
141
|
if(this._readyState !== XMLHttpRequest.OPENED)
|
135
|
142
|
throw 'InvalidStateError : XMLHttpRequest is not opened yet.'
|
136
|
143
|
let promise = Promise.resolve()
|
|
@@ -164,10 +171,12 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
164
|
171
|
for(let h in _headers) {
|
165
|
172
|
_headers[h] = _headers[h].toString()
|
166
|
173
|
}
|
|
174
|
+
|
167
|
175
|
this._task = RNFetchBlob
|
168
|
176
|
.config({
|
169
|
177
|
auto: true,
|
170
|
178
|
timeout : this._timeout,
|
|
179
|
+ increment : this._increment,
|
171
|
180
|
binaryContentTypes : XMLHttpRequest.binaryContentTypes
|
172
|
181
|
})
|
173
|
182
|
.fetch(_method, _url, _headers, body)
|
|
@@ -271,7 +280,7 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
271
|
280
|
this.upload.dispatchEvent('progress', new ProgressEvent(true, send, total))
|
272
|
281
|
}
|
273
|
282
|
|
274
|
|
- _progressEvent(send:number, total:number) {
|
|
283
|
+ _progressEvent(send:number, total:number, chunk:string) {
|
275
|
284
|
log.verbose(this.readyState)
|
276
|
285
|
if(this._readyState === XMLHttpRequest.HEADERS_RECEIVED)
|
277
|
286
|
this._dispatchReadStateChange(XMLHttpRequest.LOADING)
|
|
@@ -279,6 +288,10 @@ export default class XMLHttpRequest extends XMLHttpRequestEventTarget{
|
279
|
288
|
if(total && total >= 0)
|
280
|
289
|
lengthComputable = true
|
281
|
290
|
let e = new ProgressEvent(lengthComputable, send, total)
|
|
291
|
+
|
|
292
|
+ if(this._increment) {
|
|
293
|
+ this._responseText += chunk
|
|
294
|
+ }
|
282
|
295
|
this.dispatchEvent('progress', e)
|
283
|
296
|
}
|
284
|
297
|
|