@@ -109,7 +109,21 @@ void TaskCancellationManager::Cancel(TaskId taskId) noexcept
109
109
}
110
110
}
111
111
112
-
112
+ /*
113
+ struct RNFetchBlobProgressConfig {
114
+ public:
115
+ RNFetchBlobProgressConfig();
116
+ RNFetchBlobProgressConfig(int32_t count_, int32_t interval_);
117
+
118
+ int32_t lastTick;
119
+ int32_t tick;
120
+ int32_t count;
121
+ int32_t interval;
122
+ };
123
+ */
124
+
125
+ RNFetchBlobProgressConfig::RNFetchBlobProgressConfig (int32_t count_, int32_t interval_) : count(count_), interval(interval_) {
126
+ }
113
127
114
128
void RNFetchBlob::Initialize (winrt::Microsoft::ReactNative::ReactContext const & reactContext) noexcept
115
129
{
@@ -1055,26 +1069,26 @@ winrt::fire_and_forget RNFetchBlob::fetchBlob(
1055
1069
1056
1070
RNFetchBlobConfig config;
1057
1071
1058
- if (!options[" Progress" ].IsNull ()) {
1059
- auto & downloadOptions{ options[" Progress" ].AsObject () };
1060
- if (!downloadOptions[" count" ].IsNull ()) {
1061
- int32_t downloadCount{ downloadOptions[" count" ].AsInt32 ()};
1062
- bool lol = true ;
1063
- }
1064
- if (!downloadOptions[" interval" ].IsNull ()) {
1065
- int32_t downloadInterval{ downloadOptions[" interval" ].AsInt32 () };
1066
- bool lol = true ;
1067
- }
1068
- }
1069
- if (!options[" UploadProgress" ].IsNull ()) {
1070
- auto & uploadOptions{ options[" UploadProgress" ].AsObject () };
1071
- if (!uploadOptions[" count" ].IsNull ()) {
1072
- int32_t uploadCount{ uploadOptions[" count" ].AsInt32 () };
1073
- }
1074
- if (!uploadOptions[" interval" ].IsNull ()) {
1075
- int32_t uploadInterval{ uploadOptions[" interval" ].AsInt32 () };
1076
- }
1077
- }
1072
+ // if (!options["Progress"].IsNull()) {
1073
+ // auto& downloadOptions{ options["Progress"].AsObject() };
1074
+ // if (!downloadOptions["count"].IsNull()) {
1075
+ // int32_t downloadCount{ downloadOptions["count"].AsInt32()};
1076
+ // bool lol = true;
1077
+ // }
1078
+ // if (!downloadOptions["interval"].IsNull()) {
1079
+ // int32_t downloadInterval{ downloadOptions["interval"].AsInt32() };
1080
+ // bool lol = true;
1081
+ // }
1082
+ // }
1083
+ // if (!options["UploadProgress"].IsNull()) {
1084
+ // auto& uploadOptions{ options["UploadProgress"].AsObject() };
1085
+ // if (!uploadOptions["count"].IsNull()) {
1086
+ // int32_t uploadCount{ uploadOptions["count"].AsInt32() };
1087
+ // }
1088
+ // if (!uploadOptions["interval"].IsNull()) {
1089
+ // int32_t uploadInterval{ uploadOptions["interval"].AsInt32() };
1090
+ // }
1091
+ // }
1078
1092
1079
1093
if (options[" appendExt" ].IsNull () == true )
1080
1094
{
@@ -1129,7 +1143,7 @@ winrt::fire_and_forget RNFetchBlob::fetchBlob(
1129
1143
std::string methodUpperCase{ method };
1130
1144
for (auto & c : methodUpperCase)
1131
1145
{
1132
- toupper (c);
1146
+ putchar ( toupper (c) );
1133
1147
}
1134
1148
1135
1149
// Delete, Patch, Post, Put, Get, Options, Head
@@ -1177,7 +1191,7 @@ winrt::fire_and_forget RNFetchBlob::fetchBlob(
1177
1191
}
1178
1192
1179
1193
requestMessage.Content (requestContent);
1180
- co_await m_tasks.Add (taskId, ProcessRequestAsync (filter, requestMessage, config, callback));
1194
+ co_await m_tasks.Add (taskId, ProcessRequestAsync (taskId, filter, requestMessage, config, callback));
1181
1195
1182
1196
}
1183
1197
@@ -1198,26 +1212,26 @@ winrt::fire_and_forget RNFetchBlob::fetchBlobForm(
1198
1212
1199
1213
RNFetchBlobConfig config;
1200
1214
1201
- if (!options[" Progress" ].IsNull ()) {
1202
- auto & downloadOptions{ options[" Progress" ].AsObject () };
1203
- if (!downloadOptions[" count" ].IsNull ()) {
1204
- int32_t downloadCount{ downloadOptions[" count" ].AsInt32 () };
1205
- bool lol = true ;
1206
- }
1207
- if (!downloadOptions[" interval" ].IsNull ()) {
1208
- int32_t downloadInterval{ downloadOptions[" interval" ].AsInt32 () };
1209
- bool lol = true ;
1210
- }
1211
- }
1212
- if (!options[" UploadProgress" ].IsNull ()) {
1213
- auto & uploadOptions{ options[" UploadProgress" ].AsObject () };
1214
- if (!uploadOptions[" count" ].IsNull ()) {
1215
- int32_t uploadCount{ uploadOptions[" count" ].AsInt32 () };
1216
- }
1217
- if (!uploadOptions[" interval" ].IsNull ()) {
1218
- int32_t uploadInterval{ uploadOptions[" interval" ].AsInt32 () };
1219
- }
1220
- }
1215
+ // if (!options["Progress"].IsNull()) {
1216
+ // auto& downloadOptions{ options["Progress"].AsObject() };
1217
+ // if (!downloadOptions["count"].IsNull()) {
1218
+ // int32_t downloadCount{ downloadOptions["count"].AsInt32() };
1219
+ // bool lol = true;
1220
+ // }
1221
+ // if (!downloadOptions["interval"].IsNull()) {
1222
+ // int32_t downloadInterval{ downloadOptions["interval"].AsInt32() };
1223
+ // bool lol = true;
1224
+ // }
1225
+ // }
1226
+ // if (!options["UploadProgress"].IsNull()) {
1227
+ // auto& uploadOptions{ options["UploadProgress"].AsObject() };
1228
+ // if (!uploadOptions["count"].IsNull()) {
1229
+ // int32_t uploadCount{ uploadOptions["count"].AsInt32() };
1230
+ // }
1231
+ // if (!uploadOptions["interval"].IsNull()) {
1232
+ // int32_t uploadInterval{ uploadOptions["interval"].AsInt32() };
1233
+ // }
1234
+ // }
1221
1235
1222
1236
if (options[" appendExt" ].IsNull () == true )
1223
1237
{
@@ -1354,7 +1368,7 @@ winrt::fire_and_forget RNFetchBlob::fetchBlobForm(
1354
1368
// // TODO: Add in multipart aspects
1355
1369
// }
1356
1370
requestMessage.Content (requestContent);
1357
- co_await m_tasks.Add (taskId, ProcessRequestAsync (filter, requestMessage, config, callback));
1371
+ co_await m_tasks.Add (taskId, ProcessRequestAsync (taskId, filter, requestMessage, config, callback));
1358
1372
}
1359
1373
1360
1374
// winrt::fire_and_forget RNFetchBlob::createBlobForm(
@@ -1374,18 +1388,20 @@ winrt::fire_and_forget RNFetchBlob::fetchBlobForm(
1374
1388
void RNFetchBlob::enableProgressReport (
1375
1389
std::string taskId,
1376
1390
int interval,
1377
- int count) noexcept
1378
- {
1379
- return ;
1391
+ int count) noexcept {
1392
+ RNFetchBlobProgressConfig config{interval, count};
1393
+ std::scoped_lock lock{ m_mutex };
1394
+ downloadProgressMap.try_emplace (taskId, config);
1380
1395
}
1381
1396
1382
1397
// enableUploadProgressReport
1383
1398
void RNFetchBlob::enableUploadProgressReport (
1384
1399
std::string taskId,
1385
1400
int interval,
1386
- int count) noexcept
1387
- {
1388
- return ;
1401
+ int count) noexcept {
1402
+ RNFetchBlobProgressConfig config{ interval, count };
1403
+ std::scoped_lock lock{ m_mutex };
1404
+ uploadProgressMap.try_emplace (taskId, config);
1389
1405
}
1390
1406
1391
1407
// cancelRequest
@@ -1456,6 +1472,7 @@ void RNFetchBlob::splitPath(const std::wstring& fullPath, winrt::hstring& direct
1456
1472
}
1457
1473
1458
1474
winrt::Windows::Foundation::IAsyncAction RNFetchBlob::ProcessRequestAsync (
1475
+ const std::string& taskId,
1459
1476
const winrt::Windows::Web::Http::Filters::HttpBaseProtocolFilter& filter,
1460
1477
winrt::Windows::Web::Http::HttpRequestMessage& httpRequestMessage,
1461
1478
RNFetchBlobConfig& config,
@@ -1491,32 +1508,45 @@ try
1491
1508
for (;;)
1492
1509
{
1493
1510
buffer.Length (0 );
1494
- auto readBuffer = contentStream.ReadAsync (buffer, buffer.Capacity (), InputStreamOptions::None). get ( );
1511
+ auto readBuffer = co_await contentStream.ReadAsync (buffer, buffer.Capacity (), InputStreamOptions::None);
1495
1512
totalRead += readBuffer.Length ();
1496
1513
if (readBuffer.Length () == 0 )
1497
1514
{
1498
1515
break ;
1499
1516
}
1500
1517
co_await outputStream.WriteAsync (readBuffer);
1501
1518
1502
- m_reactContext.CallJSFunction (L" RCTDeviceEventEmitter" , L" emit" , L" RNFetchBlobProgress" ,
1503
- Microsoft::ReactNative::JSValueObject{
1504
- { " recieved" , totalRead },
1505
- { " total" , contentLength.Type () == PropertyType::UInt64 ?
1506
- Microsoft::ReactNative::JSValue (contentLength.Value ()) :
1507
- Microsoft::ReactNative::JSValue{nullptr } },
1508
- });
1509
-
1519
+ // condition if taskId in a table where I need to report, then emit this
1520
+ // to do that, I need a map that with a mutex
1521
+ // mutex for all rn fetch blob main class
1522
+ // std::scoped_lock lock {m_mutex}
1523
+ auto it{ downloadProgressMap.find (taskId) };
1524
+ if (it != downloadProgressMap.end ()) {
1525
+ auto var{ downloadProgressMap[taskId] };
1526
+ m_reactContext.CallJSFunction (L" RCTDeviceEventEmitter" , L" emit" , L" RNFetchBlobProgress" ,
1527
+ Microsoft::ReactNative::JSValueObject{
1528
+ { " recieved" , totalRead },
1529
+ { " total" , contentLength.Type () == PropertyType::UInt64 ?
1530
+ Microsoft::ReactNative::JSValue (contentLength.Value ()) :
1531
+ Microsoft::ReactNative::JSValue{nullptr } },
1532
+ });
1533
+ }
1510
1534
}
1511
1535
callback (" " , " path" , config.path );
1512
1536
1513
1537
}
1514
1538
else {
1515
- m_reactContext.CallJSFunction (L" RCTDeviceEventEmitter" , L" emit" , L" RNFetchBlobProgress" ,
1516
- Microsoft::ReactNative::JSValueObject{
1517
- { " recieved" , 0 },
1518
- { " total" , 0 },
1519
- });
1539
+ auto it{ downloadProgressMap.find (taskId) };
1540
+ if (it != downloadProgressMap.end ()) {
1541
+
1542
+ auto var{ downloadProgressMap[taskId] };
1543
+
1544
+ m_reactContext.CallJSFunction (L" RCTDeviceEventEmitter" , L" emit" , L" RNFetchBlobProgress" ,
1545
+ Microsoft::ReactNative::JSValueObject{
1546
+ { " recieved" , 0 },
1547
+ { " total" , 0 },
1548
+ });
1549
+ }
1520
1550
callback (winrt::to_string (co_await response.Content ().ReadAsStringAsync ()), " result" , config.path );
1521
1551
}
1522
1552
co_return ;
0 commit comments