@epicgames-ps/lib-pixelstreamingfrontend-ue5.5 0.3.0 → 0.3.1

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 (169) hide show
  1. package/dist/commonjs/AFK/AFKController.js +109 -109
  2. package/dist/commonjs/Config/Config.js +559 -559
  3. package/dist/commonjs/Config/SettingBase.js +98 -98
  4. package/dist/commonjs/Config/SettingFlag.js +49 -49
  5. package/dist/commonjs/Config/SettingNumber.js +83 -83
  6. package/dist/commonjs/Config/SettingOption.js +84 -84
  7. package/dist/commonjs/Config/SettingText.js +42 -42
  8. package/dist/commonjs/DataChannel/DataChannelController.js +106 -106
  9. package/dist/commonjs/DataChannel/DataChannelLatencyTestController.js +94 -94
  10. package/dist/commonjs/DataChannel/DataChannelLatencyTestResults.js +18 -18
  11. package/dist/commonjs/DataChannel/DataChannelSender.js +43 -43
  12. package/dist/commonjs/DataChannel/InitialSettings.js +41 -41
  13. package/dist/commonjs/DataChannel/LatencyTestResults.js +60 -60
  14. package/dist/commonjs/FreezeFrame/FreezeFrame.js +93 -93
  15. package/dist/commonjs/FreezeFrame/FreezeFrameController.js +95 -95
  16. package/dist/commonjs/Inputs/GamepadController.js +188 -188
  17. package/dist/commonjs/Inputs/GamepadTypes.js +21 -21
  18. package/dist/commonjs/Inputs/IInputController.js +2 -2
  19. package/dist/commonjs/Inputs/InputClassesFactory.js +96 -96
  20. package/dist/commonjs/Inputs/KeyCodes.js +112 -112
  21. package/dist/commonjs/Inputs/KeyboardController.js +137 -137
  22. package/dist/commonjs/Inputs/MouseButtons.js +28 -28
  23. package/dist/commonjs/Inputs/MouseController.js +97 -97
  24. package/dist/commonjs/Inputs/MouseControllerHovering.js +93 -93
  25. package/dist/commonjs/Inputs/MouseControllerLocked.js +153 -153
  26. package/dist/commonjs/Inputs/SpecialKeyCodes.js +19 -19
  27. package/dist/commonjs/Inputs/TouchController.js +123 -123
  28. package/dist/commonjs/Inputs/TouchControllerFake.js +91 -91
  29. package/dist/commonjs/Inputs/XRGamepadController.js +124 -124
  30. package/dist/commonjs/PeerConnectionController/AggregatedStats.js +252 -252
  31. package/dist/commonjs/PeerConnectionController/CandidatePairStats.js +10 -10
  32. package/dist/commonjs/PeerConnectionController/CandidateStat.js +10 -10
  33. package/dist/commonjs/PeerConnectionController/CodecStats.js +10 -10
  34. package/dist/commonjs/PeerConnectionController/DataChannelStats.js +10 -10
  35. package/dist/commonjs/PeerConnectionController/InboundRTPStats.js +22 -22
  36. package/dist/commonjs/PeerConnectionController/InboundTrackStats.js +10 -10
  37. package/dist/commonjs/PeerConnectionController/OutBoundRTPStats.js +16 -16
  38. package/dist/commonjs/PeerConnectionController/PeerConnectionController.js +584 -584
  39. package/dist/commonjs/PeerConnectionController/SessionStats.js +10 -10
  40. package/dist/commonjs/PeerConnectionController/StreamStats.js +10 -10
  41. package/dist/commonjs/PixelStreaming/PixelStreaming.js +607 -607
  42. package/dist/commonjs/UI/OnScreenKeyboard.js +82 -82
  43. package/dist/commonjs/UeInstanceMessage/ResponseController.js +38 -38
  44. package/dist/commonjs/UeInstanceMessage/SendMessageController.js +120 -120
  45. package/dist/commonjs/UeInstanceMessage/StreamMessageController.js +210 -210
  46. package/dist/commonjs/UeInstanceMessage/ToStreamerMessagesController.js +49 -49
  47. package/dist/commonjs/Util/EventEmitter.js +386 -386
  48. package/dist/commonjs/Util/FileUtil.js +108 -108
  49. package/dist/commonjs/Util/IURLSearchParams.js +25 -25
  50. package/dist/commonjs/Util/InputCoordTranslator.js +49 -49
  51. package/dist/commonjs/Util/RTCUtils.js +40 -40
  52. package/dist/commonjs/VideoPlayer/StreamController.js +67 -67
  53. package/dist/commonjs/VideoPlayer/VideoPlayer.js +177 -177
  54. package/dist/commonjs/WebRtcPlayer/WebRtcPlayerController.js +1221 -1221
  55. package/dist/commonjs/WebXR/WebXRController.js +335 -335
  56. package/dist/commonjs/pixelstreamingfrontend.js +70 -70
  57. package/dist/esm/AFK/AFKController.js +105 -105
  58. package/dist/esm/Config/Config.js +551 -551
  59. package/dist/esm/Config/SettingBase.js +94 -94
  60. package/dist/esm/Config/SettingFlag.js +45 -45
  61. package/dist/esm/Config/SettingNumber.js +79 -79
  62. package/dist/esm/Config/SettingOption.js +80 -80
  63. package/dist/esm/Config/SettingText.js +38 -38
  64. package/dist/esm/DataChannel/DataChannelController.js +102 -102
  65. package/dist/esm/DataChannel/DataChannelLatencyTestController.js +90 -90
  66. package/dist/esm/DataChannel/DataChannelLatencyTestResults.js +14 -14
  67. package/dist/esm/DataChannel/DataChannelSender.js +39 -39
  68. package/dist/esm/DataChannel/InitialSettings.js +34 -34
  69. package/dist/esm/DataChannel/LatencyTestResults.js +56 -56
  70. package/dist/esm/FreezeFrame/FreezeFrame.js +89 -89
  71. package/dist/esm/FreezeFrame/FreezeFrameController.js +91 -91
  72. package/dist/esm/Inputs/GamepadController.js +184 -184
  73. package/dist/esm/Inputs/GamepadTypes.js +17 -17
  74. package/dist/esm/Inputs/IInputController.js +1 -1
  75. package/dist/esm/Inputs/InputClassesFactory.js +91 -91
  76. package/dist/esm/Inputs/KeyCodes.js +109 -109
  77. package/dist/esm/Inputs/KeyboardController.js +133 -133
  78. package/dist/esm/Inputs/MouseButtons.js +23 -23
  79. package/dist/esm/Inputs/MouseController.js +93 -93
  80. package/dist/esm/Inputs/MouseControllerHovering.js +89 -89
  81. package/dist/esm/Inputs/MouseControllerLocked.js +149 -149
  82. package/dist/esm/Inputs/SpecialKeyCodes.js +15 -15
  83. package/dist/esm/Inputs/TouchController.js +119 -119
  84. package/dist/esm/Inputs/TouchControllerFake.js +87 -87
  85. package/dist/esm/Inputs/XRGamepadController.js +120 -120
  86. package/dist/esm/PeerConnectionController/AggregatedStats.js +248 -248
  87. package/dist/esm/PeerConnectionController/CandidatePairStats.js +6 -6
  88. package/dist/esm/PeerConnectionController/CandidateStat.js +6 -6
  89. package/dist/esm/PeerConnectionController/CodecStats.js +6 -6
  90. package/dist/esm/PeerConnectionController/DataChannelStats.js +6 -6
  91. package/dist/esm/PeerConnectionController/InboundRTPStats.js +16 -16
  92. package/dist/esm/PeerConnectionController/InboundTrackStats.js +6 -6
  93. package/dist/esm/PeerConnectionController/OutBoundRTPStats.js +11 -11
  94. package/dist/esm/PeerConnectionController/PeerConnectionController.js +580 -580
  95. package/dist/esm/PeerConnectionController/SessionStats.js +6 -6
  96. package/dist/esm/PeerConnectionController/StreamStats.js +6 -6
  97. package/dist/esm/PixelStreaming/PixelStreaming.js +603 -603
  98. package/dist/esm/UI/OnScreenKeyboard.js +78 -78
  99. package/dist/esm/UeInstanceMessage/ResponseController.js +34 -34
  100. package/dist/esm/UeInstanceMessage/SendMessageController.js +116 -116
  101. package/dist/esm/UeInstanceMessage/StreamMessageController.js +205 -205
  102. package/dist/esm/UeInstanceMessage/ToStreamerMessagesController.js +45 -45
  103. package/dist/esm/Util/EventEmitter.js +345 -345
  104. package/dist/esm/Util/FileUtil.js +103 -103
  105. package/dist/esm/Util/IURLSearchParams.js +21 -21
  106. package/dist/esm/Util/InputCoordTranslator.js +45 -45
  107. package/dist/esm/Util/RTCUtils.js +36 -36
  108. package/dist/esm/VideoPlayer/StreamController.js +63 -63
  109. package/dist/esm/VideoPlayer/VideoPlayer.js +173 -173
  110. package/dist/esm/WebRtcPlayer/WebRtcPlayerController.js +1217 -1217
  111. package/dist/esm/WebXR/WebXRController.js +331 -331
  112. package/dist/esm/pixelstreamingfrontend.js +24 -24
  113. package/dist/types/AFK/AFKController.d.ts +38 -38
  114. package/dist/types/Config/Config.d.ts +220 -220
  115. package/dist/types/Config/SettingBase.d.ts +43 -43
  116. package/dist/types/Config/SettingFlag.d.ts +24 -24
  117. package/dist/types/Config/SettingNumber.d.ts +41 -41
  118. package/dist/types/Config/SettingOption.d.ts +41 -41
  119. package/dist/types/Config/SettingText.d.ts +21 -21
  120. package/dist/types/DataChannel/DataChannelController.d.ts +59 -59
  121. package/dist/types/DataChannel/DataChannelLatencyTestController.d.ts +25 -25
  122. package/dist/types/DataChannel/DataChannelLatencyTestResults.d.ts +46 -46
  123. package/dist/types/DataChannel/DataChannelSender.d.ts +21 -21
  124. package/dist/types/DataChannel/InitialSettings.d.ts +44 -44
  125. package/dist/types/DataChannel/LatencyTestResults.d.ts +31 -31
  126. package/dist/types/FreezeFrame/FreezeFrame.d.ts +36 -36
  127. package/dist/types/FreezeFrame/FreezeFrameController.d.ts +37 -37
  128. package/dist/types/Inputs/GamepadController.d.ts +61 -61
  129. package/dist/types/Inputs/GamepadTypes.d.ts +15 -15
  130. package/dist/types/Inputs/IInputController.d.ts +16 -16
  131. package/dist/types/Inputs/InputClassesFactory.d.ts +53 -53
  132. package/dist/types/Inputs/KeyCodes.d.ts +5 -5
  133. package/dist/types/Inputs/KeyboardController.d.ts +34 -34
  134. package/dist/types/Inputs/MouseButtons.d.ts +22 -22
  135. package/dist/types/Inputs/MouseController.d.ts +40 -40
  136. package/dist/types/Inputs/MouseControllerHovering.d.ts +26 -26
  137. package/dist/types/Inputs/MouseControllerLocked.d.ts +31 -31
  138. package/dist/types/Inputs/SpecialKeyCodes.d.ts +14 -14
  139. package/dist/types/Inputs/TouchController.d.ts +28 -28
  140. package/dist/types/Inputs/TouchControllerFake.d.ts +29 -29
  141. package/dist/types/Inputs/XRGamepadController.d.ts +15 -15
  142. package/dist/types/PeerConnectionController/AggregatedStats.d.ts +82 -82
  143. package/dist/types/PeerConnectionController/CandidatePairStats.d.ts +22 -22
  144. package/dist/types/PeerConnectionController/CandidateStat.d.ts +13 -13
  145. package/dist/types/PeerConnectionController/CodecStats.d.ts +14 -14
  146. package/dist/types/PeerConnectionController/DataChannelStats.d.ts +15 -15
  147. package/dist/types/PeerConnectionController/InboundRTPStats.d.ts +141 -141
  148. package/dist/types/PeerConnectionController/InboundTrackStats.d.ts +32 -32
  149. package/dist/types/PeerConnectionController/OutBoundRTPStats.d.ts +23 -23
  150. package/dist/types/PeerConnectionController/PeerConnectionController.d.ts +143 -143
  151. package/dist/types/PeerConnectionController/SessionStats.d.ts +8 -8
  152. package/dist/types/PeerConnectionController/StreamStats.d.ts +9 -9
  153. package/dist/types/PixelStreaming/PixelStreaming.d.ts +271 -271
  154. package/dist/types/UI/OnScreenKeyboard.d.ts +30 -30
  155. package/dist/types/UeInstanceMessage/ResponseController.d.ts +19 -19
  156. package/dist/types/UeInstanceMessage/SendMessageController.d.ts +18 -18
  157. package/dist/types/UeInstanceMessage/StreamMessageController.d.ts +29 -29
  158. package/dist/types/UeInstanceMessage/ToStreamerMessagesController.d.ts +32 -32
  159. package/dist/types/Util/EventEmitter.d.ts +429 -429
  160. package/dist/types/Util/FileUtil.d.ts +32 -32
  161. package/dist/types/Util/IURLSearchParams.d.ts +9 -9
  162. package/dist/types/Util/InputCoordTranslator.d.ts +29 -29
  163. package/dist/types/Util/RTCUtils.d.ts +8 -8
  164. package/dist/types/VideoPlayer/StreamController.d.ts +22 -22
  165. package/dist/types/VideoPlayer/VideoPlayer.d.ts +78 -78
  166. package/dist/types/WebRtcPlayer/WebRtcPlayerController.d.ts +379 -379
  167. package/dist/types/WebXR/WebXRController.d.ts +42 -42
  168. package/dist/types/pixelstreamingfrontend.d.ts +23 -23
  169. package/package.json +45 -45
