17
17
18
18
#if __has_include(<React/RCTAssert.h>)
19
19
#import < React/RCTBridge.h>
20
- #import < React/RCTEventDispatcher.h>
21
20
#else
22
21
#import " RCTBridge.h"
23
- #import " RCTEventDispatcher.h"
24
22
#endif
25
23
26
24
@@ -58,12 +56,6 @@ - (id)initWithCallback:(RCTResponseSenderBlock)callback {
58
56
return self;
59
57
}
60
58
61
- - (id )initWithEventDispatcherRef : (RCTEventDispatcher *)eventDispatcherRef {
62
- self = [super init ];
63
- self.eventDispatcher = eventDispatcherRef;
64
- return self;
65
- }
66
-
67
59
// static member getter
68
60
+ (NSDictionary *) getFileStreams {
69
61
@@ -160,11 +152,10 @@ + (void) readStream:(NSString *)uri
160
152
bufferSize : (int )bufferSize
161
153
tick : (int )tick
162
154
streamId : (NSString *)streamId
163
- eventDispatcherRef : (RCTEventDispatcher *) eventDispatcherRef
155
+ baseModule : (ReactNativeBlobUtil*) baseModule
164
156
{
165
157
[[self class ] getPathFromUri: uri completionHandler: ^(NSString *path, ALAssetRepresentation *asset) {
166
158
167
- __block RCTEventDispatcher * event = eventDispatcherRef;
168
159
__block int read = 0 ;
169
160
__block int backoff = tick *1000 ;
170
161
__block int chunkSize = bufferSize;
@@ -179,15 +170,15 @@ + (void) readStream:(NSString *)uri
179
170
{
180
171
NSString * message = [NSString stringWithFormat: @" File does not exist at path %@ " , path];
181
172
NSDictionary * payload = @{ @" event" : FS_EVENT_ERROR, @" code" : @" ENOENT" , @" detail" : message };
182
- [event sendDeviceEventWithName : streamId body: payload];
173
+ [baseModule emitEventDict : streamId body: payload];
183
174
free (buffer);
184
175
return ;
185
176
}
186
177
NSInputStream * stream = [[NSInputStream alloc ] initWithFileAtPath: path];
187
178
[stream open ];
188
179
while ((read = [stream read :buffer maxLength: bufferSize]) > 0 )
189
180
{
190
- [[self class ] emitDataChunks: [NSData dataWithBytes: buffer length: read ] encoding: encoding streamId: streamId event: event ];
181
+ [[self class ] emitDataChunks: [NSData dataWithBytes: buffer length: read ] encoding: encoding streamId: streamId baseModule: baseModule ];
191
182
if (tick > 0 )
192
183
{
193
184
usleep (backoff);
@@ -202,7 +193,7 @@ + (void) readStream:(NSString *)uri
202
193
while ((read = [asset getBytes: buffer fromOffset: cursor length: bufferSize error: &err]) > 0 )
203
194
{
204
195
cursor += read ;
205
- [[self class ] emitDataChunks: [NSData dataWithBytes: buffer length: read ] encoding: encoding streamId: streamId event: event ];
196
+ [[self class ] emitDataChunks: [NSData dataWithBytes: buffer length: read ] encoding: encoding streamId: streamId baseModule: baseModule ];
206
197
if (tick > 0 )
207
198
{
208
199
usleep (backoff);
@@ -212,7 +203,7 @@ + (void) readStream:(NSString *)uri
212
203
else
213
204
{
214
205
NSDictionary * payload = @{ @" event" : FS_EVENT_ERROR, @" code" : @" EINVAL" , @" detail" : @" Unable to resolve URI" };
215
- [event sendDeviceEventWithName : streamId body: payload];
206
+ [baseModule emitEventDict : streamId body: payload];
216
207
}
217
208
// release buffer
218
209
if (buffer != nil )
@@ -222,12 +213,12 @@ + (void) readStream:(NSString *)uri
222
213
@catch (NSError * err)
223
214
{
224
215
NSDictionary * payload = @{ @" event" : FS_EVENT_ERROR, @" code" : @" EUNSPECIFIED" , @" detail" : [err description ] };
225
- [event sendDeviceEventWithName : streamId body: payload];
216
+ [baseModule emitEventDict : streamId body: payload];
226
217
}
227
218
@finally
228
219
{
229
220
NSDictionary * payload = @{ @" event" : FS_EVENT_END, @" detail" : @" " };
230
- [event sendDeviceEventWithName : streamId body: payload];
221
+ [baseModule emitEventDict : streamId body: payload];
231
222
}
232
223
233
224
}];
@@ -236,7 +227,7 @@ + (void) readStream:(NSString *)uri
236
227
}
237
228
238
229
// send read stream chunks via native event emitter
239
- + (void ) emitDataChunks : (NSData *)data encoding : (NSString *) encoding streamId : (NSString *)streamId event : (RCTEventDispatcher *)event
230
+ + (void ) emitDataChunks : (NSData *)data encoding : (NSString *) encoding streamId : (NSString *)streamId baseModule : (ReactNativeBlobUtil *)baseModule
240
231
{
241
232
@try
242
233
{
@@ -247,12 +238,12 @@ + (void) emitDataChunks:(NSData *)data encoding:(NSString *) encoding streamId:(
247
238
@" event" : FS_EVENT_DATA,
248
239
@" detail" : [[NSString alloc ] initWithData: data encoding: NSUTF8StringEncoding]
249
240
};
250
- [event sendDeviceEventWithName : streamId body: payload];
241
+ [baseModule emitEventDict : streamId body: payload];
251
242
}
252
243
else if ([[encoding lowercaseString ] isEqualToString: @" base64" ])
253
244
{
254
245
NSDictionary * payload = @{ @" event" : FS_EVENT_DATA, @" detail" : [data base64EncodedStringWithOptions: 0 ] };
255
- [event sendDeviceEventWithName : streamId body: payload];
246
+ [baseModule emitEventDict : streamId body: payload];
256
247
}
257
248
else if ([[encoding lowercaseString ] isEqualToString: @" ascii" ])
258
249
{
@@ -270,21 +261,21 @@ + (void) emitDataChunks:(NSData *)data encoding:(NSString *) encoding streamId:(
270
261
}
271
262
272
263
NSDictionary * payload = @{ @" event" : FS_EVENT_DATA, @" detail" : asciiArray };
273
- [event sendDeviceEventWithName : streamId body: payload];
264
+ [baseModule emitEventDict : streamId body: payload];
274
265
}
275
266
276
267
}
277
268
@catch (NSException * ex)
278
269
{
279
270
NSString * message = [NSString stringWithFormat: @" Failed to convert data to '%@ ' encoded string, this might due to the source data is not able to convert using this encoding. source = %@ " , encoding, [ex description ]];
280
- [event
281
- sendDeviceEventWithName : streamId
271
+ [baseModule
272
+ emitEventDict : streamId
282
273
body: @{
283
274
@" event" : MSG_EVENT_ERROR,
284
275
@" detail" : message
285
276
}];
286
- [event
287
- sendDeviceEventWithName : MSG_EVENT
277
+ [baseModule
278
+ emitEventDict : MSG_EVENT
288
279
body: @{
289
280
@" event" : MSG_EVENT_WARN,
290
281
@" detail" : message
0 commit comments