Skip to content

Commit 8288b8f

Browse files
huntiefacebook-github-bot
authored andcommitted
Bootstrap Fusebox NetworkReporter API
Summary: Bootstraps the `NetworkReporter` API and `jsinspector_network` library. This will form the common C++ logic for Network Inspection in React Native DevTools. Changelog: [Internal] Differential Revision: D70554862
1 parent a1ed5f9 commit 8288b8f

File tree

11 files changed

+259
-62
lines changed

11 files changed

+259
-62
lines changed

packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ add_react_common_subdir(jsi)
7070
add_react_common_subdir(callinvoker)
7171
add_react_common_subdir(oscompat)
7272
add_react_common_subdir(jsinspector-modern)
73+
add_react_common_subdir(jsinspector-modern/network)
7374
add_react_common_subdir(jsinspector-modern/tracing)
7475
add_react_common_subdir(hermes/executor)
7576
add_react_common_subdir(hermes/inspector-modern)
@@ -167,6 +168,7 @@ add_library(reactnative
167168
$<TARGET_OBJECTS:jserrorhandler>
168169
$<TARGET_OBJECTS:jsinspector>
169170
$<TARGET_OBJECTS:jsitooling>
171+
$<TARGET_OBJECTS:jsinspector_network>
170172
$<TARGET_OBJECTS:jsinspector_tracing>
171173
$<TARGET_OBJECTS:jsireact>
172174
$<TARGET_OBJECTS:logger>
@@ -254,6 +256,7 @@ target_include_directories(reactnative
254256
$<TARGET_PROPERTY:glog_init,INTERFACE_INCLUDE_DIRECTORIES>
255257
$<TARGET_PROPERTY:jserrorhandler,INTERFACE_INCLUDE_DIRECTORIES>
256258
$<TARGET_PROPERTY:jsinspector,INTERFACE_INCLUDE_DIRECTORIES>
259+
$<TARGET_PROPERTY:jsinspector_network,INTERFACE_INCLUDE_DIRECTORIES>
257260
$<TARGET_PROPERTY:jsinspector_tracing,INTERFACE_INCLUDE_DIRECTORIES>
258261
$<TARGET_PROPERTY:jsireact,INTERFACE_INCLUDE_DIRECTORIES>
259262
$<TARGET_PROPERTY:mapbufferjni,INTERFACE_INCLUDE_DIRECTORIES>

packages/react-native/ReactCommon/jsinspector-modern/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ target_include_directories(jsinspector PUBLIC ${REACT_COMMON_DIR})
2121
target_link_libraries(jsinspector
2222
folly_runtime
2323
glog
24+
jsinspector_network
2425
jsinspector_tracing
2526
react_featureflags
2627
runtimeexecutor

packages/react-native/ReactCommon/jsinspector-modern/NetworkIOAgent.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
#include "Base64.h"
1212
#include "Utf8.h"
1313

14+
#include <jsinspector-modern/network/NetworkReporter.h>
15+
16+
#include <sstream>
1417
#include <utility>
18+
#include <variant>
1519

1620
namespace facebook::react::jsinspector_modern {
1721

@@ -267,7 +271,16 @@ bool NetworkIOAgent::handleRequest(
267271
}
268272

269273
if (InspectorFlags::getInstance().getNetworkInspectionEnabled()) {
274+
// @cdp Network.enable support is experimental.
270275
if (req.method == "Network.enable") {
276+
NetworkReporter::getInstance().enableDebugging();
277+
frontendChannel_(cdp::jsonResult(req.id));
278+
return true;
279+
}
280+
281+
// @cdp Network.disable support is experimental.
282+
if (req.method == "Network.disable") {
283+
NetworkReporter::getInstance().disableDebugging();
271284
frontendChannel_(cdp::jsonResult(req.id));
272285
return true;
273286
}

packages/react-native/ReactCommon/jsinspector-modern/NetworkIOAgent.h

-3
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
#include "ScopedExecutor.h"
1313

1414
#include <folly/dynamic.h>
15-
#include <mutex>
16-
#include <sstream>
1715
#include <string>
1816
#include <unordered_map>
1917
#include <utility>
20-
#include <variant>
2118

2219
namespace facebook::react::jsinspector_modern {
2320

packages/react-native/ReactCommon/jsinspector-modern/React-jsinspector.podspec

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Pod::Spec.new do |s|
6464
s.dependency "DoubleConversion"
6565
s.dependency "React-runtimeexecutor", version
6666
s.dependency "React-jsi"
67+
add_dependency(s, "React-jsinspectornetwork", :framework_name => 'jsinspector_modernnetwork')
6768
add_dependency(s, "React-jsinspectortracing", :framework_name => 'jsinspector_moderntracing')
6869
s.dependency "React-perflogger", version
6970
if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
cmake_minimum_required(VERSION 3.13)
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
9+
include(${REACT_ANDROID_DIR}/src/main/jni/first-party/jni-lib-merge/SoMerging-utils.cmake)
10+
11+
add_compile_options(
12+
-fexceptions
13+
-std=c++20
14+
-Wall
15+
-Wpedantic)
16+
17+
file(GLOB jsinspector_network_SRC CONFIGURE_DEPENDS *.cpp)
18+
19+
add_library(jsinspector_network OBJECT ${jsinspector_network_SRC})
20+
target_merge_so(jsinspector_network)
21+
22+
target_include_directories(jsinspector_network PUBLIC ${REACT_COMMON_DIR})
23+
24+
target_link_libraries(jsinspector_network
25+
folly_runtime
26+
glog
27+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "NetworkReporter.h"
9+
10+
#include <glog/logging.h>
11+
12+
namespace facebook::react::jsinspector_modern {
13+
14+
NetworkReporter& NetworkReporter::getInstance() {
15+
static NetworkReporter tracer;
16+
return tracer;
17+
}
18+
19+
bool NetworkReporter::enableDebugging() {
20+
std::lock_guard lock(mutex_);
21+
if (enabled_) {
22+
return false;
23+
}
24+
25+
enabled_ = true;
26+
LOG(INFO) << "Network debugging enabled" << std::endl;
27+
return true;
28+
}
29+
30+
bool NetworkReporter::disableDebugging() {
31+
std::lock_guard lock(mutex_);
32+
if (!enabled_) {
33+
return false;
34+
}
35+
36+
enabled_ = false;
37+
LOG(INFO) << "Network debugging disabled" << std::endl;
38+
return true;
39+
}
40+
41+
} // namespace facebook::react::jsinspector_modern
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <mutex>
11+
12+
namespace facebook::react::jsinspector_modern {
13+
14+
/**
15+
* [Experimental] An interface for reporting network events to the modern
16+
* debugger server and Web Performance APIs.
17+
*/
18+
class NetworkReporter {
19+
public:
20+
static NetworkReporter& getInstance();
21+
22+
/**
23+
* Enable network tracking over CDP. Once enabled, network events will be
24+
* sent to the debugger client. Returns `false` if already enabled.
25+
*
26+
* Corresponds to @cdp `Network.enable`.
27+
*/
28+
bool enableDebugging();
29+
30+
/**
31+
* Disable network tracking over CDP, preventing network events from being
32+
* sent to the debugger client. Returns `false` if not initially enabled.
33+
*
34+
* Corresponds to @cdp `Network.disable`.
35+
*/
36+
bool disableDebugging();
37+
38+
private:
39+
NetworkReporter() = default;
40+
NetworkReporter(const NetworkReporter&) = delete;
41+
NetworkReporter& operator=(const NetworkReporter&) = delete;
42+
~NetworkReporter() = default;
43+
44+
bool enabled_{false};
45+
std::mutex mutex_;
46+
};
47+
48+
} // namespace facebook::react::jsinspector_modern
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
require "json"
7+
8+
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "..", "package.json")))
9+
version = package['version']
10+
11+
source = { :git => 'https://github.com/facebook/react-native.git' }
12+
if version == '1000.0.0'
13+
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
14+
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
15+
else
16+
source[:tag] = "v#{version}"
17+
end
18+
19+
folly_config = get_folly_config()
20+
folly_compiler_flags = folly_config[:compiler_flags]
21+
22+
header_search_paths = [
23+
"\"$(PODS_ROOT)/RCT-Folly\"",
24+
]
25+
26+
if ENV['USE_FRAMEWORKS']
27+
header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../..\""
28+
end
29+
30+
header_dir = 'jsinspector-modern/network'
31+
module_name = "jsinspector_modernnetwork"
32+
33+
Pod::Spec.new do |s|
34+
s.name = "React-jsinspectornetwork"
35+
s.version = version
36+
s.summary = "Network inspection for React Native DevTools"
37+
s.homepage = "https://reactnative.dev/"
38+
s.license = package["license"]
39+
s.author = "Meta Platforms, Inc. and its affiliates"
40+
s.platforms = min_supported_versions
41+
s.source = source
42+
s.source_files = "*.{cpp,h}"
43+
s.header_dir = header_dir
44+
s.compiler_flags = folly_compiler_flags
45+
s.pod_target_xcconfig = {
46+
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
47+
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
48+
"DEFINES_MODULE" => "YES"}
49+
50+
if ENV['USE_FRAMEWORKS']
51+
s.module_name = module_name
52+
s.header_mappings_dir = "../.."
53+
end
54+
55+
s.dependency "glog"
56+
s.dependency "RCT-Folly"
57+
end

packages/react-native/scripts/react_native_pods.rb

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def use_react_native! (
146146
pod 'React-jsiexecutor', :path => "#{prefix}/ReactCommon/jsiexecutor"
147147
pod 'React-jsinspector', :path => "#{prefix}/ReactCommon/jsinspector-modern"
148148
pod 'React-jsitooling', :path => "#{prefix}/ReactCommon/jsitooling"
149+
pod 'React-jsinspectornetwork', :path => "#{prefix}/ReactCommon/jsinspector-modern/network"
149150
pod 'React-jsinspectortracing', :path => "#{prefix}/ReactCommon/jsinspector-modern/tracing"
150151

151152
pod 'React-callinvoker', :path => "#{prefix}/ReactCommon/callinvoker"

0 commit comments

Comments
 (0)