@@ -1,185 +1,185 @@
1
- // Copyright Epic Games, Inc. All Rights Reserved.
2
- import { deepCopyGamepad } from './GamepadTypes';
3
- /**
4
- * Gamepad layout codes enum
5
- */
6
- /* eslint-disable @typescript-eslint/no-duplicate-enum-values */
7
- export var GamepadLayout;
8
- (function (GamepadLayout) {
9
- GamepadLayout[GamepadLayout["RightClusterBottomButton"] = 0] = "RightClusterBottomButton";
10
- GamepadLayout[GamepadLayout["RightClusterRightButton"] = 1] = "RightClusterRightButton";
11
- GamepadLayout[GamepadLayout["RightClusterLeftButton"] = 2] = "RightClusterLeftButton";
12
- GamepadLayout[GamepadLayout["RightClusterTopButton"] = 3] = "RightClusterTopButton";
13
- GamepadLayout[GamepadLayout["LeftShoulder"] = 4] = "LeftShoulder";
14
- GamepadLayout[GamepadLayout["RightShoulder"] = 5] = "RightShoulder";
15
- GamepadLayout[GamepadLayout["LeftTrigger"] = 6] = "LeftTrigger";
16
- GamepadLayout[GamepadLayout["RightTrigger"] = 7] = "RightTrigger";
17
- GamepadLayout[GamepadLayout["SelectOrBack"] = 8] = "SelectOrBack";
18
- GamepadLayout[GamepadLayout["StartOrForward"] = 9] = "StartOrForward";
19
- GamepadLayout[GamepadLayout["LeftAnalogPress"] = 10] = "LeftAnalogPress";
20
- GamepadLayout[GamepadLayout["RightAnalogPress"] = 11] = "RightAnalogPress";
21
- GamepadLayout[GamepadLayout["LeftClusterTopButton"] = 12] = "LeftClusterTopButton";
22
- GamepadLayout[GamepadLayout["LeftClusterBottomButton"] = 13] = "LeftClusterBottomButton";
23
- GamepadLayout[GamepadLayout["LeftClusterLeftButton"] = 14] = "LeftClusterLeftButton";
24
- GamepadLayout[GamepadLayout["LeftClusterRightButton"] = 15] = "LeftClusterRightButton";
25
- GamepadLayout[GamepadLayout["CentreButton"] = 16] = "CentreButton";
26
- // Axes
27
- GamepadLayout[GamepadLayout["LeftStickHorizontal"] = 0] = "LeftStickHorizontal";
28
- GamepadLayout[GamepadLayout["LeftStickVertical"] = 1] = "LeftStickVertical";
29
- GamepadLayout[GamepadLayout["RightStickHorizontal"] = 2] = "RightStickHorizontal";
30
- GamepadLayout[GamepadLayout["RightStickVertical"] = 3] = "RightStickVertical";
31
- })(GamepadLayout || (GamepadLayout = {}));
32
- /* eslint-enable @typescript-eslint/no-duplicate-enum-values */
33
- /**
34
- * Handles gamepad events from the document to send to the streamer.
35
- */
36
- export class GamepadController {
37
- constructor(streamMessageController) {
38
- this.streamMessageController = streamMessageController;
39
- this.onGamepadConnectedListener = this.onGamepadConnected.bind(this);
40
- this.onGamepadDisconnectedListener = this.onGamepadDisconnected.bind(this);
41
- this.beforeUnloadListener = this.onBeforeUnload.bind(this);
42
- this.requestAnimationFrame = (window.mozRequestAnimationFrame ||
43
- window.webkitRequestAnimationFrame ||
44
- window.requestAnimationFrame).bind(window);
45
- }
46
- register() {
47
- window.addEventListener('beforeunload', this.beforeUnloadListener);
48
- const browserWindow = window;
49
- if ('GamepadEvent' in browserWindow) {
50
- window.addEventListener('gamepadconnected', this.onGamepadConnectedListener);
51
- window.addEventListener('gamepaddisconnected', this.onGamepadDisconnectedListener);
52
- }
53
- else if ('WebKitGamepadEvent' in browserWindow) {
54
- window.addEventListener('webkitgamepadconnected', this.onGamepadConnectedListener);
55
- window.addEventListener('webkitgamepaddisconnected', this.onGamepadDisconnectedListener);
56
- }
57
- this.controllers = [];
58
- if (navigator.getGamepads) {
59
- for (const gamepad of navigator.getGamepads()) {
60
- if (gamepad) {
61
- this.onGamepadConnected(new GamepadEvent('gamepadconnected', { gamepad }));
62
- }
63
- }
64
- }
65
- }
66
- unregister() {
67
- window.removeEventListener('gamepadconnected', this.onGamepadConnectedListener);
68
- window.removeEventListener('gamepaddisconnected', this.onGamepadDisconnectedListener);
69
- window.removeEventListener('webkitgamepadconnected', this.onGamepadConnectedListener);
70
- window.removeEventListener('webkitgamepaddisconnected', this.onGamepadDisconnectedListener);
71
- for (const controller of this.controllers) {
72
- if (controller.id !== undefined) {
73
- this.streamMessageController.toStreamerHandlers.get('GamepadDisconnected')([controller.id]);
74
- }
75
- }
76
- this.controllers = [];
77
- }
78
- onGamepadResponseReceived(gamepadId) {
79
- for (const controller of this.controllers) {
80
- if (controller.id === undefined) {
81
- controller.id = gamepadId;
82
- break;
83
- }
84
- }
85
- }
86
- onGamepadConnected(event) {
87
- const gamepad = event.gamepad;
88
- const newController = {
89
- currentState: deepCopyGamepad(gamepad),
90
- prevState: deepCopyGamepad(gamepad),
91
- id: undefined
92
- };
93
- this.controllers[gamepad.index] = newController;
94
- window.requestAnimationFrame(() => this.updateStatus());
95
- this.streamMessageController.toStreamerHandlers.get('GamepadConnected')();
96
- }
97
- onGamepadDisconnected(event) {
98
- const gamepad = event.gamepad;
99
- const deletedController = this.controllers[gamepad.index];
100
- delete this.controllers[gamepad.index];
101
- this.controllers = this.controllers.filter((controller) => controller !== undefined);
102
- this.streamMessageController.toStreamerHandlers.get('GamepadDisconnected')([deletedController.id]);
103
- }
104
- scanGamepads() {
105
- const gamepads = navigator.getGamepads
106
- ? navigator.getGamepads()
107
- : navigator.webkitGetGamepads
108
- ? navigator.webkitGetGamepads()
109
- : [];
110
- for (let i = 0; i < gamepads.length; i++) {
111
- if (gamepads[i] && gamepads[i].index in this.controllers) {
112
- this.controllers[gamepads[i].index].currentState = gamepads[i];
113
- }
114
- }
115
- }
116
- updateStatus() {
117
- this.scanGamepads();
118
- const toStreamerHandlers = this.streamMessageController.toStreamerHandlers;
119
- // Iterate over multiple controllers in the case the multiple gamepads are connected
120
- for (const controller of this.controllers) {
121
- // If we haven't received an id (possible if using an older version of UE), return to original functionality
122
- const controllerIndex = controller.id === undefined ? this.controllers.indexOf(controller) : controller.id;
123
- const currentState = controller.currentState;
124
- for (let i = 0; i < controller.currentState.buttons.length; i++) {
125
- const currentButton = controller.currentState.buttons[i];
126
- const previousButton = controller.prevState.buttons[i];
127
- if (currentButton.pressed) {
128
- // press
129
- if (i == GamepadLayout.LeftTrigger) {
130
- // UEs left analog has a button index of 5
131
- toStreamerHandlers.get('GamepadAnalog')([controllerIndex, 5, currentButton.value]);
132
- }
133
- else if (i == GamepadLayout.RightTrigger) {
134
- // UEs right analog has a button index of 6
135
- toStreamerHandlers.get('GamepadAnalog')([controllerIndex, 6, currentButton.value]);
136
- }
137
- else {
138
- toStreamerHandlers.get('GamepadButtonPressed')([
139
- controllerIndex,
140
- i,
141
- previousButton.pressed ? 1 : 0
142
- ]);
143
- }
144
- }
145
- else if (!currentButton.pressed && previousButton.pressed) {
146
- // release
147
- if (i == GamepadLayout.LeftTrigger) {
148
- // UEs left analog has a button index of 5
149
- toStreamerHandlers.get('GamepadAnalog')([controllerIndex, 5, 0]);
150
- }
151
- else if (i == GamepadLayout.RightTrigger) {
152
- // UEs right analog has a button index of 6
153
- toStreamerHandlers.get('GamepadAnalog')([controllerIndex, 6, 0]);
154
- }
155
- else {
156
- toStreamerHandlers.get('GamepadButtonReleased')([controllerIndex, i, 0]);
157
- }
158
- }
159
- }
160
- // Iterate over gamepad axes (we will increment in lots of 2 as there is 2 axes per stick)
161
- for (let i = 0; i < currentState.axes.length; i += 2) {
162
- // Horizontal axes are even numbered
163
- const x = parseFloat(currentState.axes[i].toFixed(4));
164
- // Vertical axes are odd numbered
165
- // https://w3c.github.io/gamepad/#remapping Gamepad browser side standard mapping has positive down, negative up. This is downright disgusting. So we fix it.
166
- const y = -parseFloat(currentState.axes[i + 1].toFixed(4));
167
- // UE's analog axes follow the same order as the browsers, but start at index 1 so we will offset as such
168
- toStreamerHandlers.get('GamepadAnalog')([controllerIndex, i + 1, x]); // Horizontal axes, only offset by 1
169
- toStreamerHandlers.get('GamepadAnalog')([controllerIndex, i + 2, y]); // Vertical axes, offset by two (1 to match UEs axes convention and then another 1 for the vertical axes)
170
- }
171
- this.controllers[controllerIndex].prevState = deepCopyGamepad(currentState);
172
- }
173
- if (this.controllers.length > 0) {
174
- this.requestAnimationFrame(() => this.updateStatus());
175
- }
176
- }
177
- onBeforeUnload(_) {
178
- // When a user navigates away from the page, we need to inform UE of all the disconnecting
179
- // controllers
180
- for (const controller of this.controllers) {
181
- this.streamMessageController.toStreamerHandlers.get('GamepadDisconnected')([controller.id]);
182
- }
183
- }
184
- }
1
+ // Copyright Epic Games, Inc. All Rights Reserved.
2
+ import { deepCopyGamepad } from './GamepadTypes';
3
+ /**
4
+ * Gamepad layout codes enum
5
+ */
6
+ /* eslint-disable @typescript-eslint/no-duplicate-enum-values */
7
+ export var GamepadLayout;
8
+ (function (GamepadLayout) {
9
+ GamepadLayout[GamepadLayout["RightClusterBottomButton"] = 0] = "RightClusterBottomButton";
10
+ GamepadLayout[GamepadLayout["RightClusterRightButton"] = 1] = "RightClusterRightButton";
11
+ GamepadLayout[GamepadLayout["RightClusterLeftButton"] = 2] = "RightClusterLeftButton";
12
+ GamepadLayout[GamepadLayout["RightClusterTopButton"] = 3] = "RightClusterTopButton";
13
+ GamepadLayout[GamepadLayout["LeftShoulder"] = 4] = "LeftShoulder";
14
+ GamepadLayout[GamepadLayout["RightShoulder"] = 5] = "RightShoulder";
15
+ GamepadLayout[GamepadLayout["LeftTrigger"] = 6] = "LeftTrigger";
16
+ GamepadLayout[GamepadLayout["RightTrigger"] = 7] = "RightTrigger";
17
+ GamepadLayout[GamepadLayout["SelectOrBack"] = 8] = "SelectOrBack";
18
+ GamepadLayout[GamepadLayout["StartOrForward"] = 9] = "StartOrForward";
19
+ GamepadLayout[GamepadLayout["LeftAnalogPress"] = 10] = "LeftAnalogPress";
20
+ GamepadLayout[GamepadLayout["RightAnalogPress"] = 11] = "RightAnalogPress";
21
+ GamepadLayout[GamepadLayout["LeftClusterTopButton"] = 12] = "LeftClusterTopButton";
22
+ GamepadLayout[GamepadLayout["LeftClusterBottomButton"] = 13] = "LeftClusterBottomButton";
23
+ GamepadLayout[GamepadLayout["LeftClusterLeftButton"] = 14] = "LeftClusterLeftButton";
24
+ GamepadLayout[GamepadLayout["LeftClusterRightButton"] = 15] = "LeftClusterRightButton";
25
+ GamepadLayout[GamepadLayout["CentreButton"] = 16] = "CentreButton";
26
+ // Axes
27
+ GamepadLayout[GamepadLayout["LeftStickHorizontal"] = 0] = "LeftStickHorizontal";
28
+ GamepadLayout[GamepadLayout["LeftStickVertical"] = 1] = "LeftStickVertical";
29
+ GamepadLayout[GamepadLayout["RightStickHorizontal"] = 2] = "RightStickHorizontal";
30
+ GamepadLayout[GamepadLayout["RightStickVertical"] = 3] = "RightStickVertical";
31
+ })(GamepadLayout || (GamepadLayout = {}));
32
+ /* eslint-enable @typescript-eslint/no-duplicate-enum-values */
33
+ /**
34
+ * Handles gamepad events from the document to send to the streamer.
35
+ */
36
+ export class GamepadController {
37
+ constructor(streamMessageController) {
38
+ this.streamMessageController = streamMessageController;
39
+ this.onGamepadConnectedListener = this.onGamepadConnected.bind(this);
40
+ this.onGamepadDisconnectedListener = this.onGamepadDisconnected.bind(this);
41
+ this.beforeUnloadListener = this.onBeforeUnload.bind(this);
42
+ this.requestAnimationFrame = (window.mozRequestAnimationFrame ||
43
+ window.webkitRequestAnimationFrame ||
44
+ window.requestAnimationFrame).bind(window);
45
+ }
46
+ register() {
47
+ window.addEventListener('beforeunload', this.beforeUnloadListener);
48
+ const browserWindow = window;
49
+ if ('GamepadEvent' in browserWindow) {
50
+ window.addEventListener('gamepadconnected', this.onGamepadConnectedListener);
51
+ window.addEventListener('gamepaddisconnected', this.onGamepadDisconnectedListener);
52
+ }
53
+ else if ('WebKitGamepadEvent' in browserWindow) {
54
+ window.addEventListener('webkitgamepadconnected', this.onGamepadConnectedListener);
55
+ window.addEventListener('webkitgamepaddisconnected', this.onGamepadDisconnectedListener);
56
+ }
57
+ this.controllers = [];
58
+ if (navigator.getGamepads) {
59
+ for (const gamepad of navigator.getGamepads()) {
60
+ if (gamepad) {
61
+ this.onGamepadConnected(new GamepadEvent('gamepadconnected', { gamepad }));
62
+ }
63
+ }
64
+ }
65
+ }
66
+ unregister() {
67
+ window.removeEventListener('gamepadconnected', this.onGamepadConnectedListener);
68
+ window.removeEventListener('gamepaddisconnected', this.onGamepadDisconnectedListener);
69
+ window.removeEventListener('webkitgamepadconnected', this.onGamepadConnectedListener);
70
+ window.removeEventListener('webkitgamepaddisconnected', this.onGamepadDisconnectedListener);
71
+ for (const controller of this.controllers) {
72
+ if (controller.id !== undefined) {
73
+ this.streamMessageController.toStreamerHandlers.get('GamepadDisconnected')([controller.id]);
74
+ }
75
+ }
76
+ this.controllers = [];
77
+ }
78
+ onGamepadResponseReceived(gamepadId) {
79
+ for (const controller of this.controllers) {
80
+ if (controller.id === undefined) {
81
+ controller.id = gamepadId;
82
+ break;
83
+ }
84
+ }
85
+ }
86
+ onGamepadConnected(event) {
87
+ const gamepad = event.gamepad;
88
+ const newController = {
89
+ currentState: deepCopyGamepad(gamepad),
90
+ prevState: deepCopyGamepad(gamepad),
91
+ id: undefined
92
+ };
93
+ this.controllers[gamepad.index] = newController;
94
+ window.requestAnimationFrame(() => this.updateStatus());
95
+ this.streamMessageController.toStreamerHandlers.get('GamepadConnected')();
96
+ }
97
+ onGamepadDisconnected(event) {
98
+ const gamepad = event.gamepad;
99
+ const deletedController = this.controllers[gamepad.index];
100
+ delete this.controllers[gamepad.index];
101
+ this.controllers = this.controllers.filter((controller) => controller !== undefined);
102
+ this.streamMessageController.toStreamerHandlers.get('GamepadDisconnected')([deletedController.id]);
103
+ }
104
+ scanGamepads() {
105
+ const gamepads = navigator.getGamepads
106
+ ? navigator.getGamepads()
107
+ : navigator.webkitGetGamepads
108
+ ? navigator.webkitGetGamepads()
109
+ : [];
110
+ for (let i = 0; i < gamepads.length; i++) {
111
+ if (gamepads[i] && gamepads[i].index in this.controllers) {
112
+ this.controllers[gamepads[i].index].currentState = gamepads[i];
113
+ }
114
+ }
115
+ }
116
+ updateStatus() {
117
+ this.scanGamepads();
118
+ const toStreamerHandlers = this.streamMessageController.toStreamerHandlers;
119
+ // Iterate over multiple controllers in the case the multiple gamepads are connected
120
+ for (const controller of this.controllers) {
121
+ // If we haven't received an id (possible if using an older version of UE), return to original functionality
122
+ const controllerIndex = controller.id === undefined ? this.controllers.indexOf(controller) : controller.id;
123
+ const currentState = controller.currentState;
124
+ for (let i = 0; i < controller.currentState.buttons.length; i++) {
125
+ const currentButton = controller.currentState.buttons[i];
126
+ const previousButton = controller.prevState.buttons[i];
127
+ if (currentButton.pressed) {
128
+ // press
129
+ if (i == GamepadLayout.LeftTrigger) {
130
+ // UEs left analog has a button index of 5
131
+ toStreamerHandlers.get('GamepadAnalog')([controllerIndex, 5, currentButton.value]);
132
+ }
133
+ else if (i == GamepadLayout.RightTrigger) {
134
+ // UEs right analog has a button index of 6
135
+ toStreamerHandlers.get('GamepadAnalog')([controllerIndex, 6, currentButton.value]);
136
+ }
137
+ else {
138
+ toStreamerHandlers.get('GamepadButtonPressed')([
139
+ controllerIndex,
140
+ i,
141
+ previousButton.pressed ? 1 : 0
142
+ ]);
143
+ }
144
+ }
145
+ else if (!currentButton.pressed && previousButton.pressed) {
146
+ // release
147
+ if (i == GamepadLayout.LeftTrigger) {
148
+ // UEs left analog has a button index of 5
149
+ toStreamerHandlers.get('GamepadAnalog')([controllerIndex, 5, 0]);
150
+ }
151
+ else if (i == GamepadLayout.RightTrigger) {
152
+ // UEs right analog has a button index of 6
153
+ toStreamerHandlers.get('GamepadAnalog')([controllerIndex, 6, 0]);
154
+ }
155
+ else {
156
+ toStreamerHandlers.get('GamepadButtonReleased')([controllerIndex, i, 0]);
157
+ }
158
+ }
159
+ }
160
+ // Iterate over gamepad axes (we will increment in lots of 2 as there is 2 axes per stick)
161
+ for (let i = 0; i < currentState.axes.length; i += 2) {
162
+ // Horizontal axes are even numbered
163
+ const x = parseFloat(currentState.axes[i].toFixed(4));
164
+ // Vertical axes are odd numbered
165
+ // https://w3c.github.io/gamepad/#remapping Gamepad browser side standard mapping has positive down, negative up. This is downright disgusting. So we fix it.
166
+ const y = -parseFloat(currentState.axes[i + 1].toFixed(4));
167
+ // UE's analog axes follow the same order as the browsers, but start at index 1 so we will offset as such
168
+ toStreamerHandlers.get('GamepadAnalog')([controllerIndex, i + 1, x]); // Horizontal axes, only offset by 1
169
+ toStreamerHandlers.get('GamepadAnalog')([controllerIndex, i + 2, y]); // Vertical axes, offset by two (1 to match UEs axes convention and then another 1 for the vertical axes)
170
+ }
171
+ this.controllers[controllerIndex].prevState = deepCopyGamepad(currentState);
172
+ }
173
+ if (this.controllers.length > 0) {
174
+ this.requestAnimationFrame(() => this.updateStatus());
175
+ }
176
+ }
177
+ onBeforeUnload(_) {
178
+ // When a user navigates away from the page, we need to inform UE of all the disconnecting
179
+ // controllers
180
+ for (const controller of this.controllers) {
181
+ this.streamMessageController.toStreamerHandlers.get('GamepadDisconnected')([controller.id]);
182
+ }
183
+ }
184
+ }
185
185
  //# sourceMappingURL=GamepadController.js.map
