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