forked from microsoft/react-native-windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevServerHelper.h
More file actions
129 lines (110 loc) · 5.18 KB
/
Copy pathDevServerHelper.h
File metadata and controls
129 lines (110 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include <cxxreact/JSExecutor.h>
#include "Utils.h"
namespace facebook {
namespace react {
class DevServerHelper {
public:
DevServerHelper() = default;
static std::string get_WebsocketProxyUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
return Microsoft::React::FormatString(
WebsocketProxyUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}
static std::string get_LaunchDevToolsCommandUrl(
const std::string &sourceBundleHost,
const uint16_t sourceBundlePort) {
return Microsoft::React::FormatString(
LaunchDevToolsCommandUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}
static std::string get_BundleUrl(
const std::string &sourceBundleHost,
const uint16_t sourceBundlePort,
const std::string &jsbundle,
const std::string &platform,
const std::string &bundleAppId,
bool dev,
bool hot,
bool inlineSourceMap,
const uint32_t hermesBytecodeVersion) {
std::string hermesBytecodeVersionQuery;
if (hermesBytecodeVersion > 0) {
static constexpr const char HermesBytecodeVersionQueryFormat[] = "&runtimeBytecodeVersion=%d";
hermesBytecodeVersionQuery =
Microsoft::React::FormatString(HermesBytecodeVersionQueryFormat, hermesBytecodeVersion);
}
std::string appIdQuery;
if (bundleAppId.size() > 0) {
static constexpr const char AppIdQueryFormat[] = "&app=%s";
appIdQuery = Microsoft::React::FormatString(AppIdQueryFormat, bundleAppId.c_str());
}
return Microsoft::React::FormatString(
BundleUrlFormat,
GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str(),
jsbundle.c_str(),
platform.c_str(),
dev ? "true" : "false",
hot ? "true" : "false",
inlineSourceMap ? "true" : "false",
hermesBytecodeVersionQuery.c_str(),
appIdQuery.c_str());
}
static std::string get_OnChangeEndpointUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
return Microsoft::React::FormatString(
OnChangeEndpointUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}
static std::string get_PackagerConnectionUrl(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
return Microsoft::React::FormatString(
PackagerConnectionUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}
static std::string get_PackagerOpenStackFrameUrl(
const std::string &sourceBundleHost,
const uint16_t sourceBundlePort) {
return Microsoft::React::FormatString(
PackagerOpenStackFrameUrlFormat, GetDeviceLocalHost(sourceBundleHost, sourceBundlePort).c_str());
}
static std::string get_InspectorDeviceUrl(
const std::string &packagerHost,
const uint16_t packagerPort,
const std::string &deviceName,
const std::string &packageName,
const std::string &deviceId) {
return Microsoft::React::FormatString(
InspectorDeviceUrlFormat,
GetDeviceLocalHost(packagerHost, packagerPort).c_str(),
deviceName.c_str(),
packageName.c_str(),
deviceId.c_str());
}
static std::string
get_OpenDebuggerUrl(const std::string &packagerHost, const uint16_t packagerPort, const std::string &deviceId) {
return Microsoft::React::FormatString(
OpenDebuggerUrlFormat, GetDeviceLocalHost(packagerHost, packagerPort).c_str(), deviceId.c_str());
}
static constexpr const char DefaultPackagerHost[] = "localhost";
static const uint16_t DefaultPackagerPort = 8081;
private:
static std::string GetDeviceLocalHost(const std::string &sourceBundleHost, const uint16_t sourceBundlePort) {
return Microsoft::React::FormatString(
DeviceLocalHostFormat,
sourceBundleHost.empty() ? DefaultPackagerHost : sourceBundleHost.c_str(),
sourceBundlePort ? sourceBundlePort : DefaultPackagerPort);
}
static constexpr const char DeviceLocalHostFormat[] = "%s:%d";
static constexpr const char BundleUrlFormat[] =
"http://%s/%s.bundle?platform=%s&dev=%s&hot=%s&inlineSourceMap=%s%s%s";
static constexpr const char SourceMapUrlFormat[] = "http://%s/%s.map?platform=%s&dev=%s&hot=%s";
static constexpr const char LaunchDevToolsCommandUrlFormat[] = "http://%s/launch-js-devtools";
static constexpr const char OnChangeEndpointUrlFormat[] = "http://%s/onchange";
static constexpr const char WebsocketProxyUrlFormat[] = "ws://%s/debugger-proxy?role=client";
static constexpr const char PackagerConnectionUrlFormat[] = "ws://%s/message";
static constexpr const char PackagerStatusUrlFormat[] = "http://%s/status";
static constexpr const char PackagerOpenStackFrameUrlFormat[] = "https://%s/open-stack-frame";
static constexpr const char InspectorDeviceUrlFormat[] = "ws://%s/inspector/device?name=%s&app=%s&device=%s";
static constexpr const char OpenDebuggerUrlFormat[] = "http://%s/open-debugger?device=%s";
static constexpr const char PackagerOkStatus[] = "packager-status:running";
const int LongPollFailureDelayMs = 5000;
};
} // namespace react
} // namespace facebook