@@ -1,18 +1,18 @@
1
- // Copyright Epic Games, Inc. All Rights Reserved.
2
- /**
3
- * Deep copies the values from a gamepad by first converting it to a JSON object and then back to a gamepad
4
- *
5
- * @param gamepad the original gamepad
6
- * @returns a new gamepad object, populated with the original gamepads values
7
- */
8
- export function deepCopyGamepad(gamepad) {
9
- return JSON.parse(JSON.stringify({
10
- buttons: gamepad.buttons.map((b) => JSON.parse(JSON.stringify({
11
- pressed: b.pressed,
12
- touched: b.touched,
13
- value: b.value
14
- }))),
15
- axes: gamepad.axes
16
- }));
17
- }
1
+ // Copyright Epic Games, Inc. All Rights Reserved.
2
+ /**
3
+ * Deep copies the values from a gamepad by first converting it to a JSON object and then back to a gamepad
4
+ *
5
+ * @param gamepad the original gamepad
6
+ * @returns a new gamepad object, populated with the original gamepads values
7
+ */
8
+ export function deepCopyGamepad(gamepad) {
9
+ return JSON.parse(JSON.stringify({
10
+ buttons: gamepad.buttons.map((b) => JSON.parse(JSON.stringify({
11
+ pressed: b.pressed,
12
+ touched: b.touched,
13
+ value: b.value
14
+ }))),
15
+ axes: gamepad.axes
16
+ }));
17
+ }
18
18
  //# sourceMappingURL=GamepadTypes.js.map
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=IInputController.js.map
@@ -1,92 +1,92 @@
1
- // Copyright Epic Games, Inc. All Rights Reserved.
2
- import { KeyboardController } from './KeyboardController';
3
- import { MouseControllerLocked } from './MouseControllerLocked';
4
- import { MouseControllerHovering } from './MouseControllerHovering';
5
- import { TouchController } from './TouchController';
6
- import { TouchControllerFake } from './TouchControllerFake';
7
- import { GamepadController } from './GamepadController';
8
- import { ControlSchemeType } from '../Config/Config';
9
- import { Logger } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';
10
- /**
11
- * Class for making and setting up input class types
12
- */
13
- export class InputClassesFactory {
14
- /**
15
- * @param toStreamerMessagesProvider - Stream message instance
16
- * @param videoElementProvider - Video Player instance
17
- * @param coordinateConverter - A coordinateConverter instance
18
- */
19
- constructor(toStreamerMessagesProvider, videoElementProvider, coordinateConverter) {
20
- this.activeKeys = new ActiveKeys();
21
- this.toStreamerMessagesProvider = toStreamerMessagesProvider;
22
- this.videoElementProvider = videoElementProvider;
23
- this.coordinateConverter = coordinateConverter;
24
- }
25
- /**
26
- * Registers browser key events.
27
- */
28
- registerKeyBoard(config) {
29
- Logger.Info('Register Keyboard Events');
30
- const keyboardController = new KeyboardController(this.toStreamerMessagesProvider, config, this.activeKeys);
31
- keyboardController.register();
32
- return keyboardController;
33
- }
34
- /**
35
- * register mouse events based on a control type
36
- * @param controlScheme - if the mouse is either hovering or locked
37
- */
38
- registerMouse(controlScheme) {
39
- Logger.Info('Register Mouse Events');
40
- let mouseController;
41
- if (controlScheme == ControlSchemeType.HoveringMouse) {
42
- mouseController = new MouseControllerHovering(this.toStreamerMessagesProvider, this.videoElementProvider, this.coordinateConverter, this.activeKeys);
43
- }
44
- else {
45
- mouseController = new MouseControllerLocked(this.toStreamerMessagesProvider, this.videoElementProvider, this.coordinateConverter, this.activeKeys);
46
- }
47
- mouseController.register();
48
- return mouseController;
49
- }
50
- /**
51
- * register touch events
52
- * @param fakeMouseTouch - the faked mouse touch event
53
- */
54
- registerTouch(fakeMouseTouch) {
55
- Logger.Info('Registering Touch');
56
- let touchController;
57
- if (fakeMouseTouch) {
58
- touchController = new TouchControllerFake(this.toStreamerMessagesProvider, this.videoElementProvider, this.coordinateConverter);
59
- }
60
- else {
61
- touchController = new TouchController(this.toStreamerMessagesProvider, this.videoElementProvider, this.coordinateConverter);
62
- }
63
- touchController.register();
64
- return touchController;
65
- }
66
- /**
67
- * registers a gamepad
68
- */
69
- registerGamePad() {
70
- Logger.Info('Register Game Pad');
71
- const gamepadController = new GamepadController(this.toStreamerMessagesProvider);
72
- gamepadController.register();
73
- return gamepadController;
74
- }
75
- }
76
- /**
77
- * A class that keeps track of current active keys
78
- */
79
- export class ActiveKeys {
80
- constructor() {
81
- this.activeKeys = [];
82
- this.activeKeys = [];
83
- }
84
- /**
85
- * Get the current array of active keys
86
- * @returns - an array of active keys
87
- */
88
- getActiveKeys() {
89
- return this.activeKeys;
90
- }
91
- }
1
+ // Copyright Epic Games, Inc. All Rights Reserved.
2
+ import { KeyboardController } from './KeyboardController';
3
+ import { MouseControllerLocked } from './MouseControllerLocked';
4
+ import { MouseControllerHovering } from './MouseControllerHovering';
5
+ import { TouchController } from './TouchController';
6
+ import { TouchControllerFake } from './TouchControllerFake';
7
+ import { GamepadController } from './GamepadController';
8
+ import { ControlSchemeType } from '../Config/Config';
9
+ import { Logger } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';
10
+ /**
11
+ * Class for making and setting up input class types
12
+ */
13
+ export class InputClassesFactory {
14
+ /**
15
+ * @param toStreamerMessagesProvider - Stream message instance
16
+ * @param videoElementProvider - Video Player instance
17
+ * @param coordinateConverter - A coordinateConverter instance
18
+ */
19
+ constructor(toStreamerMessagesProvider, videoElementProvider, coordinateConverter) {
20
+ this.activeKeys = new ActiveKeys();
21
+ this.toStreamerMessagesProvider = toStreamerMessagesProvider;
22
+ this.videoElementProvider = videoElementProvider;
23
+ this.coordinateConverter = coordinateConverter;
24
+ }
25
+ /**
26
+ * Registers browser key events.
27
+ */
28
+ registerKeyBoard(config) {
29
+ Logger.Info('Register Keyboard Events');
30
+ const keyboardController = new KeyboardController(this.toStreamerMessagesProvider, config, this.activeKeys);
31
+ keyboardController.register();
32
+ return keyboardController;
33
+ }
34
+ /**
35
+ * register mouse events based on a control type
36
+ * @param controlScheme - if the mouse is either hovering or locked
37
+ */
38
+ registerMouse(controlScheme) {
39
+ Logger.Info('Register Mouse Events');
40
+ let mouseController;
41
+ if (controlScheme == ControlSchemeType.HoveringMouse) {
42
+ mouseController = new MouseControllerHovering(this.toStreamerMessagesProvider, this.videoElementProvider, this.coordinateConverter, this.activeKeys);
43
+ }
44
+ else {
45
+ mouseController = new MouseControllerLocked(this.toStreamerMessagesProvider, this.videoElementProvider, this.coordinateConverter, this.activeKeys);
46
+ }
47
+ mouseController.register();
48
+ return mouseController;
49
+ }
50
+ /**
51
+ * register touch events
52
+ * @param fakeMouseTouch - the faked mouse touch event
53
+ */
54
+ registerTouch(fakeMouseTouch) {
55
+ Logger.Info('Registering Touch');
56
+ let touchController;
57
+ if (fakeMouseTouch) {
58
+ touchController = new TouchControllerFake(this.toStreamerMessagesProvider, this.videoElementProvider, this.coordinateConverter);
59
+ }
60
+ else {
61
+ touchController = new TouchController(this.toStreamerMessagesProvider, this.videoElementProvider, this.coordinateConverter);
62
+ }
63
+ touchController.register();
64
+ return touchController;
65
+ }
66
+ /**
67
+ * registers a gamepad
68
+ */
69
+ registerGamePad() {
70
+ Logger.Info('Register Game Pad');
71
+ const gamepadController = new GamepadController(this.toStreamerMessagesProvider);
72
+ gamepadController.register();
73
+ return gamepadController;
74
+ }
75
+ }
76
+ /**
77
+ * A class that keeps track of current active keys
78
+ */
79
+ export class ActiveKeys {
80
+ constructor() {
81
+ this.activeKeys = [];
82
+ this.activeKeys = [];
83
+ }
84
+ /**
85
+ * Get the current array of active keys
86
+ * @returns - an array of active keys
87
+ */
88
+ getActiveKeys() {
89
+ return this.activeKeys;
90
+ }
91
+ }
92
92
  //# sourceMappingURL=InputClassesFactory.js.map