16
16
17
17
#include < Utils/CppWinrtLessExceptions.h>
18
18
#include < winrt/Windows.Foundation.h>
19
+ #include < winrt/Windows.Security.Cryptography.Core.h>
20
+ #include < winrt/Windows.Security.Cryptography.h>
19
21
#include < winrt/Windows.Storage.Streams.h>
22
+ #include < winrt/Windows.System.Profile.h>
20
23
#include < winrt/Windows.Web.Http.Filters.h>
21
24
#include < winrt/Windows.Web.Http.Headers.h>
22
25
#include < winrt/Windows.Web.Http.h>
@@ -171,6 +174,33 @@ bool IsIgnorablePollHResult(HRESULT hr) {
171
174
return hr == WININET_E_INVALID_SERVER_RESPONSE;
172
175
}
173
176
177
+ std::string GetDeviceId (const std::string &bundleAppId) {
178
+ const auto hash = winrt::Windows::Security::Cryptography::Core::HashAlgorithmProvider::OpenAlgorithm (
179
+ winrt::Windows::Security::Cryptography::Core::HashAlgorithmNames::Sha256 ())
180
+ .CreateHash ();
181
+ hash.Append (winrt::Windows::System::Profile::SystemIdentification::GetSystemIdForPublisher ().Id ());
182
+ winrt::Windows::Storage::Streams::InMemoryRandomAccessStream stream;
183
+ winrt::Windows::Storage::Streams::DataWriter writer;
184
+ // If an app ID is provided, we will allow reconnection to DevTools.
185
+ // Apps must supply a unique app ID to each ReactNativeHost instance settings for this to behave correctly.
186
+ if (!bundleAppId.empty ()) {
187
+ const auto bundleAppIdBuffer = winrt::Windows::Security::Cryptography::CryptographicBuffer::ConvertStringToBinary (
188
+ winrt::to_hstring (bundleAppId), winrt::Windows::Security::Cryptography::BinaryStringEncoding::Utf16BE);
189
+ hash.Append (bundleAppIdBuffer);
190
+ } else {
191
+ const auto processId = GetCurrentProcessId ();
192
+ std::vector<uint8_t > processIdBytes (
193
+ reinterpret_cast <const uint8_t *>(&processId), reinterpret_cast <const uint8_t *>(&processId + 1 ));
194
+ winrt::array_view<uint8_t > processIdByteArray (processIdBytes);
195
+ const auto processIdBuffer =
196
+ winrt::Windows::Security::Cryptography::CryptographicBuffer::CreateFromByteArray (processIdByteArray);
197
+ hash.Append (processIdBuffer);
198
+ }
199
+ const auto hashBuffer = hash.GetValueAndReset ();
200
+ const auto hashString = winrt::Windows::Security::Cryptography::CryptographicBuffer::EncodeToHexString (hashBuffer);
201
+ return winrt::to_string (hashString);
202
+ }
203
+
174
204
std::future<winrt::Windows::Web::Http::HttpStatusCode> PollForLiveReload (const std::string &url) {
175
205
winrt::Windows::Web::Http::HttpClient httpClient;
176
206
winrt::Windows::Foundation::Uri uri (Microsoft::Common::Unicode::Utf8ToUtf16 (url));
@@ -240,16 +270,21 @@ void DevSupportManager::StopPollingLiveReload() {
240
270
241
271
void DevSupportManager::EnsureHermesInspector (
242
272
[[maybe_unused]] const std::string &packagerHost,
243
- [[maybe_unused]] const uint16_t packagerPort) noexcept {
273
+ [[maybe_unused]] const uint16_t packagerPort,
274
+ [[maybe_unused]] const std::string &bundleAppId) noexcept {
244
275
static std::once_flag once;
245
- std::call_once (once, [this , &packagerHost, packagerPort]() {
276
+ std::call_once (once, [this , &packagerHost, packagerPort, &jsBundleName ]() {
246
277
// TODO: should we use the bundleAppId as the app param if available?
247
- std::string packageName (" RNW" );
248
- wchar_t fullName[PACKAGE_FULL_NAME_MAX_LENGTH]{};
249
- UINT32 size = ARRAYSIZE (fullName);
250
- if (SUCCEEDED (GetCurrentPackageFullName (&size, fullName))) {
251
- // we are in an unpackaged app
252
- packageName = winrt::to_string (fullName);
278
+
279
+ std::string packageName{bundleAppId};
280
+ if (packageName == " " ) {
281
+ std::string packageName (" RNW" );
282
+ wchar_t fullName[PACKAGE_FULL_NAME_MAX_LENGTH]{};
283
+ UINT32 size = ARRAYSIZE (fullName);
284
+ if (SUCCEEDED (GetCurrentPackageFullName (&size, fullName))) {
285
+ // we are in an unpackaged app
286
+ packageName = winrt::to_string (fullName);
287
+ }
253
288
}
254
289
255
290
std::string deviceName (" RNWHost" );
@@ -258,8 +293,10 @@ void DevSupportManager::EnsureHermesInspector(
258
293
deviceName = winrt::to_string (hostNames.First ().Current ().DisplayName ());
259
294
}
260
295
296
+ const auto deviceId = GetDeviceId (packageName);
261
297
m_inspectorPackagerConnection = std::make_shared<InspectorPackagerConnection>(
262
- facebook::react::DevServerHelper::get_InspectorDeviceUrl (packagerHost, packagerPort, deviceName, packageName),
298
+ facebook::react::DevServerHelper::get_InspectorDeviceUrl (
299
+ packagerHost, packagerPort, deviceName, packageName, deviceId),
263
300
m_BundleStatusProvider);
264
301
m_inspectorPackagerConnection->connectAsync ();
265
302
});
0 commit comments