@epicgames-ps/lib-pixelstreamingfrontend-ue5.5 0.0.5

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.
Files changed (138) hide show
  1. package/.cspell.json +48 -0
  2. package/.eslintignore +8 -0
  3. package/.eslintrc.js +8 -0
  4. package/.prettierignore +0 -0
  5. package/.prettierrc.json +6 -0
  6. package/dist/lib-pixelstreamingfrontend.esm.js +1 -0
  7. package/dist/lib-pixelstreamingfrontend.js +1 -0
  8. package/jest.config.js +18 -0
  9. package/package.json +48 -0
  10. package/readme.md +15 -0
  11. package/src/AFK/AFKController.test.ts +162 -0
  12. package/src/AFK/AFKController.ts +158 -0
  13. package/src/Config/Config.test.ts +222 -0
  14. package/src/Config/Config.ts +970 -0
  15. package/src/Config/SettingBase.ts +65 -0
  16. package/src/Config/SettingFlag.ts +99 -0
  17. package/src/Config/SettingNumber.ts +111 -0
  18. package/src/Config/SettingOption.ts +124 -0
  19. package/src/Config/SettingText.ts +82 -0
  20. package/src/DataChannel/DataChannelController.ts +138 -0
  21. package/src/DataChannel/DataChannelLatencyTestController.ts +129 -0
  22. package/src/DataChannel/DataChannelLatencyTestResults.ts +67 -0
  23. package/src/DataChannel/DataChannelSender.ts +59 -0
  24. package/src/DataChannel/InitialSettings.ts +61 -0
  25. package/src/DataChannel/LatencyTestResults.ts +76 -0
  26. package/src/FreezeFrame/FreezeFrame.ts +114 -0
  27. package/src/FreezeFrame/FreezeFrameController.ts +114 -0
  28. package/src/Inputs/FakeTouchController.ts +199 -0
  29. package/src/Inputs/GamepadController.ts +314 -0
  30. package/src/Inputs/GamepadTypes.ts +10 -0
  31. package/src/Inputs/HoveringMouseEvents.ts +192 -0
  32. package/src/Inputs/IMouseEvents.ts +64 -0
  33. package/src/Inputs/ITouchController.ts +29 -0
  34. package/src/Inputs/InputClassesFactory.ts +140 -0
  35. package/src/Inputs/KeyboardController.ts +354 -0
  36. package/src/Inputs/LockedMouseEvents.ts +287 -0
  37. package/src/Inputs/MouseButtons.ts +25 -0
  38. package/src/Inputs/MouseController.ts +362 -0
  39. package/src/Inputs/SpecialKeyCodes.ts +16 -0
  40. package/src/Inputs/TouchController.ts +208 -0
  41. package/src/Inputs/XRGamepadController.ts +126 -0
  42. package/src/PeerConnectionController/AggregatedStats.ts +311 -0
  43. package/src/PeerConnectionController/CandidatePairStats.ts +17 -0
  44. package/src/PeerConnectionController/CandidateStat.ts +13 -0
  45. package/src/PeerConnectionController/CodecStats.ts +19 -0
  46. package/src/PeerConnectionController/DataChannelStats.ts +17 -0
  47. package/src/PeerConnectionController/InboundRTPStats.ts +154 -0
  48. package/src/PeerConnectionController/InboundTrackStats.ts +34 -0
  49. package/src/PeerConnectionController/OutBoundRTPStats.ts +26 -0
  50. package/src/PeerConnectionController/PeerConnectionController.ts +563 -0
  51. package/src/PeerConnectionController/SessionStats.ts +10 -0
  52. package/src/PeerConnectionController/StreamStats.ts +11 -0
  53. package/src/PixelStreaming/PixelStreaming.test.ts +626 -0
  54. package/src/PixelStreaming/PixelStreaming.ts +851 -0
  55. package/src/UI/OnScreenKeyboard.ts +97 -0
  56. package/src/UeInstanceMessage/ResponseController.ts +47 -0
  57. package/src/UeInstanceMessage/SendMessageController.ts +154 -0
  58. package/src/UeInstanceMessage/StreamMessageController.ts +233 -0
  59. package/src/UeInstanceMessage/ToStreamerMessagesController.ts +62 -0
  60. package/src/Util/CoordinateConverter.ts +289 -0
  61. package/src/Util/EventEmitter.ts +611 -0
  62. package/src/Util/EventListenerTracker.ts +29 -0
  63. package/src/Util/FileUtil.ts +140 -0
  64. package/src/Util/RTCUtils.ts +41 -0
  65. package/src/Util/WebGLUtils.ts +49 -0
  66. package/src/Util/WebXRUtils.ts +25 -0
  67. package/src/VideoPlayer/StreamController.ts +89 -0
  68. package/src/VideoPlayer/VideoPlayer.ts +246 -0
  69. package/src/WebRtcPlayer/WebRtcPlayerController.ts +2158 -0
  70. package/src/WebXR/WebXRController.ts +319 -0
  71. package/src/__test__/mockMediaStream.ts +124 -0
  72. package/src/__test__/mockRTCPeerConnection.ts +347 -0
  73. package/src/__test__/mockRTCRtpReceiver.ts +22 -0
  74. package/src/__test__/mockWebSocket.ts +136 -0
  75. package/src/pixelstreamingfrontend.ts +46 -0
  76. package/tsconfig.jest.json +8 -0
  77. package/tsconfig.json +24 -0
  78. package/types/AFK/AFKController.d.ts +39 -0
  79. package/types/Config/Config.d.ts +218 -0
  80. package/types/Config/SettingBase.d.ts +30 -0
  81. package/types/Config/SettingFlag.d.ts +33 -0
  82. package/types/Config/SettingNumber.d.ts +45 -0
  83. package/types/Config/SettingOption.d.ts +43 -0
  84. package/types/Config/SettingText.d.ts +29 -0
  85. package/types/DataChannel/DataChannelController.d.ts +59 -0
  86. package/types/DataChannel/DataChannelLatencyTestController.d.ts +26 -0
  87. package/types/DataChannel/DataChannelLatencyTestResults.d.ts +46 -0
  88. package/types/DataChannel/DataChannelSender.d.ts +21 -0
  89. package/types/DataChannel/InitialSettings.d.ts +44 -0
  90. package/types/DataChannel/LatencyTestResults.d.ts +31 -0
  91. package/types/FreezeFrame/FreezeFrame.d.ts +36 -0
  92. package/types/FreezeFrame/FreezeFrameController.d.ts +37 -0
  93. package/types/Inputs/FakeTouchController.d.ts +61 -0
  94. package/types/Inputs/GamepadController.d.ts +85 -0
  95. package/types/Inputs/GamepadTypes.d.ts +8 -0
  96. package/types/Inputs/HoveringMouseEvents.d.ts +56 -0
  97. package/types/Inputs/IMouseEvents.d.ts +53 -0
  98. package/types/Inputs/ITouchController.d.ts +24 -0
  99. package/types/Inputs/InputClassesFactory.d.ts +54 -0
  100. package/types/Inputs/KeyboardController.d.ts +62 -0
  101. package/types/Inputs/LockedMouseEvents.d.ts +80 -0
  102. package/types/Inputs/MouseButtons.d.ts +22 -0
  103. package/types/Inputs/MouseController.d.ts +75 -0
  104. package/types/Inputs/SpecialKeyCodes.d.ts +14 -0
  105. package/types/Inputs/TouchController.d.ts +53 -0
  106. package/types/Inputs/XRGamepadController.d.ts +15 -0
  107. package/types/PeerConnectionController/AggregatedStats.d.ts +77 -0
  108. package/types/PeerConnectionController/CandidatePairStats.d.ts +15 -0
  109. package/types/PeerConnectionController/CandidateStat.d.ts +11 -0
  110. package/types/PeerConnectionController/CodecStats.d.ts +14 -0
  111. package/types/PeerConnectionController/DataChannelStats.d.ts +15 -0
  112. package/types/PeerConnectionController/InboundRTPStats.d.ts +141 -0
  113. package/types/PeerConnectionController/InboundTrackStats.d.ts +32 -0
  114. package/types/PeerConnectionController/OutBoundRTPStats.d.ts +23 -0
  115. package/types/PeerConnectionController/PeerConnectionController.d.ts +132 -0
  116. package/types/PeerConnectionController/SessionStats.d.ts +8 -0
  117. package/types/PeerConnectionController/StreamStats.d.ts +9 -0
  118. package/types/PixelStreaming/PixelStreaming.d.ts +259 -0
  119. package/types/UI/OnScreenKeyboard.d.ts +31 -0
  120. package/types/UeInstanceMessage/ResponseController.d.ts +19 -0
  121. package/types/UeInstanceMessage/SendMessageController.d.ts +18 -0
  122. package/types/UeInstanceMessage/StreamMessageController.d.ts +29 -0
  123. package/types/UeInstanceMessage/ToStreamerMessagesController.d.ts +32 -0
  124. package/types/Util/CoordinateConverter.d.ts +100 -0
  125. package/types/Util/EventEmitter.d.ts +422 -0
  126. package/types/Util/EventListenerTracker.d.ts +14 -0
  127. package/types/Util/FileUtil.d.ts +32 -0
  128. package/types/Util/RTCUtils.d.ts +8 -0
  129. package/types/Util/WebGLUtils.d.ts +4 -0
  130. package/types/Util/WebXRUtils.d.ts +9 -0
  131. package/types/VideoPlayer/StreamController.d.ts +24 -0
  132. package/types/VideoPlayer/VideoPlayer.d.ts +78 -0
  133. package/types/WebRtcPlayer/WebRtcPlayerController.d.ts +377 -0
  134. package/types/WebXR/WebXRController.d.ts +26 -0
  135. package/types/pixelstreamingfrontend.d.ts +22 -0
  136. package/webpack.common.js +35 -0
  137. package/webpack.dev.js +35 -0
  138. package/webpack.prod.js +36 -0
