Skip to content

Commit

Permalink
Wire up Fusebox InspectorPackagerConnection
Browse files Browse the repository at this point in the history
Using the same inspector thread initialized in ReactNativeHost, this
change wires up the InspectorPackagerConnectionDelegate to use when
initializatng the InspectorPackagerConnection from ReactCommon and
conditionally sets it for Hermes direct debugging when the appropriate
feature flag is set.
  • Loading branch information
rozele committed Apr 29, 2024
1 parent fe37841 commit d72acd8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
5 changes: 4 additions & 1 deletion vnext/Microsoft.ReactNative/ReactHost/ReactInstanceWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,10 @@ void ReactInstanceWin::InitializeBridgeless() noexcept {

if (devSettings->useDirectDebugger) {
::Microsoft::ReactNative::GetSharedDevManager()->EnsureHermesInspector(
devSettings->sourceBundleHost, devSettings->sourceBundlePort, DebugBundlePath());
devSettings->sourceBundleHost,
devSettings->sourceBundlePort,
DebugBundlePath(),
m_options.HostTargetSettings.InspectorThread);
}

m_jsiRuntimeHolder = std::make_shared<Microsoft::ReactNative::HermesRuntimeHolder>(
Expand Down
28 changes: 21 additions & 7 deletions vnext/Shared/DevSupportManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
#include <Shared/DevSettings.h>

#include <Executors/WebSocketJSExecutor.h>
#include "FuseboxInspectorPackagerConnectionDelegate.h"
#include "PackagerConnection.h"

#include "Unicode.h"
#include "Utilities.h"

#include <Utils/CppWinrtLessExceptions.h>
#include <jsinspector-modern/InspectorFlags.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Security.Cryptography.Core.h>
#include <winrt/Windows.Security.Cryptography.h>
Expand Down Expand Up @@ -257,9 +259,10 @@ void DevSupportManager::StopPollingLiveReload() {
void DevSupportManager::EnsureHermesInspector(
[[maybe_unused]] const std::string &packagerHost,
[[maybe_unused]] const uint16_t packagerPort,
[[maybe_unused]] const std::string &jsBundleName) noexcept {
[[maybe_unused]] const std::string &jsBundleName,
[[maybe_unused]] const std::shared_ptr<Mso::DispatchQueue> &inspectorThread) noexcept {
static std::once_flag once;
std::call_once(once, [this, &packagerHost, packagerPort, &jsBundleName]() {
std::call_once(once, [this, &packagerHost, packagerPort, &jsBundleName, &inspectorThread]() {
// TODO: should we use the bundleAppId as the app param if available?
std::string packageName("RNW");
wchar_t fullName[PACKAGE_FULL_NAME_MAX_LENGTH]{};
Expand All @@ -276,11 +279,22 @@ void DevSupportManager::EnsureHermesInspector(
}

const auto deviceId = GetDeviceId(jsBundleName);
m_inspectorPackagerConnection = std::make_shared<InspectorPackagerConnection>(
facebook::react::DevServerHelper::get_InspectorDeviceUrl(
packagerHost, packagerPort, deviceName, packageName, deviceId),
m_BundleStatusProvider);
m_inspectorPackagerConnection->connectAsync();
auto inspectorUrl = facebook::react::DevServerHelper::get_InspectorDeviceUrl(
packagerHost, packagerPort, deviceName, packageName, deviceId);
auto &inspectorFlags = jsinspector_modern::InspectorFlags::getInstance();
if (inspectorFlags.getEnableCxxInspectorPackagerConnection()) {
m_fuseboxInspectorPackagerConnection = std::make_unique<jsinspector_modern::InspectorPackagerConnection>(
inspectorUrl,
std::string{jsBundleName},
std::make_unique<Microsoft::ReactNative::FuseboxInspectorPackagerConnectionDelegate>(inspectorThread));
m_fuseboxInspectorPackagerConnection->connect();
} else {
m_inspectorPackagerConnection = std::make_shared<InspectorPackagerConnection>(
facebook::react::DevServerHelper::get_InspectorDeviceUrl(
packagerHost, packagerPort, deviceName, packageName, deviceId),
m_BundleStatusProvider);
m_inspectorPackagerConnection->connectAsync();
}
});
}

Expand Down
5 changes: 4 additions & 1 deletion vnext/Shared/DevSupportManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string>

#include <InspectorPackagerConnection.h>
#include <jsinspector-modern/InspectorPackagerConnection.h>

namespace facebook {
namespace react {
Expand Down Expand Up @@ -52,13 +53,15 @@ class DevSupportManager final : public facebook::react::IDevSupportManager {
virtual void EnsureHermesInspector(
const std::string &packagerHost,
const uint16_t packagerPort,
const std::string &jsBundleName) noexcept override;
const std::string &jsBundleName,
const std::shared_ptr<Mso::DispatchQueue> &inspectorThread) noexcept override;
virtual void UpdateBundleStatus(bool isLastDownloadSuccess, int64_t updateTimestamp) noexcept override;

private:
std::atomic_bool m_cancellation_token;

std::shared_ptr<InspectorPackagerConnection> m_inspectorPackagerConnection;
std::unique_ptr<facebook::react::jsinspector_modern::InspectorPackagerConnection> m_fuseboxInspectorPackagerConnection;

struct BundleStatusProvider : public InspectorPackagerConnection::IBundleStatusProvider {
virtual InspectorPackagerConnection::BundleStatus getBundleStatus() {
Expand Down
4 changes: 3 additions & 1 deletion vnext/Shared/IDevSupportManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <cxxreact/JSExecutor.h>
#include <dispatchQueue/dispatchQueue.h>
#include <functional>
#include <memory>
#include <string>
Expand All @@ -27,7 +28,8 @@ struct IDevSupportManager {
virtual void EnsureHermesInspector(
const std::string &packagerHost,
const uint16_t packagerPort,
const std::string &bundleName) noexcept = 0;
const std::string &bundleName,
const std::shared_ptr<Mso::DispatchQueue> &inspectorThread) noexcept = 0;
virtual void UpdateBundleStatus(bool isLastDownloadSuccess, int64_t updateTimestamp) noexcept = 0;
};

Expand Down
6 changes: 5 additions & 1 deletion vnext/Shared/OInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ void LoadRemoteUrlScript(

const auto bundlePath = devSettings->debugBundlePath.empty() ? jsBundleRelativePath : devSettings->debugBundlePath;
if (facebook::react::shouldStartHermesInspector(*devSettings)) {
devManager->EnsureHermesInspector(devSettings->sourceBundleHost, devSettings->sourceBundlePort, bundlePath);
devManager->EnsureHermesInspector(
devSettings->sourceBundleHost,
devSettings->sourceBundlePort,
bundlePath,
devSettings->hostTargetSettings.InspectorThread);
}

auto [jsBundleString, success] = GetJavaScriptFromServer(
Expand Down

0 comments on commit d72acd8

Please sign in to comment.