@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,970 @@
1
+ // Copyright Epic Games, Inc. All Rights Reserved.
2
+
3
+ import { Logger } from '@epicgames-ps/lib-pixelstreamingcommon-ue5.5';
4
+ import { SettingFlag } from './SettingFlag';
5
+ import { SettingNumber } from './SettingNumber';
6
+ import { SettingText } from './SettingText';
7
+ import { SettingOption } from './SettingOption';
8
+ import { EventEmitter, SettingsChangedEvent } from '../Util/EventEmitter';
9
+ import { SettingBase } from './SettingBase';
10
+
11
+ /**
12
+ * A collection of flags that can be toggled and are core to all Pixel Streaming experiences.
13
+ * These are used in the `Config.Flags` map.
14
+ */
15
+ export class Flags {
16
+ static AutoConnect = 'AutoConnect' as const;
17
+ static AutoPlayVideo = 'AutoPlayVideo' as const;
18
+ static AFKDetection = 'TimeoutIfIdle' as const;
19
+ static BrowserSendOffer = 'OfferToReceive' as const;
20
+ static HoveringMouseMode = 'HoveringMouse' as const;
21
+ static ForceMonoAudio = 'ForceMonoAudio' as const;
22
+ static ForceTURN = 'ForceTURN' as const;
23
+ static FakeMouseWithTouches = 'FakeMouseWithTouches' as const;
24
+ static IsQualityController = 'ControlsQuality' as const;
25
+ static MatchViewportResolution = 'MatchViewportRes' as const;
26
+ static StartVideoMuted = 'StartVideoMuted' as const;
27
+ static SuppressBrowserKeys = 'SuppressBrowserKeys' as const;
28
+ static UseMic = 'UseMic' as const;
29
+ static KeyboardInput = 'KeyboardInput' as const;
30
+ static MouseInput = 'MouseInput' as const;
31
+ static TouchInput = 'TouchInput' as const;
32
+ static GamepadInput = 'GamepadInput' as const;
33
+ static XRControllerInput = 'XRControllerInput' as const;
34
+ static WaitForStreamer = "WaitForStreamer" as const;
35
+ }
36
+
37
+ export type FlagsKeys = Exclude<keyof typeof Flags, 'prototype'>;
38
+ export type FlagsIds = typeof Flags[FlagsKeys];
39
+
40
+ const isFlagId = (id: string): id is FlagsIds =>
41
+ Object.getOwnPropertyNames(Flags).some(
42
+ (name: FlagsKeys) => Flags[name] === id
43
+ );
44
+
45
+ /**
46
+ * A collection of numeric parameters that are core to all Pixel Streaming experiences.
47
+ *
48
+ */
49
+ export class NumericParameters {
50
+ static AFKTimeoutSecs = 'AFKTimeout' as const;
51
+ static MinQP = 'MinQP' as const;
52
+ static MaxQP = 'MaxQP' as const;
53
+ static WebRTCFPS = 'WebRTCFPS' as const;
54
+ static WebRTCMinBitrate = 'WebRTCMinBitrate' as const;
55
+ static WebRTCMaxBitrate = 'WebRTCMaxBitrate' as const;
56
+ static MaxReconnectAttempts = 'MaxReconnectAttempts' as const;
57
+ static StreamerAutoJoinInterval = 'StreamerAutoJoinInterval' as const;
58
+ }
59
+
60
+ export type NumericParametersKeys = Exclude<
61
+ keyof typeof NumericParameters,
62
+ 'prototype'
63
+ >;
64
+ export type NumericParametersIds =
65
+ typeof NumericParameters[NumericParametersKeys];
66
+
67
+ const isNumericId = (id: string): id is NumericParametersIds =>
68
+ Object.getOwnPropertyNames(NumericParameters).some(
69
+ (name: NumericParametersKeys) => NumericParameters[name] === id
70
+ );
71
+
72
+ /**
73
+ * A collection of textual parameters that are core to all Pixel Streaming experiences.
74
+ *
75
+ */
76
+ export class TextParameters {
77
+ static SignallingServerUrl = 'ss' as const;
78
+ }
79
+
80
+ export type TextParametersKeys = Exclude<
81
+ keyof typeof TextParameters,
82
+ 'prototype'
83
+ >;
84
+ export type TextParametersIds = typeof TextParameters[TextParametersKeys];
85
+
86
+ const isTextId = (id: string): id is TextParametersIds =>
87
+ Object.getOwnPropertyNames(TextParameters).some(
88
+ (name: TextParametersKeys) => TextParameters[name] === id
89
+ );
90
+
91
+ /**
92
+ * A collection of enum based parameters that are core to all Pixel Streaming experiences.
93
+ *
94
+ */
95
+ export class OptionParameters {
96
+ static PreferredCodec = 'PreferredCodec' as const;
97
+ static StreamerId = 'StreamerId' as const;
98
+ }
99
+
100
+ export type OptionParametersKeys = Exclude<
101
+ keyof typeof OptionParameters,
102
+ 'prototype'
103
+ >;
104
+ export type OptionParametersIds = typeof OptionParameters[OptionParametersKeys];
105
+
106
+ const isOptionId = (id: string): id is OptionParametersIds =>
107
+ Object.getOwnPropertyNames(OptionParameters).some(
108
+ (name: OptionParametersKeys) => OptionParameters[name] === id
109
+ );
110
+
111
+ /**
112
+ * Utility types for inferring data type based on setting ID
113
+ */
114
+ export type OptionIds =
115
+ | FlagsIds
116
+ | NumericParametersIds
117
+ | TextParametersIds
118
+ | OptionParametersIds;
119
+ export type OptionKeys<T> = T extends FlagsIds
120
+ ? boolean
121
+ : T extends NumericParametersIds
122
+ ? number
123
+ : T extends TextParametersIds
124
+ ? string
125
+ : T extends OptionParametersIds
126
+ ? string
127
+ : never;
128
+
129
+ export type AllSettings = {
130
+ [K in OptionIds]: OptionKeys<K>;
131
+ };
132
+
133
+ export interface ConfigParams {
134
+ /** Initial Pixel Streaming settings */
135
+ initialSettings?: Partial<AllSettings>;
136
+ /** If useUrlParams is set true, will read initial values from URL parameters and persist changed settings into URL */
137
+ useUrlParams?: boolean;
138
+ }
139
+ export class Config {
140
+ /* A map of flags that can be toggled - options that can be set in the application - e.g. Use Mic? */
141
+ private flags = new Map<FlagsIds, SettingFlag>();
142
+
143
+ /* A map of numerical settings - options that can be in the application - e.g. MinBitrate */
144
+ private numericParameters = new Map<NumericParametersIds, SettingNumber>();
145
+
146
+ /* A map of text settings - e.g. signalling server url */
147
+ private textParameters = new Map<TextParametersIds, SettingText>();
148
+
149
+ /* A map of enum based settings - e.g. preferred codec */
150
+ private optionParameters = new Map<OptionParametersIds, SettingOption>();
151
+
152
+ private _useUrlParams: boolean;
153
+
154
+ // ------------ Settings -----------------
155
+
156
+ constructor(config: ConfigParams = {}) {
157
+ const { initialSettings, useUrlParams } = config;
158
+ this._useUrlParams = !!useUrlParams;
159
+ this.populateDefaultSettings(this._useUrlParams, initialSettings);
160
+ }
161
+
162
+ /**
163
+ * True if reading configuration initial values from URL parameters, and
164
+ * persisting changes in URL when changed.
165
+ */
166
+ public get useUrlParams() {
167
+ return this._useUrlParams;
168
+ }
169
+
170
+ /**
171
+ * Populate the default settings for a Pixel Streaming application
172
+ */
173
+ private populateDefaultSettings(useUrlParams: boolean, settings: Partial<AllSettings>): void {
174
+ /**
175
+ * Text Parameters
176
+ */
177
+
178
+ this.textParameters.set(
179
+ TextParameters.SignallingServerUrl,
180
+ new SettingText(
181
+ TextParameters.SignallingServerUrl,
182
+ 'Signalling url',
183
+ 'Url of the signalling server',
184
+ settings && settings.hasOwnProperty(TextParameters.SignallingServerUrl) ?
185
+ settings[TextParameters.SignallingServerUrl] :
186
+ (location.protocol === 'https:' ? 'wss://' : 'ws://') +
187
+ window.location.hostname +
188
+ // for readability, we omit the port if it's 80
189
+ (window.location.port === '80' ||
190
+ window.location.port === ''
191
+ ? ''
192
+ : `:${window.location.port}`),
193
+ useUrlParams
194
+ )
195
+ );
196
+
197
+ this.optionParameters.set(
198
+ OptionParameters.StreamerId,
199
+ new SettingOption(
200
+ OptionParameters.StreamerId,
201
+ 'Streamer ID',
202
+ 'The ID of the streamer to stream.',
203
+ settings && settings.hasOwnProperty(OptionParameters.StreamerId) ?
204
+ settings[OptionParameters.StreamerId] :
205
+ '',
206
+ [],
207
+ useUrlParams
208
+ )
209
+ );
210
+
211
+ /**
212
+ * Enum Parameters
213
+ */
214
+ this.optionParameters.set(
215
+ OptionParameters.PreferredCodec,
216
+ new SettingOption(
217
+ OptionParameters.PreferredCodec,
218
+ 'Preferred Codec',
219
+ 'The preferred codec to be used during codec negotiation',
220
+ 'H264 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f',
221
+ settings && settings.hasOwnProperty(OptionParameters.PreferredCodec) ?
222
+ [settings[OptionParameters.PreferredCodec]] :
223
+ (function (): Array<string> {
224
+ const browserSupportedCodecs: Array<string> = [];
225
+ // Try get the info needed from the RTCRtpReceiver. This is only available on chrome
226
+ if (!RTCRtpReceiver.getCapabilities) {
227
+ browserSupportedCodecs.push('Only available on Chrome');
228
+ return browserSupportedCodecs;
229
+ }
230
+
231
+ const matcher = /(VP\d|H26\d|AV1).*/;
232
+ const codecs =
233
+ RTCRtpReceiver.getCapabilities('video').codecs;
234
+ codecs.forEach((codec) => {
235
+ const str =
236
+ codec.mimeType.split('/')[1] +
237
+ ' ' +
238
+ (codec.sdpFmtpLine || '');
239
+ const match = matcher.exec(str);
240
+ if (match !== null) {
241
+ browserSupportedCodecs.push(str);
242
+ }
243
+ });
244
+ return browserSupportedCodecs;
245
+ })(),
246
+ useUrlParams
247
+ )
248
+ );
249
+
250
+ /**
251
+ * Boolean parameters
252
+ */
253
+
254
+ this.flags.set(
255
+ Flags.AutoConnect,
256
+ new SettingFlag(
257
+ Flags.AutoConnect,
258
+ 'Auto connect to stream',
259
+ 'Whether we should attempt to auto connect to the signalling server or show a click to start prompt.',
260
+ settings && settings.hasOwnProperty(Flags.AutoConnect) ?
261
+ settings[Flags.AutoConnect] :
262
+ false,
263
+ useUrlParams
264
+ )
265
+ );
266
+
267
+ this.flags.set(
268
+ Flags.AutoPlayVideo,
269
+ new SettingFlag(
270
+ Flags.AutoPlayVideo,
271
+ 'Auto play video',
272
+ 'When video is ready automatically start playing it as opposed to showing a play button.',
273
+ settings && settings.hasOwnProperty(Flags.AutoPlayVideo) ?
274
+ settings[Flags.AutoPlayVideo] :
275
+ true,
276
+ useUrlParams
277
+ )
278
+ );
279
+
280
+ this.flags.set(
281
+ Flags.BrowserSendOffer,
282
+ new SettingFlag(
283
+ Flags.BrowserSendOffer,
284
+ 'Browser send offer',
285
+ 'Browser will initiate the WebRTC handshake by sending the offer to the streamer',
286
+ settings && settings.hasOwnProperty(Flags.BrowserSendOffer) ?
287
+ settings[Flags.BrowserSendOffer] :
288
+ false,
289
+ useUrlParams
290
+ )
291
+ );
292
+
293
+ this.flags.set(
294
+ Flags.UseMic,
295
+ new SettingFlag(
296
+ Flags.UseMic,
297
+ 'Use microphone',
298
+ 'Make browser request microphone access and open an input audio track.',
299
+ settings && settings.hasOwnProperty(Flags.UseMic) ?
300
+ settings[Flags.UseMic] :
301
+ false,
302
+ useUrlParams
303
+ )
304
+ );
305
+
306
+ this.flags.set(
307
+ Flags.StartVideoMuted,
308
+ new SettingFlag(
309
+ Flags.StartVideoMuted,
310
+ 'Start video muted',
311
+ 'Video will start muted if true.',
312
+ settings && settings.hasOwnProperty(Flags.StartVideoMuted) ?
313
+ settings[Flags.StartVideoMuted] :
314
+ false,
315
+ useUrlParams
316
+ )
317
+ );
318
+
319
+ this.flags.set(
320
+ Flags.SuppressBrowserKeys,
321
+ new SettingFlag(
322
+ Flags.SuppressBrowserKeys,
323
+ 'Suppress browser keys',
324
+ 'Suppress certain browser keys that we use in UE, for example F5 to show shader complexity instead of refresh the page.',
325
+ settings && settings.hasOwnProperty(Flags.SuppressBrowserKeys) ?
326
+ settings[Flags.SuppressBrowserKeys] :
327
+ true,
328
+ useUrlParams
329
+ )
330
+ );
331
+
332
+ this.flags.set(
333
+ Flags.IsQualityController,
334
+ new SettingFlag(
335
+ Flags.IsQualityController,
336
+ 'Is quality controller?',
337
+ 'True if this peer controls stream quality',
338
+ settings && settings.hasOwnProperty(Flags.IsQualityController) ?
339
+ settings[Flags.IsQualityController] :
340
+ true,
341
+ useUrlParams
342
+ )
343
+ );
344
+
345
+ this.flags.set(
346
+ Flags.ForceMonoAudio,
347
+ new SettingFlag(
348
+ Flags.ForceMonoAudio,
349
+ 'Force mono audio',
350
+ 'Force browser to request mono audio in the SDP',
351
+ settings && settings.hasOwnProperty(Flags.ForceMonoAudio) ?
352
+ settings[Flags.ForceMonoAudio] :
353
+ false,
354
+ useUrlParams
355
+ )
356
+ );
357
+
358
+ this.flags.set(
359
+ Flags.ForceTURN,
360
+ new SettingFlag(
361
+ Flags.ForceTURN,
362
+ 'Force TURN',
363
+ 'Only generate TURN/Relayed ICE candidates.',
364
+ settings && settings.hasOwnProperty(Flags.ForceTURN) ?
365
+ settings[Flags.ForceTURN] :
366
+ false,
367
+ useUrlParams
368
+ )
369
+ );
370
+
371
+ this.flags.set(
372
+ Flags.AFKDetection,
373
+ new SettingFlag(
374
+ Flags.AFKDetection,
375
+ 'AFK if idle',
376
+ 'Timeout the experience if user is AFK for a period.',
377
+ settings && settings.hasOwnProperty(Flags.AFKDetection) ?
378
+ settings[Flags.AFKDetection] :
379
+ false,
380
+ useUrlParams
381
+ )
382
+ );
383
+
384
+ this.flags.set(
385
+ Flags.MatchViewportResolution,
386
+ new SettingFlag(
387
+ Flags.MatchViewportResolution,
388
+ 'Match viewport resolution',
389
+ 'Pixel Streaming will be instructed to dynamically resize the video stream to match the size of the video element.',
390
+ settings && settings.hasOwnProperty(Flags.MatchViewportResolution) ?
391
+ settings[Flags.MatchViewportResolution] :
392
+ false,
393
+ useUrlParams
394
+ )
395
+ );
396
+
397
+ this.flags.set(
398
+ Flags.HoveringMouseMode,
399
+ new SettingFlag(
400
+ Flags.HoveringMouseMode,
401
+ 'Control Scheme: Locked Mouse',
402
+ 'Either locked mouse, where the pointer is consumed by the video and locked to it, or hovering mouse, where the mouse is not consumed.',
403
+ settings && settings.hasOwnProperty(Flags.HoveringMouseMode) ?
404
+ settings[Flags.HoveringMouseMode] :
405
+ false,
406
+ useUrlParams,
407
+ (isHoveringMouse: boolean, setting: SettingBase) => {
408
+ setting.label = `Control Scheme: ${isHoveringMouse ? 'Hovering' : 'Locked'} Mouse`;
409
+ }
410
+ )
411
+ );
412
+
413
+ this.flags.set(
414
+ Flags.FakeMouseWithTouches,
415
+ new SettingFlag(
416
+ Flags.FakeMouseWithTouches,
417
+ 'Fake mouse with touches',
418
+ 'A single finger touch is converted into a mouse event. This allows a non-touch application to be controlled partially via a touch device.',
419
+ settings && settings.hasOwnProperty(Flags.FakeMouseWithTouches) ?
420
+ settings[Flags.FakeMouseWithTouches] :
421
+ true,
422
+ useUrlParams
423
+ )
424
+ );
425
+
426
+ this.flags.set(
427
+ Flags.KeyboardInput,
428
+ new SettingFlag(
429
+ Flags.KeyboardInput,
430
+ 'Keyboard input',
431
+ 'If enabled, send keyboard events to streamer',
432
+ settings && settings.hasOwnProperty(Flags.KeyboardInput) ?
433
+ settings[Flags.KeyboardInput] :
434
+ true,
435
+ useUrlParams
436
+ )
437
+ );
438
+
439
+ this.flags.set(
440
+ Flags.MouseInput,
441
+ new SettingFlag(
442
+ Flags.MouseInput,
443
+ 'Mouse input',
444
+ 'If enabled, send mouse events to streamer',
445
+ settings && settings.hasOwnProperty(Flags.MouseInput) ?
446
+ settings[Flags.MouseInput] :
447
+ true,
448
+ useUrlParams
449
+ )
450
+ );
451
+
452
+ this.flags.set(
453
+ Flags.TouchInput,
454
+ new SettingFlag(
455
+ Flags.TouchInput,
456
+ 'Touch input',
457
+ 'If enabled, send touch events to streamer',
458
+ settings && settings.hasOwnProperty(Flags.TouchInput) ?
459
+ settings[Flags.TouchInput] :
460
+ true,
461
+ useUrlParams
462
+ )
463
+ );
464
+
465
+ this.flags.set(
466
+ Flags.GamepadInput,
467
+ new SettingFlag(
468
+ Flags.GamepadInput,
469
+ 'Gamepad input',
470
+ 'If enabled, send gamepad events to streamer',
471
+ settings && settings.hasOwnProperty(Flags.GamepadInput) ?
472
+ settings[Flags.GamepadInput] :
473
+ true,
474
+ useUrlParams
475
+ )
476
+ );
477
+
478
+ this.flags.set(
479
+ Flags.XRControllerInput,
480
+ new SettingFlag(
481
+ Flags.XRControllerInput,
482
+ 'XR controller input',
483
+ 'If enabled, send XR controller events to streamer',
484
+ settings && settings.hasOwnProperty(Flags.XRControllerInput) ?
485
+ settings[Flags.XRControllerInput] :
486
+ true,
487
+ useUrlParams
488
+ )
489
+ );
490
+
491
+ this.flags.set(
492
+ Flags.WaitForStreamer,
493
+ new SettingFlag(
494
+ Flags.WaitForStreamer,
495
+ 'Wait for streamer',
496
+ 'Will continue trying to connect to the first streamer available.',
497
+ settings && settings.hasOwnProperty(Flags.WaitForStreamer) ?
498
+ settings[Flags.WaitForStreamer] :
499
+ true,
500
+ useUrlParams
501
+ )
502
+ );
503
+
504
+ /**
505
+ * Numeric parameters
506
+ */
507
+
508
+ this.numericParameters.set(
509
+ NumericParameters.AFKTimeoutSecs,
510
+ new SettingNumber(
511
+ NumericParameters.AFKTimeoutSecs,
512
+ 'AFK timeout',
513
+ 'The time (in seconds) it takes for the application to time out if AFK timeout is enabled.',
514
+ 0 /*min*/,
515
+ 600 /*max*/,
516
+ settings && settings.hasOwnProperty(NumericParameters.AFKTimeoutSecs) ?
517
+ settings[NumericParameters.AFKTimeoutSecs] :
518
+ 120, /*value*/
519
+ useUrlParams
520
+ )
521
+ );
522
+
523
+ this.numericParameters.set(
524
+ NumericParameters.MaxReconnectAttempts,
525
+ new SettingNumber(
526
+ NumericParameters.MaxReconnectAttempts,
527
+ 'Max Reconnects',
528
+ 'Maximum number of reconnects the application will attempt when a streamer disconnects.',
529
+ 0 /*min*/,
530
+ 999 /*max*/,
531
+ settings && settings.hasOwnProperty(NumericParameters.MaxReconnectAttempts) ?
532
+ settings[NumericParameters.MaxReconnectAttempts] :
533
+ 3, /*value*/
534
+ useUrlParams
535
+ )
536
+ );
537
+
538
+ this.numericParameters.set(
539
+ NumericParameters.MinQP,
540
+ new SettingNumber(
541
+ NumericParameters.MinQP,
542
+ 'Min QP',
543
+ 'The lower bound for the quantization parameter (QP) of the encoder. 0 = Best quality, 51 = worst quality.',
544
+ 0 /*min*/,
545
+ 51 /*max*/,
546
+ settings && settings.hasOwnProperty(NumericParameters.MinQP) ?
547
+ settings[NumericParameters.MinQP] :
548
+ 0, /*value*/
549
+ useUrlParams
550
+ )
551
+ );
552
+
553
+ this.numericParameters.set(
554
+ NumericParameters.MaxQP,
555
+ new SettingNumber(
556
+ NumericParameters.MaxQP,
557
+ 'Max QP',
558
+ 'The upper bound for the quantization parameter (QP) of the encoder. 0 = Best quality, 51 = worst quality.',
559
+ 0 /*min*/,
560
+ 51 /*max*/,
561
+ settings && settings.hasOwnProperty(NumericParameters.MaxQP) ?
562
+ settings[NumericParameters.MaxQP] :
563
+ 51, /*value*/
564
+ useUrlParams
565
+ )
566
+ );
567
+
568
+ this.numericParameters.set(
569
+ NumericParameters.WebRTCFPS,
570
+ new SettingNumber(
571
+ NumericParameters.WebRTCFPS,
572
+ 'Max FPS',
573
+ 'The maximum FPS that WebRTC will try to transmit frames at.',
574
+ 1 /*min*/,
575
+ 999 /*max*/,
576
+ settings && settings.hasOwnProperty(NumericParameters.WebRTCFPS) ?
577
+ settings[NumericParameters.WebRTCFPS] :
578
+ 60, /*value*/
579
+ useUrlParams
580
+ )
581
+ );
582
+
583
+ this.numericParameters.set(
584
+ NumericParameters.WebRTCMinBitrate,
585
+ new SettingNumber(
586
+ NumericParameters.WebRTCMinBitrate,
587
+ 'Min Bitrate (kbps)',
588
+ 'The minimum bitrate that WebRTC should use.',
589
+ 0 /*min*/,
590
+ 500000 /*max*/,
591
+ settings && settings.hasOwnProperty(NumericParameters.WebRTCMinBitrate) ?
592
+ settings[NumericParameters.WebRTCMinBitrate] :
593
+ 0, /*value*/
594
+ useUrlParams
595
+ )
596
+ );
597
+
598
+ this.numericParameters.set(
599
+ NumericParameters.WebRTCMaxBitrate,
600
+ new SettingNumber(
601
+ NumericParameters.WebRTCMaxBitrate,
602
+ 'Max Bitrate (kbps)',
603
+ 'The maximum bitrate that WebRTC should use.',
604
+ 0 /*min*/,
605
+ 500000 /*max*/,
606
+ settings && settings.hasOwnProperty(NumericParameters.WebRTCMaxBitrate) ?
607
+ settings[NumericParameters.WebRTCMaxBitrate] :
608
+ 0, /*value*/
609
+ useUrlParams
610
+ )
611
+ );
612
+
613
+ this.numericParameters.set(
614
+ NumericParameters.StreamerAutoJoinInterval,
615
+ new SettingNumber(
616
+ NumericParameters.StreamerAutoJoinInterval,
617
+ 'Streamer Auto Join Interval (ms)',
618
+ 'Delay between retries when waiting for an available streamer.',
619
+ 500 /*min*/,
620
+ 900000 /*max*/,
621
+ settings && settings.hasOwnProperty(NumericParameters.StreamerAutoJoinInterval) ?
622
+ settings[NumericParameters.StreamerAutoJoinInterval] :
623
+ 3000, /*value*/
624
+ useUrlParams
625
+ )
626
+ );
627
+ }
628
+
629
+ /**
630
+ * Add a callback to fire when the numeric setting is toggled.
631
+ * @param id The id of the flag.
632
+ * @param onChangedListener The callback to fire when the numeric value changes.
633
+ */
634
+ _addOnNumericSettingChangedListener(
635
+ id: NumericParametersIds,
636
+ onChangedListener: (newValue: number) => void
637
+ ): void {
638
+ if (this.numericParameters.has(id)) {
639
+ this.numericParameters
640
+ .get(id)
641
+ .addOnChangedListener(onChangedListener);
642
+ }
643
+ }
644
+
645
+ _addOnOptionSettingChangedListener(
646
+ id: OptionParametersIds,
647
+ onChangedListener: (newValue: string) => void
648
+ ): void {
649
+ if (this.optionParameters.has(id)) {
650
+ this.optionParameters
651
+ .get(id)
652
+ .addOnChangedListener(onChangedListener);
653
+ }
654
+ }
655
+
656
+ /**
657
+ * @param id The id of the numeric setting we are interested in getting a value for.
658
+ * @returns The numeric value stored in the parameter with the passed id.
659
+ */
660
+ getNumericSettingValue(id: NumericParametersIds): number {
661
+ if (this.numericParameters.has(id)) {
662
+ return this.numericParameters.get(id).number;
663
+ } else {
664
+ throw new Error(`There is no numeric setting with the id of ${id}`);
665
+ }
666
+ }
667
+
668
+ /**
669
+ * @param id The id of the text setting we are interested in getting a value for.
670
+ * @returns The text value stored in the parameter with the passed id.
671
+ */
672
+ getTextSettingValue(id: TextParametersIds): string {
673
+ if (this.textParameters.has(id)) {
674
+ return this.textParameters.get(id).value as string;
675
+ } else {
676
+ throw new Error(`There is no numeric setting with the id of ${id}`);
677
+ }
678
+ }
679
+
680
+ /**
681
+ * Set number in the setting.
682
+ * @param id The id of the numeric setting we are interested in.
683
+ * @param value The numeric value to set.
684
+ */
685
+ setNumericSetting(id: NumericParametersIds, value: number): void {
686
+ if (this.numericParameters.has(id)) {
687
+ this.numericParameters.get(id).number = value;
688
+ } else {
689
+ throw new Error(`There is no numeric setting with the id of ${id}`);
690
+ }
691
+ }
692
+
693
+ /**
694
+ * Add a callback to fire when the flag is toggled.
695
+ * @param id The id of the flag.
696
+ * @param onChangeListener The callback to fire when the value changes.
697
+ */
698
+ _addOnSettingChangedListener(
699
+ id: FlagsIds,
700
+ onChangeListener: (newFlagValue: boolean) => void
701
+ ): void {
702
+ if (this.flags.has(id)) {
703
+ this.flags.get(id).onChange = onChangeListener;
704
+ }
705
+ }
706
+
707
+ /**
708
+ * Add a callback to fire when the text is changed.
709
+ * @param id The id of the flag.
710
+ * @param onChangeListener The callback to fire when the value changes.
711
+ */
712
+ _addOnTextSettingChangedListener(
713
+ id: TextParametersIds,
714
+ onChangeListener: (newTextValue: string) => void
715
+ ): void {
716
+ if (this.textParameters.has(id)) {
717
+ this.textParameters.get(id).onChange = onChangeListener;
718
+ }
719
+ }
720
+
721
+ /**
722
+ * Get the option which has the given id.
723
+ * @param id The id of the option.
724
+ * @returns The SettingOption object matching id
725
+ */
726
+ getSettingOption(id: OptionParametersIds): SettingOption {
727
+ return this.optionParameters.get(id);
728
+ }
729
+
730
+ /**
731
+ * Get the value of the configuration flag which has the given id.
732
+ * @param id The unique id for the flag.
733
+ * @returns True if the flag is enabled.
734
+ */
735
+ isFlagEnabled(id: FlagsIds): boolean {
736
+ return this.flags.get(id).flag as boolean;
737
+ }
738
+
739
+ /**
740
+ * Set flag to be enabled/disabled.
741
+ * @param id The id of the flag to toggle.
742
+ * @param flagEnabled True if the flag should be enabled.
743
+ */
744
+ setFlagEnabled(id: FlagsIds, flagEnabled: boolean) {
745
+ if (!this.flags.has(id)) {
746
+ Logger.Warning(
747
+ Logger.GetStackTrace(),
748
+ `Cannot toggle flag called ${id} - it does not exist in the Config.flags map.`
749
+ );
750
+ } else {
751
+ this.flags.get(id).flag = flagEnabled;
752
+ }
753
+ }
754
+
755
+ /**
756
+ * Set the text setting.
757
+ * @param id The id of the setting
758
+ * @param settingValue The value to set in the setting.
759
+ */
760
+ setTextSetting(id: TextParametersIds, settingValue: string) {
761
+ if (!this.textParameters.has(id)) {
762
+ Logger.Warning(
763
+ Logger.GetStackTrace(),
764
+ `Cannot set text setting called ${id} - it does not exist in the Config.textParameters map.`
765
+ );
766
+ } else {
767
+ this.textParameters.get(id).text = settingValue;
768
+ }
769
+ }
770
+
771
+ /**
772
+ * Set the option setting list of options.
773
+ * @param id The id of the setting
774
+ * @param settingOptions The values the setting could take
775
+ */
776
+ setOptionSettingOptions(
777
+ id: OptionParametersIds,
778
+ settingOptions: Array<string>
779
+ ) {
780
+ if (!this.optionParameters.has(id)) {
781
+ Logger.Warning(
782
+ Logger.GetStackTrace(),
783
+ `Cannot set text setting called ${id} - it does not exist in the Config.optionParameters map.`
784
+ );
785
+ } else {
786
+ this.optionParameters.get(id).options = settingOptions;
787
+ }
788
+ }
789
+
790
+ /**
791
+ * Set option enum settings selected option.
792
+ * @param id The id of the setting
793
+ * @param settingOptions The value to select out of all the options
794
+ */
795
+ setOptionSettingValue(id: OptionParametersIds, settingValue: string) {
796
+ if (!this.optionParameters.has(id)) {
797
+ Logger.Warning(
798
+ Logger.GetStackTrace(),
799
+ `Cannot set text setting called ${id} - it does not exist in the Config.enumParameters map.`
800
+ );
801
+ } else {
802
+ const optionSetting = this.optionParameters.get(id);
803
+ const existingOptions = optionSetting.options;
804
+ if (!existingOptions.includes(settingValue)) {
805
+ existingOptions.push(settingValue);
806
+ optionSetting.options = existingOptions;
807
+ }
808
+ optionSetting.selected = settingValue;
809
+ }
810
+ }
811
+
812
+ /**
813
+ * Set the label for the flag.
814
+ * @param id The id of the flag.
815
+ * @param label The new label to use for the flag.
816
+ */
817
+ setFlagLabel(id: FlagsIds, label: string) {
818
+ if (!this.flags.has(id)) {
819
+ Logger.Warning(
820
+ Logger.GetStackTrace(),
821
+ `Cannot set label for flag called ${id} - it does not exist in the Config.flags map.`
822
+ );
823
+ } else {
824
+ this.flags.get(id).label = label;
825
+ }
826
+ }
827
+
828
+ /**
829
+ * Set a subset of all settings in one function call.
830
+ *
831
+ * @param settings A (partial) list of settings to set
832
+ */
833
+ setSettings(settings: Partial<AllSettings>) {
834
+ for (const key of Object.keys(settings)) {
835
+ if (isFlagId(key)) {
836
+ this.setFlagEnabled(key, settings[key]);
837
+ } else if (isNumericId(key)) {
838
+ this.setNumericSetting(key, settings[key]);
839
+ } else if (isTextId(key)) {
840
+ this.setTextSetting(key, settings[key]);
841
+ } else if (isOptionId(key)) {
842
+ this.setOptionSettingValue(key, settings[key]);
843
+ }
844
+ }
845
+ }
846
+
847
+ /**
848
+ * Get all settings
849
+ * @returns All setting values as an object with setting ids as keys
850
+ */
851
+ getSettings(): Partial<AllSettings> {
852
+ const settings: Partial<AllSettings> = {};
853
+ for (const [key, value] of this.flags.entries()) {
854
+ settings[key] = value.flag;
855
+ }
856
+ for (const [key, value] of this.numericParameters.entries()) {
857
+ settings[key] = value.number;
858
+ }
859
+ for (const [key, value] of this.textParameters.entries()) {
860
+ settings[key] = value.text;
861
+ }
862
+ for (const [key, value] of this.optionParameters.entries()) {
863
+ settings[key] = value.selected;
864
+ }
865
+ return settings;
866
+ }
867
+
868
+ /**
869
+ * Get all Flag settings as an array.
870
+ * @returns All SettingFlag objects
871
+ */
872
+ getFlags(): Array<SettingFlag> {
873
+ return Array.from(this.flags.values());
874
+ }
875
+
876
+ /**
877
+ * Get all Text settings as an array.
878
+ * @returns All SettingText objects
879
+ */
880
+ getTextSettings(): Array<SettingText> {
881
+ return Array.from(this.textParameters.values());
882
+ }
883
+
884
+ /**
885
+ * Get all Number settings as an array.
886
+ * @returns All SettingNumber objects
887
+ */
888
+ getNumericSettings(): Array<SettingNumber> {
889
+ return Array.from(this.numericParameters.values());
890
+ }
891
+
892
+ /**
893
+ * Get all Option settings as an array.
894
+ * @returns All SettingOption objects
895
+ */
896
+ getOptionSettings(): Array<SettingOption> {
897
+ return Array.from(this.optionParameters.values());
898
+ }
899
+
900
+ /**
901
+ * Emit events when settings change.
902
+ * @param eventEmitter
903
+ */
904
+ _registerOnChangeEvents(eventEmitter: EventEmitter) {
905
+ for (const key of this.flags.keys()) {
906
+ const flag = this.flags.get(key);
907
+ if (flag) {
908
+ flag.onChangeEmit = (newValue: boolean) =>
909
+ eventEmitter.dispatchEvent(
910
+ new SettingsChangedEvent({
911
+ id: flag.id,
912
+ type: 'flag',
913
+ value: newValue,
914
+ target: flag
915
+ })
916
+ );
917
+ }
918
+ }
919
+ for (const key of this.numericParameters.keys()) {
920
+ const number = this.numericParameters.get(key);
921
+ if (number) {
922
+ number.onChangeEmit = (newValue: number) =>
923
+ eventEmitter.dispatchEvent(
924
+ new SettingsChangedEvent({
925
+ id: number.id,
926
+ type: 'number',
927
+ value: newValue,
928
+ target: number
929
+ })
930
+ );
931
+ }
932
+ }
933
+ for (const key of this.textParameters.keys()) {
934
+ const text = this.textParameters.get(key);
935
+ if (text) {
936
+ text.onChangeEmit = (newValue: string) =>
937
+ eventEmitter.dispatchEvent(
938
+ new SettingsChangedEvent({
939
+ id: text.id,
940
+ type: 'text',
941
+ value: newValue,
942
+ target: text
943
+ })
944
+ );
945
+ }
946
+ }
947
+ for (const key of this.optionParameters.keys()) {
948
+ const option = this.optionParameters.get(key);
949
+ if (option) {
950
+ option.onChangeEmit = (newValue: string) =>
951
+ eventEmitter.dispatchEvent(
952
+ new SettingsChangedEvent({
953
+ id: option.id,
954
+ type: 'option',
955
+ value: newValue,
956
+ target: option
957
+ })
958
+ );
959
+ }
960
+ }
961
+ }
962
+ }
963
+
964
+ /**
965
+ * The enum associated with the mouse being locked or hovering
966
+ */
967
+ export enum ControlSchemeType {
968
+ LockedMouse = 0,
969
+ HoveringMouse = 1
970
+ }