1
- import { ReactNativeBlobUtilConfig } from "./ types" ;
2
- import URIUtil from " ./utils/uri" ;
3
- import fs from " ./fs" ;
4
- import getUUID from " ./utils/uuid" ;
5
- import { DeviceEventEmitter } from " react-native" ;
6
- import { FetchBlobResponse } from " ./class/ReactNativeBlobUtilBlobResponse" ;
7
- import CanceledFetchError from " ./class/ReactNativeBlobUtilCanceledFetchError" ;
8
- import ReactNativeBlobUtil from " ./codegenSpecs/NativeBlobUtils" ;
1
+ import { ReactNativeBlobUtilConfig } from ' types' ;
2
+ import URIUtil from ' ./utils/uri' ;
3
+ import fs from ' ./fs' ;
4
+ import getUUID from ' ./utils/uuid' ;
5
+ import { DeviceEventEmitter , NativeEventEmitter , NativeModules } from ' react-native' ;
6
+ import { FetchBlobResponse } from ' ./class/ReactNativeBlobUtilBlobResponse' ;
7
+ import CanceledFetchError from ' ./class/ReactNativeBlobUtilCanceledFetchError' ;
8
+ import ReactNativeBlobUtil from ' ./codegenSpecs/NativeBlobUtils' ;
9
9
10
- const emitter = DeviceEventEmitter ;
10
+ const eventEmitter = new NativeEventEmitter ( ReactNativeBlobUtil ) ;
11
11
12
12
// register message channel event handler.
13
- emitter . addListener ( " ReactNativeBlobUtilMessage" , ( e ) => {
13
+ eventEmitter . addListener ( ' ReactNativeBlobUtilMessage' , ( e ) => {
14
14
15
15
if ( e . event === 'warn' ) {
16
16
console . warn ( e . detail ) ;
@@ -19,7 +19,7 @@ emitter.addListener("ReactNativeBlobUtilMessage", (e) => {
19
19
throw e . detail ;
20
20
}
21
21
else {
22
- console . log ( " ReactNativeBlobUtil native message" , e . detail ) ;
22
+ console . log ( ' ReactNativeBlobUtil native message' , e . detail ) ;
23
23
}
24
24
} ) ;
25
25
@@ -105,7 +105,7 @@ function fetchFile(options = {}, method, url, headers = {}, body): Promise {
105
105
. then ( ( stream ) => new Promise ( ( resolve , reject ) => {
106
106
stream . open ( ) ;
107
107
info = {
108
- state : "2" ,
108
+ state : '2' ,
109
109
headers : { 'source' : 'system-fs' } ,
110
110
status : 200 ,
111
111
respType : 'text' ,
@@ -188,31 +188,31 @@ export function fetch(...args: any): Promise {
188
188
let nativeMethodName = Array . isArray ( body ) ? 'fetchBlobForm' : 'fetchBlob' ;
189
189
190
190
// on progress event listener
191
- subscription = emitter . addListener ( 'ReactNativeBlobUtilProgress' , ( e ) => {
191
+ subscription = eventEmitter . addListener ( 'ReactNativeBlobUtilProgress' , ( e ) => {
192
192
if ( e . taskId === taskId && promise . onProgress ) {
193
193
promise . onProgress ( e . written , e . total , e . chunk ) ;
194
194
}
195
195
} ) ;
196
196
197
- subscriptionUpload = emitter . addListener ( 'ReactNativeBlobUtilProgress-upload' , ( e ) => {
197
+ subscriptionUpload = eventEmitter . addListener ( 'ReactNativeBlobUtilProgress-upload' , ( e ) => {
198
198
if ( e . taskId === taskId && promise . onUploadProgress ) {
199
199
promise . onUploadProgress ( e . written , e . total ) ;
200
200
}
201
201
} ) ;
202
202
203
- stateEvent = emitter . addListener ( 'ReactNativeBlobUtilState' , ( e ) => {
203
+ stateEvent = eventEmitter . addListener ( 'ReactNativeBlobUtilState' , ( e ) => {
204
204
if ( e . taskId === taskId )
205
205
respInfo = e ;
206
206
promise . onStateChange && promise . onStateChange ( e ) ;
207
207
} ) ;
208
208
209
- subscription = emitter . addListener ( 'ReactNativeBlobUtilExpire' , ( e ) => {
209
+ subscription = eventEmitter . addListener ( 'ReactNativeBlobUtilExpire' , ( e ) => {
210
210
if ( e . taskId === taskId && promise . onExpire ) {
211
211
promise . onExpire ( e ) ;
212
212
}
213
213
} ) ;
214
214
215
- partEvent = emitter . addListener ( 'ReactNativeBlobUtilServerPush' , ( e ) => {
215
+ partEvent = eventEmitter . addListener ( 'ReactNativeBlobUtilServerPush' , ( e ) => {
216
216
if ( e . taskId === taskId && promise . onPartData ) {
217
217
promise . onPartData ( e . chunk ) ;
218
218
}
@@ -244,11 +244,11 @@ export function fetch(...args: any): Promise {
244
244
subscriptionUpload . remove ( ) ;
245
245
stateEvent . remove ( ) ;
246
246
partEvent . remove ( ) ;
247
- delete promise [ ' progress' ] ;
248
- delete promise [ ' uploadProgress' ] ;
249
- delete promise [ ' stateChange' ] ;
250
- delete promise [ ' part' ] ;
251
- delete promise [ ' cancel' ] ;
247
+ delete promise . progress ;
248
+ delete promise . uploadProgress ;
249
+ delete promise . stateChange ;
250
+ delete promise . part ;
251
+ delete promise . cancel ;
252
252
// delete promise['expire']
253
253
promise . cancel = ( ) => {
254
254
} ;
@@ -329,7 +329,7 @@ export function fetch(...args: any): Promise {
329
329
subscriptionUpload . remove ( ) ;
330
330
stateEvent . remove ( ) ;
331
331
ReactNativeBlobUtil . cancelRequest ( taskId , fn ) ;
332
- promiseReject ( new CanceledFetchError ( " canceled" ) ) ;
332
+ promiseReject ( new CanceledFetchError ( ' canceled' ) ) ;
333
333
} ;
334
334
promise . taskId = taskId ;
335
335
0 commit comments