@@ -0,0 +1,289 @@
1
+ // Copyright Epic Games, Inc. All Rights Reserved.
2
+
3
+ import { Logger } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';
4
+ import { VideoPlayer } from '../VideoPlayer/VideoPlayer';
5
+
6
+ /**
7
+ * Converts coordinates from element relative coordinates to values normalized within the value range of a short (and back again)
8
+ */
9
+ export class CoordinateConverter {
10
+ videoElementProvider: VideoPlayer;
11
+ videoElementParent: HTMLElement;
12
+ videoElement: HTMLVideoElement;
13
+ ratio: number;
14
+
15
+ normalizeAndQuantizeUnsignedFunc: (
16
+ x: number,
17
+ y: number
18
+ ) => NormalizedQuantizedUnsignedCoord;
19
+ normalizeAndQuantizeSignedFunc: (
20
+ x: number,
21
+ y: number
22
+ ) => NormalizedQuantizedSignedCoord;
23
+ denormalizeAndUnquantizeUnsignedFunc: (
24
+ x: number,
25
+ y: number
26
+ ) => UnquantizedDenormalizedUnsignedCoord;
27
+
28
+ /**
29
+ * @param videoElementProvider - the div element that the video player will be injected into
30
+ */
31
+ constructor(videoElementProvider: VideoPlayer) {
32
+ this.videoElementProvider = videoElementProvider;
33
+ this.normalizeAndQuantizeUnsignedFunc = () => {
34
+ throw new Error(
35
+ 'Normalize and quantize unsigned, method not implemented.'
36
+ );
37
+ };
38
+ this.normalizeAndQuantizeSignedFunc = () => {
39
+ throw new Error(
40
+ 'Normalize and unquantize signed, method not implemented.'
41
+ );
42
+ };
43
+ this.denormalizeAndUnquantizeUnsignedFunc = () => {
44
+ throw new Error(
45
+ 'Denormalize and unquantize unsigned, method not implemented.'
46
+ );
47
+ };
48
+ }
49
+
50
+ /**
51
+ * The surface method for setterNormalizeAndQuantizeUnsigned
52
+ * @param x - x axis point
53
+ * @param y - y axis point
54
+ */
55
+ normalizeAndQuantizeUnsigned(
56
+ x: number,
57
+ y: number
58
+ ): NormalizedQuantizedUnsignedCoord {
59
+ return this.normalizeAndQuantizeUnsignedFunc(x, y);
60
+ }
61
+
62
+ /**
63
+ * The surface method for setterUnquantizeAndDenormalizeUnsigned
64
+ * @param x - x axis point
65
+ * @param y - y axis point
66
+ */
67
+ unquantizeAndDenormalizeUnsigned(
68
+ x: number,
69
+ y: number
70
+ ): UnquantizedDenormalizedUnsignedCoord {
71
+ return this.denormalizeAndUnquantizeUnsignedFunc(x, y);
72
+ }
73
+
74
+ /**
75
+ * The surface method for setterNormalizeAndQuantizeSigned
76
+ * @param x - x axis point
77
+ * @param y - y axis point
78
+ */
79
+ normalizeAndQuantizeSigned(
80
+ x: number,
81
+ y: number
82
+ ): NormalizedQuantizedSignedCoord {
83
+ return this.normalizeAndQuantizeSignedFunc(x, y);
84
+ }
85
+
86
+ /**
87
+ * set up the Normalize And Quantize methods based on the aspect ratio and the video player ratio
88
+ */
89
+ setupNormalizeAndQuantize() {
90
+ this.videoElementParent =
91
+ this.videoElementProvider.getVideoParentElement();
92
+ this.videoElement = this.videoElementProvider.getVideoElement();
93
+
94
+ if (this.videoElementParent && this.videoElement) {
95
+ const playerAspectRatio =
96
+ this.videoElementParent.clientHeight /
97
+ this.videoElementParent.clientWidth;
98
+ const videoAspectRatio =
99
+ this.videoElement.videoHeight / this.videoElement.videoWidth;
100
+ if (playerAspectRatio > videoAspectRatio) {
101
+ Logger.Log(
102
+ Logger.GetStackTrace(),
103
+ 'Setup Normalize and Quantize for playerAspectRatio > videoAspectRatio',
104
+ 6
105
+ );
106
+ this.ratio = playerAspectRatio / videoAspectRatio;
107
+ this.normalizeAndQuantizeUnsignedFunc = (
108
+ x: number,
109
+ y: number
110
+ ) => this.normalizeAndQuantizeUnsignedPlayerBigger(x, y);
111
+ this.normalizeAndQuantizeSignedFunc = (x: number, y: number) =>
112
+ this.normalizeAndQuantizeSignedPlayerBigger(x, y);
113
+ this.denormalizeAndUnquantizeUnsignedFunc = (
114
+ x: number,
115
+ y: number
116
+ ) => this.denormalizeAndUnquantizeUnsignedPlayerBigger(x, y);
117
+ } else {
118
+ Logger.Log(
119
+ Logger.GetStackTrace(),
120
+ 'Setup Normalize and Quantize for playerAspectRatio <= videoAspectRatio',
121
+ 6
122
+ );
123
+ this.ratio = videoAspectRatio / playerAspectRatio;
124
+ this.normalizeAndQuantizeUnsignedFunc = (
125
+ x: number,
126
+ y: number
127
+ ) => this.normalizeAndQuantizeUnsignedPlayerSmaller(x, y);
128
+ this.normalizeAndQuantizeSignedFunc = (x: number, y: number) =>
129
+ this.normalizeAndQuantizeSignedPlayerSmaller(x, y);
130
+ this.denormalizeAndUnquantizeUnsignedFunc = (
131
+ x: number,
132
+ y: number
133
+ ) => this.denormalizeAndUnquantizeUnsignedPlayerSmaller(x, y);
134
+ }
135
+ }
136
+ }
137
+
138
+ /**
139
+ * normalizeAndQuantizeUnsigned for playerAspectRatio > videoAspectRatio
140
+ * @param x - x axis point
141
+ * @param y - y axis point
142
+ */
143
+ normalizeAndQuantizeUnsignedPlayerBigger(
144
+ x: number,
145
+ y: number
146
+ ): NormalizedQuantizedUnsignedCoord {
147
+ const normalizedX = x / this.videoElementParent.clientWidth;
148
+ const normalizedY =
149
+ this.ratio * (y / this.videoElementParent.clientHeight - 0.5) + 0.5;
150
+ if (
151
+ normalizedX < 0.0 ||
152
+ normalizedX > 1.0 ||
153
+ normalizedY < 0.0 ||
154
+ normalizedY > 1.0
155
+ ) {
156
+ return new NormalizedQuantizedUnsignedCoord(false, 65535, 65535);
157
+ } else {
158
+ return new NormalizedQuantizedUnsignedCoord(
159
+ true,
160
+ normalizedX * 65536,
161
+ normalizedY * 65536
162
+ );
163
+ }
164
+ }
165
+
166
+ /**
167
+ * unquantizeAndDenormalizeUnsigned for playerAspectRatio > videoAspectRatio
168
+ * @param x - x axis point
169
+ * @param y - y axis point
170
+ */
171
+ denormalizeAndUnquantizeUnsignedPlayerBigger(x: number, y: number) {
172
+ const normalizedX = x / 65536;
173
+ const normalizedY = (y / 65536 - 0.5) / this.ratio + 0.5;
174
+ return new UnquantizedDenormalizedUnsignedCoord(
175
+ normalizedX * this.videoElementParent.clientWidth,
176
+ normalizedY * this.videoElementParent.clientHeight
177
+ );
178
+ }
179
+
180
+ /**
181
+ * normalizeAndQuantizeSigned for playerAspectRatio > videoAspectRatio
182
+ * @param x - x axis point
183
+ * @param y - y axis point
184
+ */
185
+ normalizeAndQuantizeSignedPlayerBigger(x: number, y: number) {
186
+ const normalizedX = x / (0.5 * this.videoElementParent.clientWidth);
187
+ const normalizedY =
188
+ (this.ratio * y) / (0.5 * this.videoElementParent.clientHeight);
189
+ return new NormalizedQuantizedSignedCoord(
190
+ normalizedX * 32767,
191
+ normalizedY * 32767
192
+ );
193
+ }
194
+
195
+ /**
196
+ * normalizeAndQuantizeUnsigned for playerAspectRatio <= videoAspectRatio
197
+ * @param x - x axis point
198
+ * @param y - y axis point
199
+ */
200
+ normalizeAndQuantizeUnsignedPlayerSmaller(x: number, y: number) {
201
+ const normalizedX =
202
+ this.ratio * (x / this.videoElementParent.clientWidth - 0.5) + 0.5;
203
+ const normalizedY = y / this.videoElementParent.clientHeight;
204
+ if (
205
+ normalizedX < 0.0 ||
206
+ normalizedX > 1.0 ||
207
+ normalizedY < 0.0 ||
208
+ normalizedY > 1.0
209
+ ) {
210
+ return new NormalizedQuantizedUnsignedCoord(false, 65535, 65535);
211
+ } else {
212
+ return new NormalizedQuantizedUnsignedCoord(
213
+ true,
214
+ normalizedX * 65536,
215
+ normalizedY * 65536
216
+ );
217
+ }
218
+ }
219
+
220
+ /**
221
+ * unquantizeAndDenormalizeUnsigned for playerAspectRatio <= videoAspectRatio
222
+ * @param x - x axis point
223
+ * @param y - y axis point
224
+ */
225
+ denormalizeAndUnquantizeUnsignedPlayerSmaller(x: number, y: number) {
226
+ const normalizedX = (x / 65536 - 0.5) / this.ratio + 0.5;
227
+ const normalizedY = y / 65536;
228
+ return new UnquantizedDenormalizedUnsignedCoord(
229
+ normalizedX * this.videoElementParent.clientWidth,
230
+ normalizedY * this.videoElementParent.clientHeight
231
+ );
232
+ }
233
+
234
+ /**
235
+ * normalizeAndQuantizeSigned for playerAspectRatio <= videoAspectRatio
236
+ * @param x - x axis point
237
+ * @param y - y axis point
238
+ */
239
+ normalizeAndQuantizeSignedPlayerSmaller(x: number, y: number) {
240
+ const normalizedX =
241
+ (this.ratio * x) / (0.5 * this.videoElementParent.clientWidth);
242
+ const normalizedY = y / (0.5 * this.videoElementParent.clientHeight);
243
+ return new NormalizedQuantizedSignedCoord(
244
+ normalizedX * 32767,
245
+ normalizedY * 32767
246
+ );
247
+ }
248
+ }
249
+
250
+ /**
251
+ * A class for NormalizeAndQuantizeUnsigned objects
252
+ */
253
+ export class NormalizedQuantizedUnsignedCoord {
254
+ inRange: boolean;
255
+ x: number;
256
+ y: number;
257
+
258
+ constructor(inRange: boolean, x: number, y: number) {
259
+ this.inRange = inRange;
260
+ this.x = x;
261
+ this.y = y;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * A class for UnquantizedAndDenormalizeUnsigned objects
267
+ */
268
+ export class UnquantizedDenormalizedUnsignedCoord {
269
+ x: number;
270
+ y: number;
271
+
272
+ constructor(x: number, y: number) {
273
+ this.x = x;
274
+ this.y = y;
275
+ }
276
+ }
277
+
278
+ /**
279
+ * A class for NormalizedQuantizedSignedCoord objects
280
+ */
281
+ export class NormalizedQuantizedSignedCoord {
282
+ x: number;
283
+ y: number;
284
+
285
+ constructor(x: number, y: number) {
286
+ this.x = x;
287
+ this.y = y;
288
+ }
289
+ }