yeet
This commit is contained in:
32
node_modules/react-native/React/Inspector/RCTInspector.h
generated
vendored
Normal file
32
node_modules/react-native/React/Inspector/RCTInspector.h
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <React/RCTDefines.h>
|
||||
|
||||
#if RCT_DEV
|
||||
|
||||
@class RCTInspectorRemoteConnection;
|
||||
|
||||
@interface RCTInspectorLocalConnection : NSObject
|
||||
- (void)sendMessage:(NSString *)message;
|
||||
- (void)disconnect;
|
||||
@end
|
||||
|
||||
@interface RCTInspectorPage : NSObject
|
||||
@property (nonatomic, readonly) NSInteger id;
|
||||
@property (nonatomic, readonly) NSString *title;
|
||||
@property (nonatomic, readonly) NSString *vm;
|
||||
@end
|
||||
|
||||
@interface RCTInspector : NSObject
|
||||
+ (NSArray<RCTInspectorPage *> *)pages;
|
||||
+ (RCTInspectorLocalConnection *)connectPage:(NSInteger)pageId
|
||||
forRemoteConnection:(RCTInspectorRemoteConnection *)remote;
|
||||
@end
|
||||
|
||||
#endif
|
130
node_modules/react-native/React/Inspector/RCTInspector.mm
generated
vendored
Normal file
130
node_modules/react-native/React/Inspector/RCTInspector.mm
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <React/RCTInspector.h>
|
||||
|
||||
#if RCT_DEV
|
||||
|
||||
#include <jsinspector/InspectorInterfaces.h>
|
||||
|
||||
#import <React/RCTDefines.h>
|
||||
#import <React/RCTInspectorPackagerConnection.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTSRWebSocket.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
// This is a port of the Android impl, at
|
||||
// react-native-github/ReactAndroid/src/main/java/com/facebook/react/bridge/Inspector.java
|
||||
// react-native-github/ReactAndroid/src/main/jni/react/jni/JInspector.cpp
|
||||
// please keep consistent :)
|
||||
|
||||
class RemoteConnection : public IRemoteConnection {
|
||||
public:
|
||||
RemoteConnection(RCTInspectorRemoteConnection *connection) : _connection(connection) {}
|
||||
|
||||
virtual void onMessage(std::string message) override
|
||||
{
|
||||
[_connection onMessage:@(message.c_str())];
|
||||
}
|
||||
|
||||
virtual void onDisconnect() override
|
||||
{
|
||||
[_connection onDisconnect];
|
||||
}
|
||||
|
||||
private:
|
||||
const RCTInspectorRemoteConnection *_connection;
|
||||
};
|
||||
|
||||
@interface RCTInspectorPage () {
|
||||
NSInteger _id;
|
||||
NSString *_title;
|
||||
NSString *_vm;
|
||||
}
|
||||
- (instancetype)initWithId:(NSInteger)id title:(NSString *)title vm:(NSString *)vm;
|
||||
@end
|
||||
|
||||
@interface RCTInspectorLocalConnection () {
|
||||
std::unique_ptr<ILocalConnection> _connection;
|
||||
}
|
||||
- (instancetype)initWithConnection:(std::unique_ptr<ILocalConnection>)connection;
|
||||
@end
|
||||
|
||||
static IInspector *getInstance()
|
||||
{
|
||||
return &facebook::react::getInspectorInstance();
|
||||
}
|
||||
|
||||
@implementation RCTInspector
|
||||
|
||||
RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||
|
||||
+ (NSArray<RCTInspectorPage *> *)pages
|
||||
{
|
||||
std::vector<InspectorPage> pages = getInstance()->getPages();
|
||||
NSMutableArray<RCTInspectorPage *> *array = [NSMutableArray arrayWithCapacity:pages.size()];
|
||||
for (size_t i = 0; i < pages.size(); i++) {
|
||||
RCTInspectorPage *pageWrapper = [[RCTInspectorPage alloc] initWithId:pages[i].id
|
||||
title:@(pages[i].title.c_str())
|
||||
vm:@(pages[i].vm.c_str())];
|
||||
[array addObject:pageWrapper];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
+ (RCTInspectorLocalConnection *)connectPage:(NSInteger)pageId
|
||||
forRemoteConnection:(RCTInspectorRemoteConnection *)remote
|
||||
{
|
||||
auto localConnection = getInstance()->connect((int)pageId, std::make_unique<RemoteConnection>(remote));
|
||||
return [[RCTInspectorLocalConnection alloc] initWithConnection:std::move(localConnection)];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTInspectorPage
|
||||
|
||||
RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||
|
||||
- (instancetype)initWithId:(NSInteger)id title:(NSString *)title vm:(NSString *)vm
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_id = id;
|
||||
_title = title;
|
||||
_vm = vm;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTInspectorLocalConnection
|
||||
|
||||
RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||
|
||||
- (instancetype)initWithConnection:(std::unique_ptr<ILocalConnection>)connection
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_connection = std::move(connection);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)sendMessage:(NSString *)message
|
||||
{
|
||||
_connection->sendMessage([message UTF8String]);
|
||||
}
|
||||
|
||||
- (void)disconnect
|
||||
{
|
||||
_connection->disconnect();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
35
node_modules/react-native/React/Inspector/RCTInspectorPackagerConnection.h
generated
vendored
Normal file
35
node_modules/react-native/React/Inspector/RCTInspectorPackagerConnection.h
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <React/RCTDefines.h>
|
||||
|
||||
#if RCT_DEV
|
||||
|
||||
@interface RCTBundleStatus : NSObject
|
||||
@property (atomic, assign) BOOL isLastBundleDownloadSuccess;
|
||||
@property (atomic, assign) NSTimeInterval bundleUpdateTimestamp;
|
||||
@end
|
||||
|
||||
typedef RCTBundleStatus * (^RCTBundleStatusProvider)(void);
|
||||
|
||||
@interface RCTInspectorPackagerConnection : NSObject
|
||||
- (instancetype)initWithURL:(NSURL *)url;
|
||||
|
||||
- (bool)isConnected;
|
||||
- (void)connect;
|
||||
- (void)closeQuietly;
|
||||
- (void)sendEventToAllConnections:(NSString *)event;
|
||||
- (void)setBundleStatusProvider:(RCTBundleStatusProvider)bundleStatusProvider;
|
||||
@end
|
||||
|
||||
@interface RCTInspectorRemoteConnection : NSObject
|
||||
- (void)onMessage:(NSString *)message;
|
||||
- (void)onDisconnect;
|
||||
@end
|
||||
|
||||
#endif
|
351
node_modules/react-native/React/Inspector/RCTInspectorPackagerConnection.m
generated
vendored
Normal file
351
node_modules/react-native/React/Inspector/RCTInspectorPackagerConnection.m
generated
vendored
Normal file
@ -0,0 +1,351 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <React/RCTInspectorPackagerConnection.h>
|
||||
|
||||
#if RCT_DEV
|
||||
|
||||
#import <React/RCTDefines.h>
|
||||
#import <React/RCTInspector.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTSRWebSocket.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
// This is a port of the Android impl, at
|
||||
// ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorPackagerConnection.java
|
||||
// please keep consistent :)
|
||||
|
||||
const int RECONNECT_DELAY_MS = 2000;
|
||||
|
||||
@implementation RCTBundleStatus
|
||||
@end
|
||||
|
||||
@interface RCTInspectorPackagerConnection () <RCTSRWebSocketDelegate> {
|
||||
NSURL *_url;
|
||||
NSMutableDictionary<NSString *, RCTInspectorLocalConnection *> *_inspectorConnections;
|
||||
RCTSRWebSocket *_webSocket;
|
||||
dispatch_queue_t _jsQueue;
|
||||
BOOL _closed;
|
||||
BOOL _suppressConnectionErrors;
|
||||
RCTBundleStatusProvider _bundleStatusProvider;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface RCTInspectorRemoteConnection () {
|
||||
__weak RCTInspectorPackagerConnection *_owningPackagerConnection;
|
||||
NSString *_pageId;
|
||||
}
|
||||
- (instancetype)initWithPackagerConnection:(RCTInspectorPackagerConnection *)owningPackagerConnection
|
||||
pageId:(NSString *)pageId;
|
||||
@end
|
||||
|
||||
static NSDictionary<NSString *, id> *makePageIdPayload(NSString *pageId)
|
||||
{
|
||||
return @{@"pageId" : pageId};
|
||||
}
|
||||
|
||||
@implementation RCTInspectorPackagerConnection
|
||||
|
||||
RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)url
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_url = url;
|
||||
_inspectorConnections = [NSMutableDictionary new];
|
||||
_jsQueue = dispatch_queue_create("com.facebook.react.WebSocketExecutor", DISPATCH_QUEUE_SERIAL);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setBundleStatusProvider:(RCTBundleStatusProvider)bundleStatusProvider
|
||||
{
|
||||
_bundleStatusProvider = bundleStatusProvider;
|
||||
}
|
||||
|
||||
- (void)handleProxyMessage:(NSDictionary<NSString *, id> *)message
|
||||
{
|
||||
NSString *event = message[@"event"];
|
||||
NSDictionary *payload = message[@"payload"];
|
||||
if ([@"getPages" isEqualToString:event]) {
|
||||
[self sendEvent:event payload:[self pages]];
|
||||
} else if ([@"wrappedEvent" isEqualToString:event]) {
|
||||
[self handleWrappedEvent:payload];
|
||||
} else if ([@"connect" isEqualToString:event]) {
|
||||
[self handleConnect:payload];
|
||||
} else if ([@"disconnect" isEqualToString:event]) {
|
||||
[self handleDisconnect:payload];
|
||||
} else {
|
||||
RCTLogError(@"Unknown event: %@", event);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sendEventToAllConnections:(NSString *)event
|
||||
{
|
||||
for (NSString *pageId in _inspectorConnections) {
|
||||
[_inspectorConnections[pageId] sendMessage:event];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)closeAllConnections
|
||||
{
|
||||
for (NSString *pageId in _inspectorConnections) {
|
||||
[[_inspectorConnections objectForKey:pageId] disconnect];
|
||||
}
|
||||
[_inspectorConnections removeAllObjects];
|
||||
}
|
||||
|
||||
- (void)handleConnect:(NSDictionary *)payload
|
||||
{
|
||||
NSString *pageId = payload[@"pageId"];
|
||||
RCTInspectorLocalConnection *existingConnection = _inspectorConnections[pageId];
|
||||
if (existingConnection) {
|
||||
[_inspectorConnections removeObjectForKey:pageId];
|
||||
[existingConnection disconnect];
|
||||
RCTLogWarn(@"Already connected: %@", pageId);
|
||||
return;
|
||||
}
|
||||
|
||||
RCTInspectorRemoteConnection *remoteConnection =
|
||||
[[RCTInspectorRemoteConnection alloc] initWithPackagerConnection:self pageId:pageId];
|
||||
|
||||
RCTInspectorLocalConnection *inspectorConnection = [RCTInspector connectPage:[pageId integerValue]
|
||||
forRemoteConnection:remoteConnection];
|
||||
_inspectorConnections[pageId] = inspectorConnection;
|
||||
}
|
||||
|
||||
- (void)handleDisconnect:(NSDictionary *)payload
|
||||
{
|
||||
NSString *pageId = payload[@"pageId"];
|
||||
RCTInspectorLocalConnection *inspectorConnection = _inspectorConnections[pageId];
|
||||
if (inspectorConnection) {
|
||||
[self removeConnectionForPage:pageId];
|
||||
[inspectorConnection disconnect];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeConnectionForPage:(NSString *)pageId
|
||||
{
|
||||
[_inspectorConnections removeObjectForKey:pageId];
|
||||
}
|
||||
|
||||
- (void)handleWrappedEvent:(NSDictionary *)payload
|
||||
{
|
||||
NSString *pageId = payload[@"pageId"];
|
||||
NSString *wrappedEvent = payload[@"wrappedEvent"];
|
||||
RCTInspectorLocalConnection *inspectorConnection = _inspectorConnections[pageId];
|
||||
if (!inspectorConnection) {
|
||||
RCTLogWarn(@"Not connected to page: %@ , failed trying to handle event: %@", pageId, wrappedEvent);
|
||||
return;
|
||||
}
|
||||
[inspectorConnection sendMessage:wrappedEvent];
|
||||
}
|
||||
|
||||
- (NSArray *)pages
|
||||
{
|
||||
NSArray<RCTInspectorPage *> *pages = [RCTInspector pages];
|
||||
NSMutableArray *array = [NSMutableArray arrayWithCapacity:pages.count];
|
||||
|
||||
RCTBundleStatusProvider statusProvider = _bundleStatusProvider;
|
||||
RCTBundleStatus *bundleStatus = statusProvider == nil ? nil : statusProvider();
|
||||
|
||||
for (RCTInspectorPage *page in pages) {
|
||||
NSDictionary *jsonPage = @{
|
||||
@"id" : [@(page.id) stringValue],
|
||||
@"title" : page.title,
|
||||
@"app" : [[NSBundle mainBundle] bundleIdentifier],
|
||||
@"vm" : page.vm,
|
||||
@"isLastBundleDownloadSuccess" : bundleStatus == nil ? [NSNull null]
|
||||
: @(bundleStatus.isLastBundleDownloadSuccess),
|
||||
@"bundleUpdateTimestamp" : bundleStatus == nil ? [NSNull null]
|
||||
: @((long)bundleStatus.bundleUpdateTimestamp * 1000),
|
||||
};
|
||||
[array addObject:jsonPage];
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
- (void)sendWrappedEvent:(NSString *)pageId message:(NSString *)message
|
||||
{
|
||||
NSDictionary *payload = @{
|
||||
@"pageId" : pageId,
|
||||
@"wrappedEvent" : message,
|
||||
};
|
||||
[self sendEvent:@"wrappedEvent" payload:payload];
|
||||
}
|
||||
|
||||
- (void)sendEvent:(NSString *)name payload:(id)payload
|
||||
{
|
||||
NSDictionary *jsonMessage = @{
|
||||
@"event" : name,
|
||||
@"payload" : payload,
|
||||
};
|
||||
[self sendToPackager:jsonMessage];
|
||||
}
|
||||
|
||||
// analogous to InspectorPackagerConnection.Connection.onFailure(...)
|
||||
- (void)webSocket:(__unused RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error
|
||||
{
|
||||
if (_webSocket) {
|
||||
[self abort:@"Websocket exception" withCause:error];
|
||||
}
|
||||
if (!_closed && [error code] != ECONNREFUSED) {
|
||||
[self reconnect];
|
||||
}
|
||||
}
|
||||
|
||||
// analogous to InspectorPackagerConnection.Connection.onMessage(...)
|
||||
- (void)webSocket:(__unused RCTSRWebSocket *)webSocket didReceiveMessage:(id)opaqueMessage
|
||||
{
|
||||
// warn but don't die on unrecognized messages
|
||||
if (![opaqueMessage isKindOfClass:[NSString class]]) {
|
||||
RCTLogWarn(@"Unrecognized inspector message, object is of type: %@", [opaqueMessage class]);
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *messageText = opaqueMessage;
|
||||
NSError *error = nil;
|
||||
id parsedJSON = RCTJSONParse(messageText, &error);
|
||||
if (error) {
|
||||
RCTLogWarn(@"Unrecognized inspector message, string was not valid JSON: %@", messageText);
|
||||
return;
|
||||
}
|
||||
|
||||
[self handleProxyMessage:parsedJSON];
|
||||
}
|
||||
|
||||
// analogous to InspectorPackagerConnection.Connection.onClosed(...)
|
||||
- (void)webSocket:(__unused RCTSRWebSocket *)webSocket
|
||||
didCloseWithCode:(__unused NSInteger)code
|
||||
reason:(__unused NSString *)reason
|
||||
wasClean:(__unused BOOL)wasClean
|
||||
{
|
||||
_webSocket = nil;
|
||||
[self closeAllConnections];
|
||||
if (!_closed) {
|
||||
[self reconnect];
|
||||
}
|
||||
}
|
||||
|
||||
- (bool)isConnected
|
||||
{
|
||||
return _webSocket != nil;
|
||||
}
|
||||
|
||||
- (void)connect
|
||||
{
|
||||
if (_closed) {
|
||||
RCTLogError(@"Illegal state: Can't connect after having previously been closed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// The corresponding android code has a lot of custom config options for
|
||||
// timeouts, but it appears the iOS RCTSRWebSocket API doesn't have the same
|
||||
// implemented options.
|
||||
_webSocket = [[RCTSRWebSocket alloc] initWithURL:_url];
|
||||
[_webSocket setDelegateDispatchQueue:_jsQueue];
|
||||
_webSocket.delegate = self;
|
||||
[_webSocket open];
|
||||
}
|
||||
|
||||
- (void)reconnect
|
||||
{
|
||||
if (_closed) {
|
||||
RCTLogError(@"Illegal state: Can't reconnect after having previously been closed.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_suppressConnectionErrors) {
|
||||
RCTLogWarn(@"Couldn't connect to packager, will silently retry");
|
||||
_suppressConnectionErrors = true;
|
||||
}
|
||||
|
||||
__weak RCTInspectorPackagerConnection *weakSelf = self;
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, RECONNECT_DELAY_MS * NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
|
||||
RCTInspectorPackagerConnection *strongSelf = weakSelf;
|
||||
if (strongSelf && !strongSelf->_closed) {
|
||||
[strongSelf connect];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)closeQuietly
|
||||
{
|
||||
_closed = true;
|
||||
[self disposeWebSocket];
|
||||
}
|
||||
|
||||
- (void)sendToPackager:(NSDictionary *)messageObject
|
||||
{
|
||||
__weak RCTInspectorPackagerConnection *weakSelf = self;
|
||||
dispatch_async(_jsQueue, ^{
|
||||
RCTInspectorPackagerConnection *strongSelf = weakSelf;
|
||||
if (strongSelf && !strongSelf->_closed) {
|
||||
NSError *error;
|
||||
NSString *messageText = RCTJSONStringify(messageObject, &error);
|
||||
if (error) {
|
||||
RCTLogWarn(@"Couldn't send event to packager: %@", error);
|
||||
} else {
|
||||
[strongSelf->_webSocket send:messageText];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)abort:(NSString *)message withCause:(NSError *)cause
|
||||
{
|
||||
// Don't log ECONNREFUSED at all; it's expected in cases where the server isn't listening.
|
||||
if (![cause.domain isEqual:NSPOSIXErrorDomain] || cause.code != ECONNREFUSED) {
|
||||
RCTLogInfo(@"Error occurred, shutting down websocket connection: %@ %@", message, cause);
|
||||
}
|
||||
|
||||
[self closeAllConnections];
|
||||
[self disposeWebSocket];
|
||||
}
|
||||
|
||||
- (void)disposeWebSocket
|
||||
{
|
||||
if (_webSocket) {
|
||||
[_webSocket closeWithCode:1000 reason:@"End of session"];
|
||||
_webSocket.delegate = nil;
|
||||
_webSocket = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTInspectorRemoteConnection
|
||||
|
||||
RCT_NOT_IMPLEMENTED(-(instancetype)init)
|
||||
|
||||
- (instancetype)initWithPackagerConnection:(RCTInspectorPackagerConnection *)owningPackagerConnection
|
||||
pageId:(NSString *)pageId
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_owningPackagerConnection = owningPackagerConnection;
|
||||
_pageId = pageId;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)onMessage:(NSString *)message
|
||||
{
|
||||
[_owningPackagerConnection sendWrappedEvent:_pageId message:message];
|
||||
}
|
||||
|
||||
- (void)onDisconnect
|
||||
{
|
||||
RCTInspectorPackagerConnection *owningPackagerConnectionStrong = _owningPackagerConnection;
|
||||
if (owningPackagerConnectionStrong) {
|
||||
[owningPackagerConnectionStrong removeConnectionForPage:_pageId];
|
||||
[owningPackagerConnectionStrong sendEvent:@"disconnect" payload:makePageIdPayload(_pageId)];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user