react-native-windows 0.67.0-preview.4 → 0.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +129 -0
- package/CHANGELOG.md +65 -5
- package/Libraries/Components/Keyboard/Keyboard.js +2 -2
- package/Libraries/Components/Pressable/Pressable.windows.js +33 -0
- package/Libraries/Core/ReactNativeVersion.js +3 -3
- package/Libraries/Pressability/HoverState.js +4 -0
- package/Microsoft.ReactNative/Modules/CreateModules.cpp +2 -2
- package/Microsoft.ReactNative/packages.config +1 -1
- package/PropertySheets/Generated/PackageVersion.g.props +1 -1
- package/PropertySheets/JSEngine.props +1 -1
- package/Shared/IWebSocketResource.h +6 -6
- package/Shared/InspectorPackagerConnection.cpp +2 -3
- package/Shared/Modules/WebSocketModule.cpp +133 -120
- package/Shared/Modules/WebSocketModule.h +22 -12
- package/Shared/WinRTWebSocketResource.cpp +55 -46
- package/Shared/WinRTWebSocketResource.h +2 -9
- package/jest/preprocessor.js +7 -75
- package/package.json +8 -8
- package/template/shared-app/proj/NuGet.Config +2 -0
package/CHANGELOG.json
CHANGED
|
@@ -1,6 +1,135 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-windows",
|
|
3
3
|
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"date": "Mon, 24 Jan 2022 16:12:32 GMT",
|
|
6
|
+
"tag": "react-native-windows_v0.67.0",
|
|
7
|
+
"version": "0.67.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "jthysell@microsoft.com",
|
|
12
|
+
"package": "react-native-windows",
|
|
13
|
+
"commit": "a1a4439e47c2a98356d7b9b1af765d3907567e16",
|
|
14
|
+
"comment": "[0.67] Remove ADO NuGet feed from config for new projects"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "ngerlem@microsoft.com",
|
|
18
|
+
"package": "react-native-windows",
|
|
19
|
+
"commit": "56818ebc599aa084aa9ffc949691f1be71da169a",
|
|
20
|
+
"comment": "Promote 0.67 to latest"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"author": "beachball",
|
|
24
|
+
"package": "react-native-windows",
|
|
25
|
+
"comment": "Bump @react-native-windows/cli to v0.67.0",
|
|
26
|
+
"commit": "56818ebc599aa084aa9ffc949691f1be71da169a"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"author": "beachball",
|
|
30
|
+
"package": "react-native-windows",
|
|
31
|
+
"comment": "Bump @react-native-windows/virtualized-list to v0.67.0",
|
|
32
|
+
"commit": "56818ebc599aa084aa9ffc949691f1be71da169a"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"author": "beachball",
|
|
36
|
+
"package": "react-native-windows",
|
|
37
|
+
"comment": "Bump @react-native-windows/codegen to v0.67.0",
|
|
38
|
+
"commit": "56818ebc599aa084aa9ffc949691f1be71da169a"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"date": "Mon, 17 Jan 2022 16:12:54 GMT",
|
|
45
|
+
"tag": "react-native-windows_v0.67.0-preview.7",
|
|
46
|
+
"version": "0.67.0-preview.7",
|
|
47
|
+
"comments": {
|
|
48
|
+
"prerelease": [
|
|
49
|
+
{
|
|
50
|
+
"author": "saadnajmi2@gmail.com",
|
|
51
|
+
"package": "react-native-windows",
|
|
52
|
+
"commit": "not available",
|
|
53
|
+
"comment": "Fork HoverState.js to allow hover events on Pressable"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"date": "Mon, 17 Jan 2022 16:12:13 GMT",
|
|
60
|
+
"tag": "react-native-windows_v0.67.0-preview.7",
|
|
61
|
+
"version": "0.67.0-preview.7",
|
|
62
|
+
"comments": {
|
|
63
|
+
"prerelease": [
|
|
64
|
+
{
|
|
65
|
+
"author": "saadnajmi2@gmail.com",
|
|
66
|
+
"package": "react-native-windows",
|
|
67
|
+
"commit": "b58a8738eecd8a3d6a2b918fc35d9a7b93b4437a",
|
|
68
|
+
"comment": "Fork HoverState.js to allow hover events on Pressable"
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"date": "Mon, 03 Jan 2022 16:12:09 GMT",
|
|
75
|
+
"tag": "react-native-windows_v0.67.0-preview.6",
|
|
76
|
+
"version": "0.67.0-preview.6",
|
|
77
|
+
"comments": {
|
|
78
|
+
"prerelease": [
|
|
79
|
+
{
|
|
80
|
+
"author": "julio.rocha@microsoft.com",
|
|
81
|
+
"package": "react-native-windows",
|
|
82
|
+
"commit": "not available",
|
|
83
|
+
"comment": "[0.67] Avoid capturing raw this pointer in WebSocket module"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"date": "Mon, 03 Jan 2022 16:11:53 GMT",
|
|
90
|
+
"tag": "react-native-windows_v0.67.0-preview.6",
|
|
91
|
+
"version": "0.67.0-preview.6",
|
|
92
|
+
"comments": {
|
|
93
|
+
"prerelease": [
|
|
94
|
+
{
|
|
95
|
+
"author": "julio.rocha@microsoft.com",
|
|
96
|
+
"package": "react-native-windows",
|
|
97
|
+
"commit": "372ce65125bce35713a557d7613f07148821944b",
|
|
98
|
+
"comment": "[0.67] Avoid capturing raw this pointer in WebSocket module"
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"date": "Mon, 06 Dec 2021 16:10:50 GMT",
|
|
105
|
+
"tag": "react-native-windows_v0.67.0-preview.5",
|
|
106
|
+
"version": "0.67.0-preview.5",
|
|
107
|
+
"comments": {
|
|
108
|
+
"prerelease": [
|
|
109
|
+
{
|
|
110
|
+
"author": "anandrag@microsoft.com",
|
|
111
|
+
"package": "react-native-windows",
|
|
112
|
+
"commit": "b706da95136fffa1a4deba8f95dc9edfeef1020d",
|
|
113
|
+
"comment": "Bumping Hermes to v0.10"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"date": "Mon, 22 Nov 2021 16:10:24 GMT",
|
|
120
|
+
"tag": "react-native-windows_v0.67.0-preview.4",
|
|
121
|
+
"version": "0.67.0-preview.4",
|
|
122
|
+
"comments": {
|
|
123
|
+
"prerelease": [
|
|
124
|
+
{
|
|
125
|
+
"author": "vmorozov@microsoft.com",
|
|
126
|
+
"package": "react-native-windows",
|
|
127
|
+
"commit": "not available",
|
|
128
|
+
"comment": "Fix C# Module Event invocation"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
},
|
|
4
133
|
{
|
|
5
134
|
"date": "Mon, 22 Nov 2021 16:10:06 GMT",
|
|
6
135
|
"tag": "react-native-windows_v0.67.0-preview.4",
|
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,77 @@
|
|
|
1
1
|
# Change Log - react-native-windows
|
|
2
2
|
|
|
3
|
-
This log was last generated on Mon,
|
|
3
|
+
This log was last generated on Mon, 24 Jan 2022 16:12:32 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## 0.67.0
|
|
7
|
+
## 0.67.0
|
|
8
8
|
|
|
9
|
-
Mon,
|
|
9
|
+
Mon, 24 Jan 2022 16:12:32 GMT
|
|
10
10
|
|
|
11
|
-
###
|
|
11
|
+
### Patches
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- [0.67] Remove ADO NuGet feed from config for new projects (jthysell@microsoft.com)
|
|
14
|
+
- Promote 0.67 to latest (ngerlem@microsoft.com)
|
|
15
|
+
- Bump @react-native-windows/cli to v0.67.0
|
|
16
|
+
- Bump @react-native-windows/virtualized-list to v0.67.0
|
|
17
|
+
- Bump @react-native-windows/codegen to v0.67.0
|
|
14
18
|
|
|
19
|
+
## 0.67.0-preview.7
|
|
20
|
+
|
|
21
|
+
Mon, 17 Jan 2022 16:12:54 GMT
|
|
22
|
+
|
|
23
|
+
### Changes
|
|
24
|
+
|
|
25
|
+
- Fork HoverState.js to allow hover events on Pressable (saadnajmi2@gmail.com)
|
|
26
|
+
|
|
27
|
+
## 0.67.0-preview.7
|
|
28
|
+
|
|
29
|
+
Mon, 17 Jan 2022 16:12:13 GMT
|
|
30
|
+
|
|
31
|
+
### Changes
|
|
32
|
+
|
|
33
|
+
- Fork HoverState.js to allow hover events on Pressable (saadnajmi2@gmail.com)
|
|
34
|
+
|
|
35
|
+
## 0.67.0-preview.6
|
|
36
|
+
|
|
37
|
+
Mon, 03 Jan 2022 16:12:09 GMT
|
|
38
|
+
|
|
39
|
+
### Changes
|
|
40
|
+
|
|
41
|
+
- [0.67] Avoid capturing raw this pointer in WebSocket module (julio.rocha@microsoft.com)
|
|
42
|
+
|
|
43
|
+
## 0.67.0-preview.6
|
|
44
|
+
|
|
45
|
+
Mon, 03 Jan 2022 16:11:53 GMT
|
|
46
|
+
|
|
47
|
+
### Changes
|
|
48
|
+
|
|
49
|
+
- [0.67] Avoid capturing raw this pointer in WebSocket module (julio.rocha@microsoft.com)
|
|
50
|
+
|
|
51
|
+
## 0.67.0-preview.5
|
|
52
|
+
|
|
53
|
+
Mon, 06 Dec 2021 16:10:50 GMT
|
|
54
|
+
|
|
55
|
+
### Changes
|
|
56
|
+
|
|
57
|
+
- Bumping Hermes to v0.10 (anandrag@microsoft.com)
|
|
58
|
+
|
|
59
|
+
## 0.67.0-preview.4
|
|
60
|
+
|
|
61
|
+
Mon, 22 Nov 2021 16:10:24 GMT
|
|
62
|
+
|
|
63
|
+
### Changes
|
|
64
|
+
|
|
65
|
+
- Fix C# Module Event invocation (vmorozov@microsoft.com)
|
|
66
|
+
|
|
67
|
+
## 0.67.0-preview.4
|
|
68
|
+
|
|
69
|
+
Mon, 22 Nov 2021 16:10:06 GMT
|
|
70
|
+
|
|
71
|
+
### Changes
|
|
72
|
+
|
|
73
|
+
- Fix C# Module Event invocation (vmorozov@microsoft.com)
|
|
74
|
+
|
|
15
75
|
## 0.67.0-preview.3
|
|
16
76
|
|
|
17
77
|
Mon, 15 Nov 2021 16:10:10 GMT
|
|
@@ -141,9 +141,9 @@ class Keyboard {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/**
|
|
144
|
-
* @deprecated Use `remove` on the EventSubscription from `
|
|
144
|
+
* @deprecated Use `remove` on the EventSubscription from `addListener`.
|
|
145
145
|
*/
|
|
146
|
-
|
|
146
|
+
removeListener<K: $Keys<KeyboardEventDefinitions>>(
|
|
147
147
|
eventType: K,
|
|
148
148
|
listener: (...$ElementType<KeyboardEventDefinitions, K>) => mixed,
|
|
149
149
|
): void {
|
|
@@ -25,6 +25,7 @@ import usePressability from '../../Pressability/usePressability';
|
|
|
25
25
|
import {normalizeRect, type RectOrSize} from '../../StyleSheet/Rect';
|
|
26
26
|
import type {
|
|
27
27
|
LayoutEvent,
|
|
28
|
+
MouseEvent,
|
|
28
29
|
PressEvent,
|
|
29
30
|
// [Windows
|
|
30
31
|
BlurEvent,
|
|
@@ -72,6 +73,16 @@ type Props = $ReadOnly<{|
|
|
|
72
73
|
*/
|
|
73
74
|
children: React.Node | ((state: StateCallbackType) => React.Node),
|
|
74
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Duration to wait after hover in before calling `onHoverIn`.
|
|
78
|
+
*/
|
|
79
|
+
delayHoverIn?: ?number,
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Duration to wait after hover out before calling `onHoverOut`.
|
|
83
|
+
*/
|
|
84
|
+
delayHoverOut?: ?number,
|
|
85
|
+
|
|
75
86
|
/**
|
|
76
87
|
* Duration (in milliseconds) from `onPressIn` before `onLongPress` is called.
|
|
77
88
|
*/
|
|
@@ -98,6 +109,16 @@ type Props = $ReadOnly<{|
|
|
|
98
109
|
*/
|
|
99
110
|
onLayout?: ?(event: LayoutEvent) => mixed,
|
|
100
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Called when the hover is activated to provide visual feedback.
|
|
114
|
+
*/
|
|
115
|
+
onHoverIn?: ?(event: MouseEvent) => mixed,
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Called when the hover is deactivated to undo visual feedback.
|
|
119
|
+
*/
|
|
120
|
+
onHoverOut?: ?(event: MouseEvent) => mixed,
|
|
121
|
+
|
|
101
122
|
/**
|
|
102
123
|
* Called when a long-tap gesture is detected.
|
|
103
124
|
*/
|
|
@@ -201,9 +222,13 @@ function Pressable(props: Props, forwardedRef): React.Node {
|
|
|
201
222
|
android_ripple,
|
|
202
223
|
cancelable,
|
|
203
224
|
children,
|
|
225
|
+
delayHoverIn,
|
|
226
|
+
delayHoverOut,
|
|
204
227
|
delayLongPress,
|
|
205
228
|
disabled,
|
|
206
229
|
focusable,
|
|
230
|
+
onHoverIn,
|
|
231
|
+
onHoverOut,
|
|
207
232
|
onLongPress,
|
|
208
233
|
onPress,
|
|
209
234
|
onPressIn,
|
|
@@ -267,8 +292,12 @@ function Pressable(props: Props, forwardedRef): React.Node {
|
|
|
267
292
|
hitSlop,
|
|
268
293
|
pressRectOffset: pressRetentionOffset,
|
|
269
294
|
android_disableSound,
|
|
295
|
+
delayHoverIn,
|
|
296
|
+
delayHoverOut,
|
|
270
297
|
delayLongPress,
|
|
271
298
|
delayPressIn: unstable_pressDelay,
|
|
299
|
+
onHoverIn,
|
|
300
|
+
onHoverOut,
|
|
272
301
|
onLongPress,
|
|
273
302
|
onPress,
|
|
274
303
|
onPressIn(event: PressEvent): void {
|
|
@@ -301,9 +330,13 @@ function Pressable(props: Props, forwardedRef): React.Node {
|
|
|
301
330
|
android_disableSound,
|
|
302
331
|
android_rippleConfig,
|
|
303
332
|
cancelable,
|
|
333
|
+
delayHoverIn,
|
|
334
|
+
delayHoverOut,
|
|
304
335
|
delayLongPress,
|
|
305
336
|
disabled,
|
|
306
337
|
hitSlop,
|
|
338
|
+
onHoverIn,
|
|
339
|
+
onHoverOut,
|
|
307
340
|
onLongPress,
|
|
308
341
|
onPress,
|
|
309
342
|
onPressIn,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @generated by scripts/
|
|
2
|
+
* @generated by scripts/set-rn-version.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
5
5
|
*
|
|
@@ -12,6 +12,6 @@
|
|
|
12
12
|
exports.version = {
|
|
13
13
|
major: 0,
|
|
14
14
|
minor: 67,
|
|
15
|
-
patch:
|
|
16
|
-
prerelease:
|
|
15
|
+
patch: 1,
|
|
16
|
+
prerelease: null,
|
|
17
17
|
};
|
|
@@ -49,6 +49,10 @@ if (Platform.OS === 'web') {
|
|
|
49
49
|
document.addEventListener('touchmove', disableHover, true);
|
|
50
50
|
document.addEventListener('mousemove', enableHover, true);
|
|
51
51
|
}
|
|
52
|
+
// [Windows
|
|
53
|
+
} else if (Platform.OS === 'windows') {
|
|
54
|
+
isEnabled = true;
|
|
55
|
+
// Windows]
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
export function isHoverEnabled(): boolean {
|
|
@@ -19,9 +19,9 @@ using winrt::Microsoft::ReactNative::implementation::QuirkSettings;
|
|
|
19
19
|
|
|
20
20
|
namespace Microsoft::React {
|
|
21
21
|
|
|
22
|
-
std::shared_ptr<IWebSocketResource> IWebSocketResource::Make(
|
|
22
|
+
std::shared_ptr<IWebSocketResource> IWebSocketResource::Make() {
|
|
23
23
|
std::vector<winrt::Windows::Security::Cryptography::Certificates::ChainValidationResult> certExceptions;
|
|
24
|
-
return std::make_shared<WinRTWebSocketResource>(std::move(
|
|
24
|
+
return std::make_shared<WinRTWebSocketResource>(std::move(certExceptions));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
} // namespace Microsoft::React
|
|
@@ -7,6 +7,6 @@
|
|
|
7
7
|
<package id="Microsoft.UI.Xaml" version="2.7.0" targetFramework="native" />
|
|
8
8
|
<package id="Microsoft.Windows.CppWinRT" version="2.0.210312.4" targetFramework="native" />
|
|
9
9
|
<package id="Microsoft.WinUI" version="3.0.0-preview4.210210.4" targetFramework="native" />
|
|
10
|
-
<package id="ReactNative.Hermes.Windows" version="0.
|
|
10
|
+
<package id="ReactNative.Hermes.Windows" version="0.10.0-ms.1" targetFramework="native" />
|
|
11
11
|
<!-- package id="ReactNative.V8Jsi.Windows.UWP" version="0.65.5" targetFramework="native" / -->
|
|
12
12
|
</packages>
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
-->
|
|
11
11
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
12
12
|
<PropertyGroup>
|
|
13
|
-
<ReactNativeWindowsVersion>0.67.0
|
|
13
|
+
<ReactNativeWindowsVersion>0.67.0</ReactNativeWindowsVersion>
|
|
14
14
|
<ReactNativeWindowsMajor>0</ReactNativeWindowsMajor>
|
|
15
15
|
<ReactNativeWindowsMinor>67</ReactNativeWindowsMinor>
|
|
16
16
|
<ReactNativeWindowsPatch>0</ReactNativeWindowsPatch>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<!-- Enabling this will (1) Include hermes glues in the Microsoft.ReactNative binaries AND (2) Make hermes the default engine -->
|
|
9
9
|
<UseHermes Condition="'$(UseHermes)' == ''">false</UseHermes>
|
|
10
10
|
<!-- This will be true if (1) the client want to use hermes by setting UseHermes to true OR (2) We are building for UWP where dynamic switching is enabled -->
|
|
11
|
-
<HermesVersion Condition="'$(HermesVersion)' == ''">0.
|
|
11
|
+
<HermesVersion Condition="'$(HermesVersion)' == ''">0.10.0-ms.1</HermesVersion>
|
|
12
12
|
<HermesPackage Condition="'$(HermesPackage)' == '' And Exists('$(PkgReactNative_Hermes_Windows)')">$(PkgReactNative_Hermes_Windows)</HermesPackage>
|
|
13
13
|
<HermesPackage Condition="'$(HermesPackage)' == ''">$(SolutionDir)packages\ReactNative.Hermes.Windows.$(HermesVersion)</HermesPackage>
|
|
14
14
|
<EnableHermesInspectorInReleaseFlavor Condition="'$(EnableHermesInspectorInReleaseFlavor)' == ''">false</EnableHermesInspectorInReleaseFlavor>
|
|
@@ -79,17 +79,17 @@ struct IWebSocketResource {
|
|
|
79
79
|
/// <summary>
|
|
80
80
|
/// Creates an <c>IWebSocketResource</c> instance.
|
|
81
81
|
/// </summary>
|
|
82
|
-
|
|
83
|
-
/// WebSocket URL address the instance will connect to.
|
|
84
|
-
/// The address's scheme can be either ws:// or wss://.
|
|
85
|
-
/// </param>
|
|
86
|
-
static std::shared_ptr<IWebSocketResource> Make(std::string &&url);
|
|
82
|
+
static std::shared_ptr<IWebSocketResource> Make();
|
|
87
83
|
|
|
88
84
|
virtual ~IWebSocketResource() noexcept {}
|
|
89
85
|
|
|
90
86
|
/// <summary>
|
|
91
87
|
/// Establishes a continuous connection with the remote endpoint.
|
|
92
88
|
/// </summary>
|
|
89
|
+
/// <param name="url">
|
|
90
|
+
/// WebSocket URL address the instance will connect to.
|
|
91
|
+
/// The address's scheme can be either ws:// or wss://.
|
|
92
|
+
/// </param>
|
|
93
93
|
/// <param name="protocols">
|
|
94
94
|
/// Currently unused
|
|
95
95
|
/// </param>
|
|
@@ -97,7 +97,7 @@ struct IWebSocketResource {
|
|
|
97
97
|
/// HTTP header fields passed by the remote endpoint, to be used in the
|
|
98
98
|
/// handshake process.
|
|
99
99
|
/// </param>
|
|
100
|
-
virtual void Connect(const Protocols &protocols = {}, const Options &options = {}) noexcept = 0;
|
|
100
|
+
virtual void Connect(std::string &&url, const Protocols &protocols = {}, const Options &options = {}) noexcept = 0;
|
|
101
101
|
|
|
102
102
|
/// <summary>
|
|
103
103
|
/// Sends a ping frame to the remote endpoint.
|
|
@@ -204,8 +204,7 @@ winrt::fire_and_forget InspectorPackagerConnection::connectAsync() {
|
|
|
204
204
|
co_await winrt::resume_background();
|
|
205
205
|
|
|
206
206
|
std::vector<winrt::Windows::Security::Cryptography::Certificates::ChainValidationResult> certExceptions;
|
|
207
|
-
m_packagerWebSocketConnection =
|
|
208
|
-
std::make_shared<Microsoft::React::WinRTWebSocketResource>(m_url, std::move(certExceptions));
|
|
207
|
+
m_packagerWebSocketConnection = std::make_shared<Microsoft::React::WinRTWebSocketResource>(std::move(certExceptions));
|
|
209
208
|
|
|
210
209
|
m_packagerWebSocketConnection->SetOnError([](const Microsoft::React::IWebSocketResource::Error &err) {
|
|
211
210
|
facebook::react::tracing::error(err.Message.c_str());
|
|
@@ -270,7 +269,7 @@ winrt::fire_and_forget InspectorPackagerConnection::connectAsync() {
|
|
|
270
269
|
|
|
271
270
|
Microsoft::React::IWebSocketResource::Protocols protocols;
|
|
272
271
|
Microsoft::React::IWebSocketResource::Options options;
|
|
273
|
-
m_packagerWebSocketConnection->Connect(protocols, options);
|
|
272
|
+
m_packagerWebSocketConnection->Connect(std::string{m_url}, protocols, options);
|
|
274
273
|
|
|
275
274
|
co_return;
|
|
276
275
|
}
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
#include <iomanip>
|
|
15
15
|
|
|
16
16
|
using namespace facebook::xplat;
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
using facebook::react::Instance;
|
|
19
|
+
using folly::dynamic;
|
|
18
20
|
|
|
19
21
|
using Microsoft::Common::Unicode::Utf16ToUtf8;
|
|
20
22
|
using Microsoft::Common::Unicode::Utf8ToUtf16;
|
|
@@ -24,17 +26,111 @@ using std::string;
|
|
|
24
26
|
using std::weak_ptr;
|
|
25
27
|
|
|
26
28
|
namespace {
|
|
29
|
+
using Microsoft::React::IWebSocketResource;
|
|
30
|
+
using Microsoft::React::WebSocketModule;
|
|
31
|
+
|
|
27
32
|
constexpr char moduleName[] = "WebSocketModule";
|
|
33
|
+
|
|
34
|
+
static void SendEvent(weak_ptr<Instance> weakInstance, string &&eventName, dynamic &&args) {
|
|
35
|
+
if (auto instance = weakInstance.lock()) {
|
|
36
|
+
instance->callJSFunction("RCTDeviceEventEmitter", "emit", dynamic::array(std::move(eventName), std::move(args)));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static shared_ptr<IWebSocketResource>
|
|
41
|
+
GetOrCreateWebSocket(int64_t id, string &&url, weak_ptr<WebSocketModule::SharedState> weakState) {
|
|
42
|
+
auto state = weakState.lock();
|
|
43
|
+
if (!state) {
|
|
44
|
+
return nullptr;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
auto itr = state->ResourceMap.find(id);
|
|
48
|
+
if (itr == state->ResourceMap.end()) {
|
|
49
|
+
if (!state->Module) {
|
|
50
|
+
return nullptr;
|
|
51
|
+
}
|
|
52
|
+
auto weakInstance = state->Module->getInstance();
|
|
53
|
+
|
|
54
|
+
shared_ptr<IWebSocketResource> ws;
|
|
55
|
+
try {
|
|
56
|
+
ws = state->ResourceFactory(std::move(url));
|
|
57
|
+
} catch (const winrt::hresult_error &e) {
|
|
58
|
+
std::stringstream ss;
|
|
59
|
+
ss << "[" << std::hex << std::showbase << std::setw(8) << static_cast<uint32_t>(e.code()) << "] "
|
|
60
|
+
<< winrt::to_string(e.message());
|
|
61
|
+
|
|
62
|
+
SendEvent(weakInstance, "webSocketFailed", dynamic::object("id", id)("message", std::move(ss.str())));
|
|
63
|
+
|
|
64
|
+
return nullptr;
|
|
65
|
+
} catch (const std::exception &e) {
|
|
66
|
+
SendEvent(weakInstance, "webSocketFailed", dynamic::object("id", id)("message", e.what()));
|
|
67
|
+
|
|
68
|
+
return nullptr;
|
|
69
|
+
} catch (...) {
|
|
70
|
+
SendEvent(
|
|
71
|
+
weakInstance,
|
|
72
|
+
"webSocketFailed",
|
|
73
|
+
dynamic::object("id", id)("message", "Unidentified error creating IWebSocketResource"));
|
|
74
|
+
|
|
75
|
+
return nullptr;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
ws->SetOnError([id, weakInstance](const IWebSocketResource::Error &err) {
|
|
79
|
+
auto strongInstance = weakInstance.lock();
|
|
80
|
+
if (!strongInstance)
|
|
81
|
+
return;
|
|
82
|
+
|
|
83
|
+
auto errorObj = dynamic::object("id", id)("message", err.Message);
|
|
84
|
+
SendEvent(weakInstance, "websocketFailed", std::move(errorObj));
|
|
85
|
+
});
|
|
86
|
+
ws->SetOnConnect([id, weakInstance]() {
|
|
87
|
+
auto strongInstance = weakInstance.lock();
|
|
88
|
+
if (!strongInstance)
|
|
89
|
+
return;
|
|
90
|
+
|
|
91
|
+
auto args = dynamic::object("id", id);
|
|
92
|
+
SendEvent(weakInstance, "websocketOpen", std::move(args));
|
|
93
|
+
});
|
|
94
|
+
ws->SetOnMessage([id, weakInstance](size_t length, const string &message, bool isBinary) {
|
|
95
|
+
auto strongInstance = weakInstance.lock();
|
|
96
|
+
if (!strongInstance)
|
|
97
|
+
return;
|
|
98
|
+
|
|
99
|
+
auto args = dynamic::object("id", id)("data", message)("type", isBinary ? "binary" : "text");
|
|
100
|
+
SendEvent(weakInstance, "websocketMessage", std::move(args));
|
|
101
|
+
});
|
|
102
|
+
ws->SetOnClose([id, weakInstance](IWebSocketResource::CloseCode code, const string &reason) {
|
|
103
|
+
auto strongInstance = weakInstance.lock();
|
|
104
|
+
if (!strongInstance)
|
|
105
|
+
return;
|
|
106
|
+
|
|
107
|
+
auto args = dynamic::object("id", id)("code", static_cast<uint16_t>(code))("reason", reason);
|
|
108
|
+
SendEvent(weakInstance, "websocketClosed", std::move(args));
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
state->ResourceMap.emplace(id, ws);
|
|
112
|
+
return ws;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return itr->second;
|
|
116
|
+
}
|
|
117
|
+
|
|
28
118
|
} // anonymous namespace
|
|
29
119
|
|
|
30
120
|
namespace Microsoft::React {
|
|
31
121
|
|
|
32
|
-
WebSocketModule::WebSocketModule()
|
|
33
|
-
|
|
122
|
+
WebSocketModule::WebSocketModule() : m_sharedState{std::make_shared<SharedState>()} {
|
|
123
|
+
m_sharedState->ResourceFactory = [](string &&url) { return IWebSocketResource::Make(); };
|
|
124
|
+
m_sharedState->Module = this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
WebSocketModule::~WebSocketModule() noexcept /*override*/ {
|
|
128
|
+
m_sharedState->Module = nullptr;
|
|
129
|
+
}
|
|
34
130
|
|
|
35
131
|
void WebSocketModule::SetResourceFactory(
|
|
36
132
|
std::function<shared_ptr<IWebSocketResource>(const string &)> &&resourceFactory) {
|
|
37
|
-
|
|
133
|
+
m_sharedState->ResourceFactory = std::move(resourceFactory);
|
|
38
134
|
}
|
|
39
135
|
|
|
40
136
|
string WebSocketModule::getName() {
|
|
@@ -50,9 +146,9 @@ std::vector<facebook::xplat::module::CxxModule::Method> WebSocketModule::getMeth
|
|
|
50
146
|
{
|
|
51
147
|
return
|
|
52
148
|
{
|
|
53
|
-
|
|
149
|
+
{
|
|
54
150
|
"connect",
|
|
55
|
-
[
|
|
151
|
+
[weakState = weak_ptr<SharedState>(m_sharedState)](dynamic args) // const string& url, dynamic protocols, dynamic options, int64_t id
|
|
56
152
|
{
|
|
57
153
|
IWebSocketResource::Protocols protocols;
|
|
58
154
|
dynamic protocolsDynamic = jsArgAsDynamic(args, 1);
|
|
@@ -75,20 +171,21 @@ std::vector<facebook::xplat::module::CxxModule::Method> WebSocketModule::getMeth
|
|
|
75
171
|
}
|
|
76
172
|
}
|
|
77
173
|
|
|
78
|
-
weak_ptr weakWs =
|
|
174
|
+
weak_ptr weakWs = GetOrCreateWebSocket(jsArgAsInt(args, 3), jsArgAsString(args, 0), weakState);
|
|
79
175
|
if (auto sharedWs = weakWs.lock())
|
|
80
176
|
{
|
|
81
|
-
sharedWs->Connect(protocols, options);
|
|
177
|
+
sharedWs->Connect(jsArgAsString(args, 0), protocols, options);
|
|
82
178
|
}
|
|
83
|
-
}
|
|
84
|
-
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
{
|
|
85
182
|
"close",
|
|
86
|
-
[
|
|
183
|
+
[weakState = weak_ptr<SharedState>(m_sharedState)](dynamic args) // [int64_t code, string reason,] int64_t id
|
|
87
184
|
{
|
|
88
185
|
// See react-native\Libraries\WebSocket\WebSocket.js:_close
|
|
89
186
|
if (args.size() == 3) // WebSocketModule.close(statusCode, closeReason, this._socketId);
|
|
90
187
|
{
|
|
91
|
-
weak_ptr weakWs =
|
|
188
|
+
weak_ptr weakWs = GetOrCreateWebSocket(jsArgAsInt(args, 2), {}, weakState);
|
|
92
189
|
if (auto sharedWs = weakWs.lock())
|
|
93
190
|
{
|
|
94
191
|
sharedWs->Close(static_cast<IWebSocketResource::CloseCode>(jsArgAsInt(args, 0)), jsArgAsString(args, 1));
|
|
@@ -96,7 +193,7 @@ std::vector<facebook::xplat::module::CxxModule::Method> WebSocketModule::getMeth
|
|
|
96
193
|
}
|
|
97
194
|
else if (args.size() == 1) // WebSocketModule.close(this._socketId);
|
|
98
195
|
{
|
|
99
|
-
weak_ptr weakWs =
|
|
196
|
+
weak_ptr weakWs = GetOrCreateWebSocket(jsArgAsInt(args, 0), {}, weakState);
|
|
100
197
|
if (auto sharedWs = weakWs.lock())
|
|
101
198
|
{
|
|
102
199
|
sharedWs->Close(IWebSocketResource::CloseCode::Normal, {});
|
|
@@ -104,137 +201,53 @@ std::vector<facebook::xplat::module::CxxModule::Method> WebSocketModule::getMeth
|
|
|
104
201
|
}
|
|
105
202
|
else
|
|
106
203
|
{
|
|
107
|
-
auto
|
|
108
|
-
|
|
204
|
+
auto state = weakState.lock();
|
|
205
|
+
if (state && state->Module) {
|
|
206
|
+
auto errorObj = dynamic::object("id", -1)("message", "Incorrect number of parameters");
|
|
207
|
+
SendEvent(state->Module->getInstance(), "websocketFailed", std::move(errorObj));
|
|
208
|
+
}
|
|
109
209
|
}
|
|
110
|
-
}
|
|
111
|
-
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
{
|
|
112
213
|
"send",
|
|
113
|
-
[
|
|
214
|
+
[weakState = weak_ptr<SharedState>(m_sharedState)](dynamic args) // const string& message, int64_t id
|
|
114
215
|
{
|
|
115
|
-
weak_ptr weakWs =
|
|
216
|
+
weak_ptr weakWs = GetOrCreateWebSocket(jsArgAsInt(args, 1), {}, weakState);
|
|
116
217
|
if (auto sharedWs = weakWs.lock())
|
|
117
218
|
{
|
|
118
219
|
sharedWs->Send(jsArgAsString(args, 0));
|
|
119
220
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
{
|
|
122
224
|
"sendBinary",
|
|
123
|
-
[
|
|
225
|
+
[weakState = weak_ptr<SharedState>(m_sharedState)](dynamic args) // const string& base64String, int64_t id
|
|
124
226
|
{
|
|
125
|
-
weak_ptr weakWs =
|
|
227
|
+
weak_ptr weakWs = GetOrCreateWebSocket(jsArgAsInt(args, 1), {}, weakState);
|
|
126
228
|
if (auto sharedWs = weakWs.lock())
|
|
127
229
|
{
|
|
128
230
|
sharedWs->SendBinary(jsArgAsString(args, 0));
|
|
129
231
|
}
|
|
130
|
-
}
|
|
131
|
-
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
{
|
|
132
235
|
"ping",
|
|
133
|
-
[
|
|
236
|
+
[weakState = weak_ptr<SharedState>(m_sharedState)](dynamic args) // int64_t id
|
|
134
237
|
{
|
|
135
|
-
weak_ptr weakWs =
|
|
238
|
+
weak_ptr weakWs = GetOrCreateWebSocket(jsArgAsInt(args, 0), {}, weakState);
|
|
136
239
|
if (auto sharedWs = weakWs.lock())
|
|
137
240
|
{
|
|
138
241
|
sharedWs->Ping();
|
|
139
242
|
}
|
|
140
|
-
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
141
245
|
};
|
|
142
246
|
} // getMethods
|
|
143
247
|
// clang-format on
|
|
144
248
|
|
|
145
|
-
#pragma region private members
|
|
146
|
-
|
|
147
|
-
void WebSocketModule::SendEvent(string &&eventName, dynamic &&args) {
|
|
148
|
-
auto weakInstance = this->getInstance();
|
|
149
|
-
if (auto instance = weakInstance.lock()) {
|
|
150
|
-
instance->callJSFunction("RCTDeviceEventEmitter", "emit", dynamic::array(std::move(eventName), std::move(args)));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// clang-format off
|
|
155
|
-
shared_ptr<IWebSocketResource> WebSocketModule::GetOrCreateWebSocket(int64_t id, string&& url)
|
|
156
|
-
{
|
|
157
|
-
auto itr = m_webSockets.find(id);
|
|
158
|
-
if (itr == m_webSockets.end())
|
|
159
|
-
{
|
|
160
|
-
shared_ptr<IWebSocketResource> ws;
|
|
161
|
-
try
|
|
162
|
-
{
|
|
163
|
-
ws = m_resourceFactory(std::move(url));
|
|
164
|
-
}
|
|
165
|
-
catch (const winrt::hresult_error& e)
|
|
166
|
-
{
|
|
167
|
-
std::stringstream ss;
|
|
168
|
-
ss << "[" << std::hex << std::showbase << std::setw(8) << static_cast<uint32_t>(e.code()) << "] " <<
|
|
169
|
-
winrt::to_string(e.message());
|
|
170
|
-
|
|
171
|
-
SendEvent("webSocketFailed", dynamic::object("id", id)("message", std::move(ss.str())));
|
|
172
|
-
|
|
173
|
-
return nullptr;
|
|
174
|
-
}
|
|
175
|
-
catch (const std::exception& e)
|
|
176
|
-
{
|
|
177
|
-
SendEvent("webSocketFailed", dynamic::object("id", id)("message", e.what()));
|
|
178
|
-
|
|
179
|
-
return nullptr;
|
|
180
|
-
}
|
|
181
|
-
catch (...)
|
|
182
|
-
{
|
|
183
|
-
SendEvent("webSocketFailed", dynamic::object("id", id)("message", "Unidentified error creating IWebSocketResource"));
|
|
184
|
-
|
|
185
|
-
return nullptr;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
auto weakInstance = this->getInstance();
|
|
189
|
-
ws->SetOnError([this, id, weakInstance](const IWebSocketResource::Error& err)
|
|
190
|
-
{
|
|
191
|
-
auto strongInstance = weakInstance.lock();
|
|
192
|
-
if (!strongInstance)
|
|
193
|
-
return;
|
|
194
|
-
|
|
195
|
-
auto errorObj = dynamic::object("id", id)("message", err.Message);
|
|
196
|
-
this->SendEvent("websocketFailed", std::move(errorObj));
|
|
197
|
-
});
|
|
198
|
-
ws->SetOnConnect([this, id, weakInstance]()
|
|
199
|
-
{
|
|
200
|
-
auto strongInstance = weakInstance.lock();
|
|
201
|
-
if (!strongInstance)
|
|
202
|
-
return;
|
|
203
|
-
|
|
204
|
-
auto args = dynamic::object("id", id);
|
|
205
|
-
this->SendEvent("websocketOpen", std::move(args));
|
|
206
|
-
});
|
|
207
|
-
ws->SetOnMessage([this, id, weakInstance](size_t length, const string& message, bool isBinary)
|
|
208
|
-
{
|
|
209
|
-
auto strongInstance = weakInstance.lock();
|
|
210
|
-
if (!strongInstance)
|
|
211
|
-
return;
|
|
212
|
-
|
|
213
|
-
auto args = dynamic::object("id", id)("data", message)("type", isBinary ? "binary" : "text");
|
|
214
|
-
this->SendEvent("websocketMessage", std::move(args));
|
|
215
|
-
});
|
|
216
|
-
ws->SetOnClose([this, id, weakInstance](IWebSocketResource::CloseCode code, const string& reason)
|
|
217
|
-
{
|
|
218
|
-
auto strongInstance = weakInstance.lock();
|
|
219
|
-
if (!strongInstance)
|
|
220
|
-
return;
|
|
221
|
-
|
|
222
|
-
auto args = dynamic::object("id", id)("code", static_cast<uint16_t>(code))("reason", reason);
|
|
223
|
-
this->SendEvent("websocketClosed", std::move(args));
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
m_webSockets.emplace(id, ws);
|
|
227
|
-
return ws;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return itr->second;
|
|
231
|
-
}
|
|
232
|
-
// clang-format on
|
|
233
|
-
|
|
234
|
-
#pragma endregion private members
|
|
235
|
-
|
|
236
249
|
/*extern*/ std::unique_ptr<facebook::xplat::module::CxxModule> CreateWebSocketModule() noexcept {
|
|
237
|
-
return make_unique<WebSocketModule>();
|
|
250
|
+
return std::make_unique<WebSocketModule>();
|
|
238
251
|
}
|
|
239
252
|
|
|
240
253
|
} // namespace Microsoft::React
|
|
@@ -18,6 +18,26 @@ class WebSocketModule : public facebook::xplat::module::CxxModule {
|
|
|
18
18
|
|
|
19
19
|
WebSocketModule();
|
|
20
20
|
|
|
21
|
+
~WebSocketModule() noexcept override;
|
|
22
|
+
|
|
23
|
+
struct SharedState {
|
|
24
|
+
/// <summary>
|
|
25
|
+
/// Keeps <c>IWebSocketResource</c> instances identified by <c>id</c>.
|
|
26
|
+
/// As defined in WebSocket.js.
|
|
27
|
+
/// </summary>
|
|
28
|
+
std::map<int64_t, std::shared_ptr<IWebSocketResource>> ResourceMap{};
|
|
29
|
+
|
|
30
|
+
/// <summary>
|
|
31
|
+
/// Generates IWebSocketResource instances, defaulting to IWebSocketResource::Make.
|
|
32
|
+
/// </summary>
|
|
33
|
+
std::function<std::shared_ptr<IWebSocketResource>(std::string &&)> ResourceFactory;
|
|
34
|
+
|
|
35
|
+
/// <summary>
|
|
36
|
+
/// Keeps a raw reference to the module object to lazily retrieve the React Instance as needed.
|
|
37
|
+
/// </summary>
|
|
38
|
+
CxxModule *Module{nullptr};
|
|
39
|
+
};
|
|
40
|
+
|
|
21
41
|
#pragma region CxxModule overrides
|
|
22
42
|
|
|
23
43
|
/// <summary>
|
|
@@ -41,16 +61,6 @@ class WebSocketModule : public facebook::xplat::module::CxxModule {
|
|
|
41
61
|
void SetResourceFactory(std::function<std::shared_ptr<IWebSocketResource>(const std::string &)> &&resourceFactory);
|
|
42
62
|
|
|
43
63
|
private:
|
|
44
|
-
/// <summary>
|
|
45
|
-
/// Notifies an event to the current React Instance.
|
|
46
|
-
/// </summary>
|
|
47
|
-
void SendEvent(std::string &&eventName, folly::dynamic &¶meters);
|
|
48
|
-
|
|
49
|
-
/// <summary>
|
|
50
|
-
/// Creates or retrieves a raw <c>IWebSocketResource</c> pointer.
|
|
51
|
-
/// </summary>
|
|
52
|
-
std::shared_ptr<IWebSocketResource> GetOrCreateWebSocket(std::int64_t id, std::string &&url = {});
|
|
53
|
-
|
|
54
64
|
/// <summary>
|
|
55
65
|
/// Keeps <c>IWebSocketResource</c> instances identified by <c>id</c>.
|
|
56
66
|
/// As defined in WebSocket.js.
|
|
@@ -58,9 +68,9 @@ class WebSocketModule : public facebook::xplat::module::CxxModule {
|
|
|
58
68
|
std::map<int64_t, std::shared_ptr<IWebSocketResource>> m_webSockets;
|
|
59
69
|
|
|
60
70
|
/// <summary>
|
|
61
|
-
///
|
|
71
|
+
/// Keeps members that can be accessed threads other than this module's owner accessible.
|
|
62
72
|
/// </summary>
|
|
63
|
-
std::
|
|
73
|
+
std::shared_ptr<SharedState> m_sharedState;
|
|
64
74
|
};
|
|
65
75
|
|
|
66
76
|
} // namespace Microsoft::React
|
|
@@ -90,29 +90,21 @@ namespace Microsoft::React {
|
|
|
90
90
|
// private
|
|
91
91
|
WinRTWebSocketResource::WinRTWebSocketResource(
|
|
92
92
|
IMessageWebSocket &&socket,
|
|
93
|
-
Uri &&uri,
|
|
94
93
|
vector<ChainValidationResult> &&certExceptions)
|
|
95
|
-
: WinRTWebSocketResource(
|
|
96
|
-
std::move(socket),
|
|
97
|
-
DataWriter{socket.OutputStream()},
|
|
98
|
-
std::move(uri),
|
|
99
|
-
std::move(certExceptions)) {}
|
|
94
|
+
: WinRTWebSocketResource(std::move(socket), DataWriter{socket.OutputStream()}, std::move(certExceptions)) {}
|
|
100
95
|
|
|
101
96
|
WinRTWebSocketResource::WinRTWebSocketResource(
|
|
102
97
|
IMessageWebSocket &&socket,
|
|
103
98
|
IDataWriter &&writer,
|
|
104
|
-
Uri &&uri,
|
|
105
99
|
vector<ChainValidationResult> &&certExceptions)
|
|
106
|
-
:
|
|
107
|
-
m_socket.MessageReceived({this, &WinRTWebSocketResource::OnMessageReceived});
|
|
108
|
-
|
|
100
|
+
: m_socket{std::move(socket)}, m_writer{std::move(writer)} {
|
|
109
101
|
for (const auto &certException : certExceptions) {
|
|
110
102
|
m_socket.Control().IgnorableServerCertificateErrors().Append(certException);
|
|
111
103
|
}
|
|
112
104
|
}
|
|
113
105
|
|
|
114
|
-
WinRTWebSocketResource::WinRTWebSocketResource(
|
|
115
|
-
: WinRTWebSocketResource(MessageWebSocket{},
|
|
106
|
+
WinRTWebSocketResource::WinRTWebSocketResource(vector<ChainValidationResult> &&certExceptions)
|
|
107
|
+
: WinRTWebSocketResource(MessageWebSocket{}, std::move(certExceptions)) {}
|
|
116
108
|
|
|
117
109
|
WinRTWebSocketResource::~WinRTWebSocketResource() noexcept /*override*/
|
|
118
110
|
{
|
|
@@ -123,13 +115,14 @@ WinRTWebSocketResource::~WinRTWebSocketResource() noexcept /*override*/
|
|
|
123
115
|
|
|
124
116
|
#pragma region Private members
|
|
125
117
|
|
|
126
|
-
IAsyncAction WinRTWebSocketResource::PerformConnect() noexcept {
|
|
118
|
+
IAsyncAction WinRTWebSocketResource::PerformConnect(Uri &&uri) noexcept {
|
|
127
119
|
auto self = shared_from_this();
|
|
120
|
+
auto coUri = std::move(uri);
|
|
128
121
|
|
|
129
122
|
co_await resume_background();
|
|
130
123
|
|
|
131
124
|
try {
|
|
132
|
-
auto async = self->m_socket.ConnectAsync(
|
|
125
|
+
auto async = self->m_socket.ConnectAsync(coUri);
|
|
133
126
|
|
|
134
127
|
co_await lessthrow_await_adapter<IAsyncAction>{async};
|
|
135
128
|
|
|
@@ -293,36 +286,6 @@ fire_and_forget WinRTWebSocketResource::PerformClose() noexcept {
|
|
|
293
286
|
m_closePerformed.Set();
|
|
294
287
|
}
|
|
295
288
|
|
|
296
|
-
void WinRTWebSocketResource::OnMessageReceived(
|
|
297
|
-
IWebSocket const &sender,
|
|
298
|
-
IMessageWebSocketMessageReceivedEventArgs const &args) {
|
|
299
|
-
try {
|
|
300
|
-
string response;
|
|
301
|
-
IDataReader reader = args.GetDataReader();
|
|
302
|
-
auto len = reader.UnconsumedBufferLength();
|
|
303
|
-
if (args.MessageType() == SocketMessageType::Utf8) {
|
|
304
|
-
reader.UnicodeEncoding(UnicodeEncoding::Utf8);
|
|
305
|
-
vector<uint8_t> data(len);
|
|
306
|
-
reader.ReadBytes(data);
|
|
307
|
-
|
|
308
|
-
response = string(CheckedReinterpretCast<char *>(data.data()), data.size());
|
|
309
|
-
} else {
|
|
310
|
-
auto buffer = reader.ReadBuffer(len);
|
|
311
|
-
winrt::hstring data = CryptographicBuffer::EncodeToBase64String(buffer);
|
|
312
|
-
|
|
313
|
-
response = winrt::to_string(std::wstring_view(data));
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (m_readHandler) {
|
|
317
|
-
m_readHandler(response.length(), response, args.MessageType() == SocketMessageType::Binary);
|
|
318
|
-
}
|
|
319
|
-
} catch (hresult_error const &e) {
|
|
320
|
-
if (m_errorHandler) {
|
|
321
|
-
m_errorHandler({HResultToString(e), ErrorType::Receive});
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
289
|
void WinRTWebSocketResource::Synchronize() noexcept {
|
|
327
290
|
// Ensure sequence of other operations
|
|
328
291
|
if (m_connectRequested) {
|
|
@@ -334,7 +297,36 @@ void WinRTWebSocketResource::Synchronize() noexcept {
|
|
|
334
297
|
|
|
335
298
|
#pragma region IWebSocketResource
|
|
336
299
|
|
|
337
|
-
void WinRTWebSocketResource::Connect(const Protocols &protocols, const Options &options) noexcept {
|
|
300
|
+
void WinRTWebSocketResource::Connect(string &&url, const Protocols &protocols, const Options &options) noexcept {
|
|
301
|
+
m_socket.MessageReceived(
|
|
302
|
+
[self = shared_from_this()](IWebSocket const &sender, IMessageWebSocketMessageReceivedEventArgs const &args) {
|
|
303
|
+
try {
|
|
304
|
+
string response;
|
|
305
|
+
IDataReader reader = args.GetDataReader();
|
|
306
|
+
auto len = reader.UnconsumedBufferLength();
|
|
307
|
+
if (args.MessageType() == SocketMessageType::Utf8) {
|
|
308
|
+
reader.UnicodeEncoding(UnicodeEncoding::Utf8);
|
|
309
|
+
vector<uint8_t> data(len);
|
|
310
|
+
reader.ReadBytes(data);
|
|
311
|
+
|
|
312
|
+
response = string(CheckedReinterpretCast<char *>(data.data()), data.size());
|
|
313
|
+
} else {
|
|
314
|
+
auto buffer = reader.ReadBuffer(len);
|
|
315
|
+
winrt::hstring data = CryptographicBuffer::EncodeToBase64String(buffer);
|
|
316
|
+
|
|
317
|
+
response = winrt::to_string(std::wstring_view(data));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
if (self->m_readHandler) {
|
|
321
|
+
self->m_readHandler(response.length(), response, args.MessageType() == SocketMessageType::Binary);
|
|
322
|
+
}
|
|
323
|
+
} catch (hresult_error const &e) {
|
|
324
|
+
if (self->m_errorHandler) {
|
|
325
|
+
self->m_errorHandler({HResultToString(e), ErrorType::Receive});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
338
330
|
m_readyState = ReadyState::Connecting;
|
|
339
331
|
|
|
340
332
|
for (const auto &header : options) {
|
|
@@ -348,7 +340,24 @@ void WinRTWebSocketResource::Connect(const Protocols &protocols, const Options &
|
|
|
348
340
|
}
|
|
349
341
|
|
|
350
342
|
m_connectRequested = true;
|
|
351
|
-
|
|
343
|
+
|
|
344
|
+
Uri uri{nullptr};
|
|
345
|
+
try {
|
|
346
|
+
uri = Uri{winrt::to_hstring(url)};
|
|
347
|
+
} catch (hresult_error const &e) {
|
|
348
|
+
if (m_errorHandler) {
|
|
349
|
+
m_errorHandler({HResultToString(e), ErrorType::Connection});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Abort - Mark connection as concluded.
|
|
353
|
+
SetEvent(m_connectPerformed.get());
|
|
354
|
+
m_connectPerformedPromise.set_value();
|
|
355
|
+
m_connectRequested = false;
|
|
356
|
+
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
PerformConnect(std::move(uri));
|
|
352
361
|
}
|
|
353
362
|
|
|
354
363
|
void WinRTWebSocketResource::Ping() noexcept {
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
namespace Microsoft::React {
|
|
18
18
|
|
|
19
19
|
class WinRTWebSocketResource : public IWebSocketResource, public std::enable_shared_from_this<WinRTWebSocketResource> {
|
|
20
|
-
winrt::Windows::Foundation::Uri m_uri;
|
|
21
20
|
winrt::Windows::Networking::Sockets::IMessageWebSocket m_socket;
|
|
22
21
|
// TODO: Use or remove.
|
|
23
22
|
winrt::Windows::Networking::Sockets::IMessageWebSocket::MessageReceived_revoker m_revoker;
|
|
@@ -45,28 +44,22 @@ class WinRTWebSocketResource : public IWebSocketResource, public std::enable_sha
|
|
|
45
44
|
|
|
46
45
|
WinRTWebSocketResource(
|
|
47
46
|
winrt::Windows::Networking::Sockets::IMessageWebSocket &&socket,
|
|
48
|
-
winrt::Windows::Foundation::Uri &&uri,
|
|
49
47
|
std::vector<winrt::Windows::Security::Cryptography::Certificates::ChainValidationResult> &&certExceptions);
|
|
50
48
|
|
|
51
|
-
winrt::Windows::Foundation::IAsyncAction PerformConnect() noexcept;
|
|
49
|
+
winrt::Windows::Foundation::IAsyncAction PerformConnect(winrt::Windows::Foundation::Uri &&uri) noexcept;
|
|
52
50
|
winrt::fire_and_forget PerformPing() noexcept;
|
|
53
51
|
winrt::fire_and_forget PerformWrite(std::string &&message, bool isBinary) noexcept;
|
|
54
52
|
winrt::fire_and_forget PerformClose() noexcept;
|
|
55
53
|
|
|
56
|
-
void OnMessageReceived(
|
|
57
|
-
winrt::Windows::Networking::Sockets::IWebSocket const &sender,
|
|
58
|
-
winrt::Windows::Networking::Sockets::IMessageWebSocketMessageReceivedEventArgs const &args);
|
|
59
54
|
void Synchronize() noexcept;
|
|
60
55
|
|
|
61
56
|
public:
|
|
62
57
|
WinRTWebSocketResource(
|
|
63
58
|
winrt::Windows::Networking::Sockets::IMessageWebSocket &&socket,
|
|
64
59
|
winrt::Windows::Storage::Streams::IDataWriter &&writer,
|
|
65
|
-
winrt::Windows::Foundation::Uri &&uri,
|
|
66
60
|
std::vector<winrt::Windows::Security::Cryptography::Certificates::ChainValidationResult> &&certExceptions);
|
|
67
61
|
|
|
68
62
|
WinRTWebSocketResource(
|
|
69
|
-
const std::string &urlString,
|
|
70
63
|
std::vector<winrt::Windows::Security::Cryptography::Certificates::ChainValidationResult> &&certExceptions);
|
|
71
64
|
|
|
72
65
|
~WinRTWebSocketResource() noexcept override;
|
|
@@ -76,7 +69,7 @@ class WinRTWebSocketResource : public IWebSocketResource, public std::enable_sha
|
|
|
76
69
|
/// <summary>
|
|
77
70
|
/// <see cref="IWebSocketResource::Connect" />
|
|
78
71
|
/// </summary>
|
|
79
|
-
void Connect(const Protocols &protocols, const Options &options) noexcept override;
|
|
72
|
+
void Connect(std::string &&url, const Protocols &protocols, const Options &options) noexcept override;
|
|
80
73
|
|
|
81
74
|
/// <summary>
|
|
82
75
|
/// <see cref="IWebSocketResource::Ping" />
|
package/jest/preprocessor.js
CHANGED
|
@@ -13,42 +13,10 @@
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
15
|
const babelRegisterOnly = require('metro-babel-register');
|
|
16
|
-
const nullthrows = require('nullthrows');
|
|
17
16
|
const createCacheKeyFunction = require('@jest/create-cache-key-function')
|
|
18
17
|
.default;
|
|
19
|
-
const t = require('@babel/types');
|
|
20
|
-
const {statements} = require('@babel/template').default;
|
|
21
18
|
|
|
22
|
-
const
|
|
23
|
-
const importAll = '__importAll__';
|
|
24
|
-
|
|
25
|
-
// prelude
|
|
26
|
-
const importPrelude = statements(`
|
|
27
|
-
function ${importDefault}(moduleId) {
|
|
28
|
-
const exports = require(moduleId);
|
|
29
|
-
|
|
30
|
-
if (exports && exports.__esModule) {
|
|
31
|
-
return exports.default;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return exports;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function ${importAll}(moduleId) {
|
|
38
|
-
const exports = require(moduleId);
|
|
39
|
-
|
|
40
|
-
if (exports && exports.__esModule) {
|
|
41
|
-
return exports;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return Object.assign({}, exports, {default: exports});
|
|
45
|
-
};
|
|
46
|
-
`);
|
|
47
|
-
|
|
48
|
-
const {
|
|
49
|
-
transformSync: babelTransformSync,
|
|
50
|
-
transformFromAstSync: babelTransformFromAstSync,
|
|
51
|
-
} = require('@babel/core');
|
|
19
|
+
const {transformSync: babelTransformSync} = require('@babel/core');
|
|
52
20
|
const generate = require('@babel/generator').default;
|
|
53
21
|
|
|
54
22
|
const nodeFiles = new RegExp(
|
|
@@ -73,13 +41,13 @@ module.exports = {
|
|
|
73
41
|
}).code;
|
|
74
42
|
}
|
|
75
43
|
|
|
76
|
-
|
|
44
|
+
const {ast} = transformer.transform({
|
|
77
45
|
filename: file,
|
|
78
46
|
options: {
|
|
79
47
|
ast: true, // needed for open source (?) https://github.com/facebook/react-native/commit/f8d6b97140cffe8d18b2558f94570c8d1b410d5c#r28647044
|
|
80
48
|
dev: true,
|
|
81
49
|
enableBabelRuntime: false,
|
|
82
|
-
experimentalImportSupport:
|
|
50
|
+
experimentalImportSupport: false,
|
|
83
51
|
globalPrefix: '',
|
|
84
52
|
hot: false,
|
|
85
53
|
inlineRequires: true,
|
|
@@ -111,6 +79,10 @@ module.exports = {
|
|
|
111
79
|
[require('@babel/plugin-transform-regenerator')],
|
|
112
80
|
[require('@babel/plugin-transform-sticky-regex')],
|
|
113
81
|
[require('@babel/plugin-transform-unicode-regex')],
|
|
82
|
+
[
|
|
83
|
+
require('@babel/plugin-transform-modules-commonjs'),
|
|
84
|
+
{strict: false, allowTopLevelThis: true},
|
|
85
|
+
],
|
|
114
86
|
[require('@babel/plugin-transform-classes')],
|
|
115
87
|
[require('@babel/plugin-transform-arrow-functions')],
|
|
116
88
|
[require('@babel/plugin-transform-spread')],
|
|
@@ -127,46 +99,6 @@ module.exports = {
|
|
|
127
99
|
],
|
|
128
100
|
});
|
|
129
101
|
|
|
130
|
-
// We're not using @babel/plugin-transform-modules-commonjs so
|
|
131
|
-
// we need to add 'use strict' manually
|
|
132
|
-
const directives = ast.program.directives;
|
|
133
|
-
|
|
134
|
-
if (
|
|
135
|
-
ast.program.sourceType === 'module' &&
|
|
136
|
-
(directives == null ||
|
|
137
|
-
directives.findIndex(d => d.value.value === 'use strict') === -1)
|
|
138
|
-
) {
|
|
139
|
-
ast.program.directives = [
|
|
140
|
-
...(directives || []),
|
|
141
|
-
t.directive(t.directiveLiteral('use strict')),
|
|
142
|
-
];
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Postprocess the transformed module to handle ESM and inline requires.
|
|
146
|
-
// We need to do this in a separate pass to avoid issues tracking references.
|
|
147
|
-
const babelTransformResult = babelTransformFromAstSync(ast, src, {
|
|
148
|
-
ast: true,
|
|
149
|
-
retainLines: true,
|
|
150
|
-
plugins: [
|
|
151
|
-
[
|
|
152
|
-
require('metro-transform-plugins').importExportPlugin,
|
|
153
|
-
{importDefault, importAll},
|
|
154
|
-
],
|
|
155
|
-
[
|
|
156
|
-
require('babel-preset-fbjs/plugins/inline-requires.js'),
|
|
157
|
-
{inlineableCalls: [importDefault, importAll]},
|
|
158
|
-
],
|
|
159
|
-
],
|
|
160
|
-
sourceType: 'module',
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
ast = nullthrows(babelTransformResult.ast);
|
|
164
|
-
|
|
165
|
-
// Inject import helpers *after* running the inline-requires transform,
|
|
166
|
-
// because otherwise it will assume they are user code and bail out of
|
|
167
|
-
// inlining calls to them.
|
|
168
|
-
ast.program.body.unshift(...importPrelude());
|
|
169
|
-
|
|
170
102
|
return generate(
|
|
171
103
|
ast,
|
|
172
104
|
// $FlowFixMe[prop-missing] Error found when improving flow typing for libs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-windows",
|
|
3
|
-
"version": "0.67.0
|
|
3
|
+
"version": "0.67.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@react-native-community/cli": "^6.0.0",
|
|
27
27
|
"@react-native-community/cli-platform-android": "^6.0.0",
|
|
28
28
|
"@react-native-community/cli-platform-ios": "^6.0.0",
|
|
29
|
-
"@react-native-windows/cli": "0.67.0
|
|
30
|
-
"@react-native-windows/virtualized-list": "0.67.0
|
|
29
|
+
"@react-native-windows/cli": "0.67.0",
|
|
30
|
+
"@react-native-windows/virtualized-list": "0.67.0",
|
|
31
31
|
"@react-native/assets": "1.0.0",
|
|
32
32
|
"@react-native/normalize-color": "2.0.0",
|
|
33
33
|
"@react-native/polyfills": "2.0.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"ws": "^6.1.4"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@react-native-windows/codegen": "0.67.0
|
|
60
|
+
"@react-native-windows/codegen": "0.67.0",
|
|
61
61
|
"@rnw-scripts/eslint-config": "1.1.8",
|
|
62
62
|
"@rnw-scripts/jest-out-of-tree-snapshot-resolver": "^1.0.2",
|
|
63
63
|
"@rnx-kit/jest-preset": "^0.1.0",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"metro-config": "^0.66.0",
|
|
73
73
|
"prettier": "1.19.1",
|
|
74
74
|
"react": "17.0.2",
|
|
75
|
-
"react-native": "0.67.
|
|
75
|
+
"react-native": "0.67.1",
|
|
76
76
|
"react-native-platform-override": "^1.5.1",
|
|
77
77
|
"react-refresh": "^0.4.0",
|
|
78
78
|
"react-shallow-renderer": "16.14.1",
|
|
@@ -80,15 +80,15 @@
|
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"react": "17.0.2",
|
|
83
|
-
"react-native": "0.67.0
|
|
83
|
+
"react-native": "^0.67.0"
|
|
84
84
|
},
|
|
85
85
|
"beachball": {
|
|
86
|
-
"defaultNpmTag": "
|
|
86
|
+
"defaultNpmTag": "latest",
|
|
87
87
|
"gitTags": true,
|
|
88
88
|
"disallowedChangeTypes": [
|
|
89
89
|
"major",
|
|
90
90
|
"minor",
|
|
91
|
-
"
|
|
91
|
+
"prerelease"
|
|
92
92
|
]
|
|
93
93
|
},
|
|
94
94
|
"files": [
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
{{#nuGetTestFeed}}
|
|
9
9
|
<add key="NuGetTestFeed" value="{{ nuGetTestFeed }}" />
|
|
10
10
|
{{/nuGetTestFeed}}
|
|
11
|
+
{{#nuGetADOFeed}}
|
|
11
12
|
<add key="react-native" value="https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/nuget/v3/index.json" />
|
|
13
|
+
{{/nuGetADOFeed}}
|
|
12
14
|
<add key="Nuget.org" value="https://api.nuget.org/v3/index.json" />
|
|
13
15
|
</packageSources>
|
|
14
16
|
<disabledPackageSources>
|