@bugsee/react-native 0.0.0-stage → 7.0.0-beta2
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/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +557 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +962 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
#import "include/BGSRNLaunchHold.h"
|
|
2
|
+
#import "include/BGSRNMainThread.h"
|
|
3
|
+
|
|
4
|
+
// WORKAROUND for https://github.com/bugsee/bugsee-cocoa/issues/227 -- see
|
|
5
|
+
// BGSRNLaunchHold.h. Remove once that is fixed.
|
|
6
|
+
|
|
7
|
+
const NSUInteger BGSRNLaunchHoldCapacity = 64;
|
|
8
|
+
const int64_t BGSRNLaunchHoldDeadlineMs = 30000;
|
|
9
|
+
|
|
10
|
+
static NSString *const kLaunched = @"com.bugsee.lifecycle.Launched";
|
|
11
|
+
static NSString *const kStopping = @"com.bugsee.lifecycle.Stopping";
|
|
12
|
+
static NSString *const kStopped = @"com.bugsee.lifecycle.Stopped";
|
|
13
|
+
|
|
14
|
+
@interface BGSRNHeldCall : NSObject
|
|
15
|
+
@property (nonatomic, copy) NSString *label;
|
|
16
|
+
@property (nonatomic, copy) BGSRNGatedCall call;
|
|
17
|
+
@end
|
|
18
|
+
|
|
19
|
+
@implementation BGSRNHeldCall
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
@implementation BGSRNLaunchHold {
|
|
23
|
+
NSUInteger _capacity;
|
|
24
|
+
int64_t _deadlineMs;
|
|
25
|
+
BugseeStatus (^_status)(void);
|
|
26
|
+
NSMutableArray<BGSRNHeldCall *> *_held;
|
|
27
|
+
/// Bumped whenever the held calls are settled, so a deadline armed for an
|
|
28
|
+
/// earlier batch does nothing to a later one.
|
|
29
|
+
NSUInteger _generation;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
+ (BGSRNLaunchHold *)shared {
|
|
33
|
+
static BGSRNLaunchHold *shared = nil;
|
|
34
|
+
static dispatch_once_t once;
|
|
35
|
+
dispatch_once(&once, ^{
|
|
36
|
+
shared = [[BGSRNLaunchHold alloc] initWithCapacity:BGSRNLaunchHoldCapacity
|
|
37
|
+
deadlineMs:BGSRNLaunchHoldDeadlineMs
|
|
38
|
+
status:^BugseeStatus {
|
|
39
|
+
Bugsee *instance = [Bugsee sharedInstance];
|
|
40
|
+
return instance != nil ? instance.status : BugseeStatusStopped;
|
|
41
|
+
}];
|
|
42
|
+
});
|
|
43
|
+
return shared;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
- (instancetype)initWithCapacity:(NSUInteger)capacity
|
|
47
|
+
deadlineMs:(int64_t)deadlineMs
|
|
48
|
+
status:(BugseeStatus (^)(void))status {
|
|
49
|
+
if ((self = [super init])) {
|
|
50
|
+
_capacity = capacity;
|
|
51
|
+
_deadlineMs = deadlineMs;
|
|
52
|
+
_status = [status copy];
|
|
53
|
+
_held = [NSMutableArray array];
|
|
54
|
+
}
|
|
55
|
+
return self;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (NSUInteger)heldCount {
|
|
59
|
+
return _held.count;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
- (void)submit:(NSString *)label call:(BGSRNGatedCall)call {
|
|
63
|
+
if (call == nil) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const BugseeStatus status = _status();
|
|
67
|
+
if (status == BugseeStatusLaunching) {
|
|
68
|
+
if (_held.count >= _capacity) {
|
|
69
|
+
NSLog(@"BugseeRN %@ dropped: %lu calls are already held until launched (bugsee-cocoa#227)",
|
|
70
|
+
label, (unsigned long)_held.count);
|
|
71
|
+
call(BGSRNGatedRunDrop);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
BGSRNHeldCall *held = [BGSRNHeldCall new];
|
|
75
|
+
held.label = label;
|
|
76
|
+
held.call = call;
|
|
77
|
+
[_held addObject:held];
|
|
78
|
+
NSLog(@"BugseeRN %@ held until launched (bugsee-cocoa#227) held=%lu", label,
|
|
79
|
+
(unsigned long)_held.count);
|
|
80
|
+
if (_held.count == 1) {
|
|
81
|
+
[self armDeadline];
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Whatever is held goes first: Launched can be visible here before its
|
|
86
|
+
// lifecycle event has arrived, and this call must not overtake older ones.
|
|
87
|
+
[self settleWithStatus:status reason:@"status changed"];
|
|
88
|
+
call(BGSRNGatedRunNow);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
- (void)lifecycleEvent:(NSString *)name {
|
|
92
|
+
if (![name isEqualToString:kLaunched] && ![name isEqualToString:kStopping] &&
|
|
93
|
+
![name isEqualToString:kStopped]) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// The SDK delivers lifecycle events on its own queue; the hold lives on main.
|
|
97
|
+
BGSRNRunOnMain(^{
|
|
98
|
+
[self settleWithStatus:self->_status() reason:name];
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// Replays everything held when `status` is Launched, drops it when it is
|
|
103
|
+
/// anything but Launching, and keeps holding while it is still Launching (a
|
|
104
|
+
/// Launched event from an earlier launch, overtaken by a stop and a
|
|
105
|
+
/// relaunch, must not release the new launch's calls).
|
|
106
|
+
- (void)settleWithStatus:(BugseeStatus)status reason:(NSString *)reason {
|
|
107
|
+
if (_held.count == 0 || status == BugseeStatusLaunching) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
NSArray<BGSRNHeldCall *> *held = [_held copy];
|
|
111
|
+
[_held removeAllObjects];
|
|
112
|
+
_generation += 1;
|
|
113
|
+
const BOOL replay = status == BugseeStatusLaunched;
|
|
114
|
+
if (replay) {
|
|
115
|
+
NSLog(@"BugseeRN launched: replaying %lu held call(s) (bugsee-cocoa#227)",
|
|
116
|
+
(unsigned long)held.count);
|
|
117
|
+
} else {
|
|
118
|
+
NSLog(@"BugseeRN launch did not complete (%@, status=%ld): dropping %lu held call(s) "
|
|
119
|
+
@"(bugsee-cocoa#227)",
|
|
120
|
+
reason, (long)status, (unsigned long)held.count);
|
|
121
|
+
}
|
|
122
|
+
for (BGSRNHeldCall *entry in held) {
|
|
123
|
+
entry.call(replay ? BGSRNGatedRunReplay : BGSRNGatedRunDrop);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
- (void)armDeadline {
|
|
128
|
+
if (_deadlineMs <= 0) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const NSUInteger generation = _generation;
|
|
132
|
+
__weak __typeof(self) weakSelf = self;
|
|
133
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, _deadlineMs * (int64_t)NSEC_PER_MSEC),
|
|
134
|
+
dispatch_get_main_queue(), ^{
|
|
135
|
+
__typeof(self) strongSelf = weakSelf;
|
|
136
|
+
if (strongSelf == nil || strongSelf->_generation != generation) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
BugseeStatus status = strongSelf->_status();
|
|
140
|
+
// Still Launching at the deadline: give up on this launch.
|
|
141
|
+
// Anything else settles as the event would have.
|
|
142
|
+
[strongSelf settleWithStatus:status == BugseeStatusLaunching ? BugseeStatusStopped : status
|
|
143
|
+
reason:@"deadline"];
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#import "BGSRNMainThread.h"
|
|
2
|
+
|
|
3
|
+
void BGSRNRunOnMain(dispatch_block_t block) {
|
|
4
|
+
if (block == nil) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
if ([NSThread isMainThread]) {
|
|
8
|
+
block();
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
dispatch_async(dispatch_get_main_queue(), block);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
void BGSRNRunOnMainSync(dispatch_block_t block) {
|
|
15
|
+
if (block == nil) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if ([NSThread isMainThread]) {
|
|
19
|
+
block();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
dispatch_sync(dispatch_get_main_queue(), block);
|
|
23
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#import "BGSRNNetworkEvents.h"
|
|
2
|
+
|
|
3
|
+
static NSString *const BGSRNNetworkEventMechanism = @"react-native";
|
|
4
|
+
|
|
5
|
+
static BOOL BGSRNIsStringOrNull(id value) {
|
|
6
|
+
return value == nil || value == [NSNull null] || [value isKindOfClass:[NSString class]];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static NSString *BGSRNStringOrNil(id value) {
|
|
10
|
+
if ([value isKindOfClass:[NSString class]]) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
return nil;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/// `completed` is the name JS and the device test use. The SDK's wire name
|
|
17
|
+
/// for that stage is `complete`, `BugseeNetworkEventComplete`.
|
|
18
|
+
static BOOL BGSRNNetworkStage(id name, BGSNetworkEventStage *out) {
|
|
19
|
+
if (name == nil || name == [NSNull null] || [name isEqual:@"completed"] || [name isEqual:@"complete"]) {
|
|
20
|
+
*out = BGSNetworkEventStageRequestCompleted;
|
|
21
|
+
return YES;
|
|
22
|
+
}
|
|
23
|
+
if (![name isKindOfClass:[NSString class]]) {
|
|
24
|
+
return NO;
|
|
25
|
+
}
|
|
26
|
+
NSString *wire = name;
|
|
27
|
+
if ([wire isEqualToString:@"started"]) {
|
|
28
|
+
wire = @"before";
|
|
29
|
+
} else if ([wire isEqualToString:@"aborted"] || [wire isEqualToString:@"cancel"]) {
|
|
30
|
+
wire = @"abort";
|
|
31
|
+
} else if ([wire isEqualToString:@"timings"]) {
|
|
32
|
+
wire = @"timing";
|
|
33
|
+
}
|
|
34
|
+
if ([wire isEqualToString:@"before"]) {
|
|
35
|
+
*out = BGSNetworkEventStageRequestStarted;
|
|
36
|
+
} else if ([wire isEqualToString:@"redirect"]) {
|
|
37
|
+
*out = BGSNetworkEventStageRedirect;
|
|
38
|
+
} else if ([wire isEqualToString:@"error"]) {
|
|
39
|
+
*out = BGSNetworkEventStageRequestErrored;
|
|
40
|
+
} else if ([wire isEqualToString:@"abort"]) {
|
|
41
|
+
*out = BGSNetworkEventStageRequestAborted;
|
|
42
|
+
} else if ([wire isEqualToString:@"timing"]) {
|
|
43
|
+
*out = BGSNetworkEventStageRequestTimingsReceived;
|
|
44
|
+
} else if ([wire isEqualToString:@"websocket"]) {
|
|
45
|
+
*out = BGSNetworkEventStageWebSocket;
|
|
46
|
+
} else {
|
|
47
|
+
return NO;
|
|
48
|
+
}
|
|
49
|
+
return YES;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static NSString *BGSRNBugseeEventType(BGSNetworkEventStage stage) {
|
|
53
|
+
switch (stage) {
|
|
54
|
+
case BGSNetworkEventStageRequestStarted:
|
|
55
|
+
return BugseeNetworkEventBegin;
|
|
56
|
+
case BGSNetworkEventStageRequestAborted:
|
|
57
|
+
return BugseeNetworkEventCancel;
|
|
58
|
+
case BGSNetworkEventStageRequestErrored:
|
|
59
|
+
return BugseeNetworkEventError;
|
|
60
|
+
case BGSNetworkEventStageWebSocket:
|
|
61
|
+
return BugseeWebSocketEventMessage;
|
|
62
|
+
case BGSNetworkEventStageRequestCompleted:
|
|
63
|
+
case BGSNetworkEventStageRedirect:
|
|
64
|
+
case BGSNetworkEventStageRequestTimingsReceived:
|
|
65
|
+
return BugseeNetworkEventComplete;
|
|
66
|
+
}
|
|
67
|
+
return BugseeNetworkEventComplete;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static BOOL BGSRNHeaders(id value, NSDictionary<NSString *, NSString *> *__autoreleasing *out) {
|
|
71
|
+
if (value == nil || value == [NSNull null]) {
|
|
72
|
+
*out = nil;
|
|
73
|
+
return YES;
|
|
74
|
+
}
|
|
75
|
+
if (![value isKindOfClass:[NSDictionary class]]) {
|
|
76
|
+
return NO;
|
|
77
|
+
}
|
|
78
|
+
NSMutableDictionary<NSString *, NSString *> *map = [NSMutableDictionary dictionary];
|
|
79
|
+
for (id key in (NSDictionary *)value) {
|
|
80
|
+
id item = ((NSDictionary *)value)[key];
|
|
81
|
+
if (![key isKindOfClass:[NSString class]] || ![item isKindOfClass:[NSString class]]) {
|
|
82
|
+
return NO;
|
|
83
|
+
}
|
|
84
|
+
map[key] = item;
|
|
85
|
+
}
|
|
86
|
+
*out = map;
|
|
87
|
+
return YES;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
BGSRNNetworkEventOutcome BGSRNRecordNetworkEvent(NSDictionary<NSString *, id> *object,
|
|
91
|
+
BGSRNNetworkEventSubmit submit,
|
|
92
|
+
NSTimeInterval nowMs) {
|
|
93
|
+
NSString *url = BGSRNStringOrNil(object[@"url"]);
|
|
94
|
+
NSString *method = BGSRNStringOrNil(object[@"method"]);
|
|
95
|
+
if (url == nil || method == nil) {
|
|
96
|
+
return BGSRNNetworkEventOutcomeRejected;
|
|
97
|
+
}
|
|
98
|
+
BGSNetworkEventStage stage = BGSNetworkEventStageRequestCompleted;
|
|
99
|
+
if (!BGSRNNetworkStage(object[@"stage"], &stage)) {
|
|
100
|
+
return BGSRNNetworkEventOutcomeRejected;
|
|
101
|
+
}
|
|
102
|
+
if (object[@"id"] != nil && !BGSRNIsStringOrNull(object[@"id"])) {
|
|
103
|
+
return BGSRNNetworkEventOutcomeRejected;
|
|
104
|
+
}
|
|
105
|
+
for (NSString *key in @[@"body", @"statusText", @"errorDescription", @"errorShortMessage", @"redirectedFromURL"]) {
|
|
106
|
+
if (object[key] != nil && !BGSRNIsStringOrNull(object[key])) {
|
|
107
|
+
return BGSRNNetworkEventOutcomeRejected;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (object[@"responseCode"] != nil && object[@"responseCode"] != [NSNull null]
|
|
111
|
+
&& ![object[@"responseCode"] isKindOfClass:[NSNumber class]]) {
|
|
112
|
+
return BGSRNNetworkEventOutcomeRejected;
|
|
113
|
+
}
|
|
114
|
+
NSDictionary<NSString *, NSString *> *headers = nil;
|
|
115
|
+
const BOOL hasHeaders = object[@"headers"] != nil;
|
|
116
|
+
if (hasHeaders && !BGSRNHeaders(object[@"headers"], &headers)) {
|
|
117
|
+
return BGSRNNetworkEventOutcomeRejected;
|
|
118
|
+
}
|
|
119
|
+
if (object[@"error"] != nil && object[@"error"] != [NSNull null]
|
|
120
|
+
&& ![object[@"error"] isKindOfClass:[NSDictionary class]]) {
|
|
121
|
+
return BGSRNNetworkEventOutcomeRejected;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
NSString *eventId = BGSRNStringOrNil(object[@"id"]);
|
|
125
|
+
if (eventId.length == 0) {
|
|
126
|
+
eventId = [NSUUID UUID].UUIDString;
|
|
127
|
+
}
|
|
128
|
+
NSData *body = nil;
|
|
129
|
+
NSString *bodyText = BGSRNStringOrNil(object[@"body"]);
|
|
130
|
+
if (bodyText != nil) {
|
|
131
|
+
body = [bodyText dataUsingEncoding:NSUTF8StringEncoding];
|
|
132
|
+
}
|
|
133
|
+
id errorValue = object[@"error"];
|
|
134
|
+
NSDictionary *error = [errorValue isKindOfClass:[NSDictionary class]] ? errorValue : nil;
|
|
135
|
+
const NSInteger responseCode = (object[@"responseCode"] != nil && object[@"responseCode"] != [NSNull null])
|
|
136
|
+
? [object[@"responseCode"] integerValue]
|
|
137
|
+
: 0;
|
|
138
|
+
const BugseeNetworkType kind = stage == BGSNetworkEventStageWebSocket ? BugseeWebSocket : BugseeNetwork;
|
|
139
|
+
BugseeNetworkEvent *event = [BugseeNetworkEvent eventWithID:eventId
|
|
140
|
+
HTTPmethod:method
|
|
141
|
+
type:kind
|
|
142
|
+
bugseeEventType:BGSRNBugseeEventType(stage)
|
|
143
|
+
url:url
|
|
144
|
+
redirectedUrl:BGSRNStringOrNil(object[@"redirectedFromURL"])
|
|
145
|
+
body:body
|
|
146
|
+
error:error
|
|
147
|
+
headers:hasHeaders ? headers : nil
|
|
148
|
+
noBodyReason:nil
|
|
149
|
+
dataSize:(int64_t)body.length
|
|
150
|
+
responseCode:responseCode];
|
|
151
|
+
if (event == nil) {
|
|
152
|
+
return BGSRNNetworkEventOutcomeNoEvent;
|
|
153
|
+
}
|
|
154
|
+
event.mechanism = BGSRNNetworkEventMechanism;
|
|
155
|
+
event.timestamp = nowMs;
|
|
156
|
+
// Filtering is required. The one-argument addNetworkEvent: passes NO.
|
|
157
|
+
submit(event, YES);
|
|
158
|
+
return BGSRNNetworkEventOutcomeAdded;
|
|
159
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#import "BGSRNNetworkFilter.h"
|
|
2
|
+
|
|
3
|
+
static id BGSRNJSONOrNull(id value) {
|
|
4
|
+
return value == nil ? [NSNull null] : value;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
NSString *BGSRNNetworkEventJSON(BugseeNetworkEvent *event) {
|
|
8
|
+
const BOOL websocket = event.type == BugseeWebSocket;
|
|
9
|
+
const BOOL udp = event.type == BugseeUDPSocket;
|
|
10
|
+
NSString *stage = websocket ? @"websocket"
|
|
11
|
+
: udp ? @"udpsocket"
|
|
12
|
+
: event.bugseeNetworkEventType;
|
|
13
|
+
NSString *websocketEvent = websocket ? event.bugseeNetworkEventType : nil;
|
|
14
|
+
NSMutableDictionary *headers = nil;
|
|
15
|
+
if ([event.headers isKindOfClass:[NSDictionary class]]) {
|
|
16
|
+
headers = [NSMutableDictionary dictionary];
|
|
17
|
+
[event.headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
|
|
18
|
+
if ([key isKindOfClass:[NSString class]] && [obj isKindOfClass:[NSString class]]) {
|
|
19
|
+
headers[key] = obj;
|
|
20
|
+
}
|
|
21
|
+
}];
|
|
22
|
+
}
|
|
23
|
+
NSMutableDictionary *payload = [@{
|
|
24
|
+
@"id" : BGSRNJSONOrNull(event.ID),
|
|
25
|
+
@"url" : BGSRNJSONOrNull(event.url),
|
|
26
|
+
@"method" : BGSRNJSONOrNull(event.method),
|
|
27
|
+
@"headers" : headers != nil ? headers : [NSNull null],
|
|
28
|
+
@"mechanism" : BGSRNJSONOrNull(event.mechanism),
|
|
29
|
+
@"type" : BGSRNJSONOrNull(stage),
|
|
30
|
+
@"websocketEvent" : BGSRNJSONOrNull(websocketEvent),
|
|
31
|
+
@"responseCode" : @(event.responseCode),
|
|
32
|
+
@"redirectedFromURL" : BGSRNJSONOrNull(event.redirectedFromURL),
|
|
33
|
+
@"error" : BGSRNJSONOrNull(event.error),
|
|
34
|
+
} mutableCopy];
|
|
35
|
+
// Non-empty bytes that are not UTF-8 stay off the snapshot. JSON null is
|
|
36
|
+
// only for a body that is actually nil or empty; a present null is a clear.
|
|
37
|
+
if (event.body.length > 0) {
|
|
38
|
+
NSString *text = [[NSString alloc] initWithData:event.body encoding:NSUTF8StringEncoding];
|
|
39
|
+
if (text != nil) {
|
|
40
|
+
payload[@"body"] = text;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
payload[@"body"] = [NSNull null];
|
|
44
|
+
}
|
|
45
|
+
NSData *data = [NSJSONSerialization dataWithJSONObject:payload options:0 error:nil];
|
|
46
|
+
if (data == nil) {
|
|
47
|
+
return nil;
|
|
48
|
+
}
|
|
49
|
+
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
BOOL BGSRNApplyNetworkReplacement(BugseeNetworkEvent *event, NSString *eventJson) {
|
|
53
|
+
NSData *data = [eventJson dataUsingEncoding:NSUTF8StringEncoding];
|
|
54
|
+
if (data == nil) {
|
|
55
|
+
return NO;
|
|
56
|
+
}
|
|
57
|
+
id parsed = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
|
|
58
|
+
if (![parsed isKindOfClass:[NSDictionary class]]) {
|
|
59
|
+
return NO;
|
|
60
|
+
}
|
|
61
|
+
NSDictionary *object = parsed;
|
|
62
|
+
if (object[@"url"] != nil) {
|
|
63
|
+
id url = object[@"url"];
|
|
64
|
+
if (url == [NSNull null]) {
|
|
65
|
+
event.url = nil;
|
|
66
|
+
if (event.url != nil) {
|
|
67
|
+
return NO;
|
|
68
|
+
}
|
|
69
|
+
} else if ([url isKindOfClass:[NSString class]]) {
|
|
70
|
+
event.url = url;
|
|
71
|
+
if (![event.url isEqualToString:url]) {
|
|
72
|
+
return NO;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
return NO;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (object[@"body"] != nil) {
|
|
79
|
+
id body = object[@"body"];
|
|
80
|
+
if (body == [NSNull null]) {
|
|
81
|
+
event.body = nil;
|
|
82
|
+
if (event.body != nil) {
|
|
83
|
+
return NO;
|
|
84
|
+
}
|
|
85
|
+
} else if ([body isKindOfClass:[NSString class]]) {
|
|
86
|
+
NSData *encoded = [(NSString *)body dataUsingEncoding:NSUTF8StringEncoding];
|
|
87
|
+
event.body = encoded;
|
|
88
|
+
NSString *roundTrip = event.body == nil
|
|
89
|
+
? nil
|
|
90
|
+
: [[NSString alloc] initWithData:event.body encoding:NSUTF8StringEncoding];
|
|
91
|
+
if (![roundTrip isEqualToString:body]) {
|
|
92
|
+
return NO;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
return NO;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (object[@"headers"] != nil) {
|
|
99
|
+
id headers = object[@"headers"];
|
|
100
|
+
if (headers == [NSNull null]) {
|
|
101
|
+
event.headers = nil;
|
|
102
|
+
if (event.headers != nil) {
|
|
103
|
+
return NO;
|
|
104
|
+
}
|
|
105
|
+
} else if ([headers isKindOfClass:[NSDictionary class]]) {
|
|
106
|
+
NSMutableDictionary *map = [NSMutableDictionary dictionary];
|
|
107
|
+
for (id key in (NSDictionary *)headers) {
|
|
108
|
+
id value = ((NSDictionary *)headers)[key];
|
|
109
|
+
if (![key isKindOfClass:[NSString class]] || ![value isKindOfClass:[NSString class]]) {
|
|
110
|
+
return NO;
|
|
111
|
+
}
|
|
112
|
+
map[key] = value;
|
|
113
|
+
}
|
|
114
|
+
event.headers = map;
|
|
115
|
+
if (![event.headers isEqualToDictionary:map]) {
|
|
116
|
+
return NO;
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
return NO;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (object[@"redirectedFromURL"] != nil) {
|
|
123
|
+
id redirected = object[@"redirectedFromURL"];
|
|
124
|
+
if (redirected == [NSNull null]) {
|
|
125
|
+
event.redirectedFromURL = nil;
|
|
126
|
+
if (event.redirectedFromURL != nil) {
|
|
127
|
+
return NO;
|
|
128
|
+
}
|
|
129
|
+
} else if ([redirected isKindOfClass:[NSString class]]) {
|
|
130
|
+
event.redirectedFromURL = redirected;
|
|
131
|
+
if (![event.redirectedFromURL isEqualToString:redirected]) {
|
|
132
|
+
return NO;
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
return NO;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (object[@"error"] != nil) {
|
|
139
|
+
id error = object[@"error"];
|
|
140
|
+
if (error == [NSNull null]) {
|
|
141
|
+
event.error = nil;
|
|
142
|
+
if (event.error != nil) {
|
|
143
|
+
return NO;
|
|
144
|
+
}
|
|
145
|
+
} else if ([error isKindOfClass:[NSDictionary class]]) {
|
|
146
|
+
event.error = error;
|
|
147
|
+
if (![event.error isEqualToDictionary:error]) {
|
|
148
|
+
return NO;
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
return NO;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return YES;
|
|
155
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#import "include/BGSRNPluginEndpoint.h"
|
|
2
|
+
|
|
3
|
+
NSString *const BGSRNPluginEndpointInfoKey = @"BugseeReactNativeEndpoint";
|
|
4
|
+
|
|
5
|
+
/// The iOS SDK's endpoint option key (src/options/endpoint.ts, IOS_ENDPOINT_KEY).
|
|
6
|
+
static NSString *const BGSRNEndpointOptionKey = @"endpoint";
|
|
7
|
+
|
|
8
|
+
NSDictionary *BGSRNOptionsWithPluginEndpoint(NSDictionary *_Nullable options, id _Nullable configured) {
|
|
9
|
+
NSDictionary *given = options ?: @{};
|
|
10
|
+
if (![configured isKindOfClass:[NSString class]] || given[BGSRNEndpointOptionKey] != nil) {
|
|
11
|
+
return given;
|
|
12
|
+
}
|
|
13
|
+
NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
|
|
14
|
+
NSString *value = [(NSString *)configured stringByTrimmingCharactersInSet:whitespace];
|
|
15
|
+
if (value.length == 0) {
|
|
16
|
+
return given;
|
|
17
|
+
}
|
|
18
|
+
NSMutableDictionary *result = [given mutableCopy];
|
|
19
|
+
result[BGSRNEndpointOptionKey] = value;
|
|
20
|
+
return [result copy];
|
|
21
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#import "BGSRNReactRootOriginTracker.h"
|
|
2
|
+
|
|
3
|
+
const NSTimeInterval BGSRNReactRootSearchMinInterval = 0.5;
|
|
4
|
+
|
|
5
|
+
@implementation BGSRNReactRootOriginTracker {
|
|
6
|
+
UIView *_Nullable (^_findRoot)(void);
|
|
7
|
+
NSValue *_Nullable (^_readOrigin)(UIWindow *window);
|
|
8
|
+
NSTimeInterval (^_clock)(void);
|
|
9
|
+
/// The React root found last. Weak: a reload replaces it, and the tracker
|
|
10
|
+
/// must not keep the old one alive.
|
|
11
|
+
__weak UIView *_root;
|
|
12
|
+
BOOL _hasSearched;
|
|
13
|
+
NSTimeInterval _lastSearch;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
- (instancetype)initWithFindRoot:(UIView *_Nullable (^)(void))findRoot
|
|
17
|
+
readOrigin:(NSValue *_Nullable (^)(UIWindow *window))readOrigin
|
|
18
|
+
clock:(NSTimeInterval (^)(void))clock {
|
|
19
|
+
self = [super init];
|
|
20
|
+
if (self) {
|
|
21
|
+
_findRoot = [findRoot copy];
|
|
22
|
+
_readOrigin = [readOrigin copy];
|
|
23
|
+
_clock = [clock copy];
|
|
24
|
+
}
|
|
25
|
+
return self;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (NSValue *)origin {
|
|
29
|
+
return [self originSearchingAtOnce:NO];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
- (NSValue *)originFindingTheRoot {
|
|
33
|
+
return [self originSearchingAtOnce:YES];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
- (NSValue *)originSearchingAtOnce:(BOOL)atOnce {
|
|
37
|
+
@try {
|
|
38
|
+
UIView *root = _root;
|
|
39
|
+
if (root.window == nil && [self claimSearch:atOnce]) {
|
|
40
|
+
root = _findRoot();
|
|
41
|
+
_root = root;
|
|
42
|
+
}
|
|
43
|
+
UIWindow *window = [root isKindOfClass:UIWindow.class] ? (UIWindow *)root : root.window;
|
|
44
|
+
return window == nil ? nil : _readOrigin(window);
|
|
45
|
+
} @catch (NSException *exception) {
|
|
46
|
+
NSLog(@"BugseeRN secure origin lookup threw: %@", NSStringFromClass(exception.class));
|
|
47
|
+
return nil;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Whether a search may run now: always at once, else not within
|
|
52
|
+
/// `BGSRNReactRootSearchMinInterval` of the last one.
|
|
53
|
+
- (BOOL)claimSearch:(BOOL)atOnce {
|
|
54
|
+
const NSTimeInterval now = _clock();
|
|
55
|
+
if (!atOnce && _hasSearched && now - _lastSearch < BGSRNReactRootSearchMinInterval) {
|
|
56
|
+
return NO;
|
|
57
|
+
}
|
|
58
|
+
_hasSearched = YES;
|
|
59
|
+
_lastSearch = now;
|
|
60
|
+
return YES;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@end
|