@yang__yj/pixelstreaming-core 1.0.1 → 1.0.3

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.
@@ -1,7 +1,6 @@
1
1
  // Copyright Epic Games, Inc. All Rights Reserved.
2
2
 
3
- import { ElMessage, ElMessageBox } from 'element-plus'
4
- import { useRoute, useRouter } from "vue-router";
3
+ import { ElMessage, ElMessageBox } from 'element-plus';
5
4
  import { WebSocketController } from '../WebSockets/WebSocketController';
6
5
  import { StreamController } from '../VideoPlayer/StreamController';
7
6
  import {
@@ -66,7 +65,7 @@ import {
66
65
  import {
67
66
  DataChannelLatencyTestRequest,
68
67
  DataChannelLatencyTestResponse
69
- } from "../DataChannel/DataChannelLatencyTestResults";
68
+ } from '../DataChannel/DataChannelLatencyTestResults';
70
69
  /**
71
70
  * Entry point for the WebRTC Player
72
71
  */
@@ -138,7 +137,9 @@ export class WebRtcPlayerController {
138
137
  this.onAfkTriggered.bind(this)
139
138
  );
140
139
  this.afkController.onAFKTimedOutCallback = () => {
141
- this.closeSignalingServer('You have been disconnected due to inactivity');
140
+ this.closeSignalingServer(
141
+ 'You have been disconnected due to inactivity'
142
+ );
142
143
  };
143
144
 
144
145
  this.freezeFrameController = new FreezeFrameController(
@@ -162,9 +163,9 @@ export class WebRtcPlayerController {
162
163
  'Resolution.Height': height
163
164
  };
164
165
 
165
- this.streamMessageController.toStreamerHandlers.get(
166
- 'Command'
167
- )([JSON.stringify(descriptor)]);
166
+ this.streamMessageController.toStreamerHandlers.get('Command')([
167
+ JSON.stringify(descriptor)
168
+ ]);
168
169
  };
169
170
 
170
171
  // Every time video player is resized in browser we need to reinitialize the mouse coordinate conversion and freeze frame sizing logic.
@@ -201,7 +202,9 @@ export class WebRtcPlayerController {
201
202
  messageList: MessageReceive.MessageStreamerList
202
203
  ) => this.handleStreamerListMessage(messageList);
203
204
 
204
- this.webSocketController.onPlayerCount = (playerCount: MessageReceive.MessagePlayerCount) => {
205
+ this.webSocketController.onPlayerCount = (
206
+ playerCount: MessageReceive.MessagePlayerCount
207
+ ) => {
205
208
  this.pixelStreaming._onPlayerCount(playerCount.count);
206
209
  };
207
210
 
@@ -215,7 +218,9 @@ export class WebRtcPlayerController {
215
218
  // 发送当前连接 所有像素流 TODO:无法判断是固定的什么项目的像素流
216
219
  // this.webSocketController.requestStreamerList();
217
220
  // this.webSocketController.requestStreamerObject(window.streamerName());
218
- this.webSocketController.requestStreamerObject(sessionStorage.getItem('streamerName'));
221
+ this.webSocketController.requestStreamerObject(
222
+ sessionStorage.getItem('streamerName')
223
+ );
219
224
 
220
225
  // this.webSocketController.onStreamerList = (
221
226
  // messageList: MessageReceive.MessageStreamerList
@@ -224,45 +229,59 @@ export class WebRtcPlayerController {
224
229
  }
225
230
  });
226
231
 
227
- this.webSocketController.onClose.addEventListener('close', (event: CustomEvent) => {
228
- // when we refresh the page during a stream we get the going away code.
229
- // in that case we don't want to reconnect since we're navigating away.
230
- // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
231
- // lists all the codes.
232
- const CODE_GOING_AWAY = 1001;
233
-
234
- const willTryReconnect = this.shouldReconnect
235
- && event.detail.code != CODE_GOING_AWAY
236
- && this.config.getNumericSettingValue(NumericParameters.MaxReconnectAttempts) > 0
237
-
238
- const disconnectMessage = this.disconnectMessage ? this.disconnectMessage : event.detail.reason;
239
- this.pixelStreaming._onDisconnect(disconnectMessage, !willTryReconnect && !this.isReconnecting);
232
+ this.webSocketController.onClose.addEventListener(
233
+ 'close',
234
+ (event: CustomEvent) => {
235
+ // when we refresh the page during a stream we get the going away code.
236
+ // in that case we don't want to reconnect since we're navigating away.
237
+ // https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code
238
+ // lists all the codes.
239
+ const CODE_GOING_AWAY = 1001;
240
+
241
+ const willTryReconnect =
242
+ this.shouldReconnect &&
243
+ event.detail.code != CODE_GOING_AWAY &&
244
+ this.config.getNumericSettingValue(
245
+ NumericParameters.MaxReconnectAttempts
246
+ ) > 0;
247
+
248
+ const disconnectMessage = this.disconnectMessage
249
+ ? this.disconnectMessage
250
+ : event.detail.reason;
251
+ this.pixelStreaming._onDisconnect(
252
+ disconnectMessage,
253
+ !willTryReconnect && !this.isReconnecting
254
+ );
240
255
 
241
- this.afkController.stopAfkWarningTimer();
256
+ this.afkController.stopAfkWarningTimer();
242
257
 
243
- // stop sending stats on interval if we have closed our connection
244
- if (this.statsTimerHandle && this.statsTimerHandle !== undefined) {
245
- window.clearInterval(this.statsTimerHandle);
246
- }
258
+ // stop sending stats on interval if we have closed our connection
259
+ if (
260
+ this.statsTimerHandle &&
261
+ this.statsTimerHandle !== undefined
262
+ ) {
263
+ window.clearInterval(this.statsTimerHandle);
264
+ }
247
265
 
248
- // reset the stream quality icon.
249
- this.setVideoEncoderAvgQP(0);
266
+ // reset the stream quality icon.
267
+ this.setVideoEncoderAvgQP(0);
250
268
 
251
- // unregister all input device event handlers on disconnect
252
- this.setTouchInputEnabled(false);
253
- this.setMouseInputEnabled(false);
254
- this.setKeyboardInputEnabled(false);
255
- this.setGamePadInputEnabled(false);
269
+ // unregister all input device event handlers on disconnect
270
+ this.setTouchInputEnabled(false);
271
+ this.setMouseInputEnabled(false);
272
+ this.setKeyboardInputEnabled(false);
273
+ this.setGamePadInputEnabled(false);
256
274
 
257
- if (willTryReconnect) {
258
- // need a small delay here to prevent reconnect spamming
259
- setTimeout(() => {
260
- this.isReconnecting = true;
261
- this.reconnectAttempt++;
262
- this.tryReconnect(event.detail.reason);
263
- }, 2000);
275
+ if (willTryReconnect) {
276
+ // need a small delay here to prevent reconnect spamming
277
+ setTimeout(() => {
278
+ this.isReconnecting = true;
279
+ this.reconnectAttempt++;
280
+ this.tryReconnect(event.detail.reason);
281
+ }, 2000);
282
+ }
264
283
  }
265
- });
284
+ );
266
285
 
267
286
  // 在应用中设置webRtc播放器控制器的最后几个方法,以便激活连接
268
287
  this.sendMessageController = new SendMessageController(
@@ -291,7 +310,7 @@ export class WebRtcPlayerController {
291
310
  this.config._addOnOptionSettingChangedListener(
292
311
  OptionParameters.StreamerId,
293
312
  (streamerid) => {
294
- if (streamerid === "") {
313
+ if (streamerid === '') {
295
314
  return;
296
315
  }
297
316
 
@@ -324,7 +343,7 @@ export class WebRtcPlayerController {
324
343
  // }
325
344
 
326
345
  return signallingServerUrl;
327
- }
346
+ };
328
347
  }
329
348
 
330
349
  /**
@@ -349,9 +368,7 @@ export class WebRtcPlayerController {
349
368
 
350
369
  //try {
351
370
  const messageType =
352
- this.streamMessageController.fromStreamerMessages.get(
353
- message[0]
354
- );
371
+ this.streamMessageController.fromStreamerMessages.get(message[0]);
355
372
  this.streamMessageController.fromStreamerHandlers.get(messageType)(
356
373
  event.data
357
374
  );
@@ -406,8 +423,9 @@ export class WebRtcPlayerController {
406
423
  this.streamMessageController.registerMessageHandler(
407
424
  MessageDirection.FromStreamer,
408
425
  'DataChannelLatencyTest',
409
- (data: ArrayBuffer) => this.handleDataChannelLatencyTestResponse(data)
410
- )
426
+ (data: ArrayBuffer) =>
427
+ this.handleDataChannelLatencyTestResponse(data)
428
+ );
411
429
  this.streamMessageController.registerMessageHandler(
412
430
  MessageDirection.FromStreamer,
413
431
  'InitialSettings',
@@ -502,7 +520,8 @@ export class WebRtcPlayerController {
502
520
  'LatencyTest',
503
521
  (data: Array<number | string>) =>
504
522
  this.sendMessageController.sendMessageToStreamer(
505
- 'LatencyTest', data
523
+ 'LatencyTest',
524
+ data
506
525
  )
507
526
  );
508
527
  this.streamMessageController.registerMessageHandler(
@@ -525,7 +544,8 @@ export class WebRtcPlayerController {
525
544
  'UIInteraction',
526
545
  (data: Array<number | string>) =>
527
546
  this.sendMessageController.sendMessageToStreamer(
528
- 'UIInteraction', data
547
+ 'UIInteraction',
548
+ data
529
549
  )
530
550
  );
531
551
  this.streamMessageController.registerMessageHandler(
@@ -533,7 +553,8 @@ export class WebRtcPlayerController {
533
553
  'Command',
534
554
  (data: Array<number | string>) =>
535
555
  this.sendMessageController.sendMessageToStreamer(
536
- 'Command', data
556
+ 'Command',
557
+ data
537
558
  )
538
559
  );
539
560
  this.streamMessageController.registerMessageHandler(
@@ -541,7 +562,8 @@ export class WebRtcPlayerController {
541
562
  'TextboxEntry',
542
563
  (data: Array<number | string>) =>
543
564
  this.sendMessageController.sendMessageToStreamer(
544
- 'TextboxEntry', data
565
+ 'TextboxEntry',
566
+ data
545
567
  )
546
568
  );
547
569
  this.streamMessageController.registerMessageHandler(
@@ -814,9 +836,10 @@ export class WebRtcPlayerController {
814
836
  delete protocolJSON.Direction;
815
837
  Logger.Log(
816
838
  Logger.GetStackTrace(),
817
- `Received new ${direction == MessageDirection.FromStreamer
818
- ? 'FromStreamer'
819
- : 'ToStreamer'
839
+ `Received new ${
840
+ direction == MessageDirection.FromStreamer
841
+ ? 'FromStreamer'
842
+ : 'ToStreamer'
820
843
  } protocol. Updating existing protocol...(更新现有协议)`
821
844
  );
822
845
  Object.keys(protocolJSON).forEach((messageType) => {
@@ -825,26 +848,27 @@ export class WebRtcPlayerController {
825
848
  case MessageDirection.ToStreamer:
826
849
  // Check that the message contains all the relevant params
827
850
  if (
828
- !Object.prototype.hasOwnProperty.call(
829
- message,
830
- 'id'
831
- )
851
+ !Object.prototype.hasOwnProperty.call(message, 'id')
832
852
  ) {
833
853
  Logger.Error(
834
854
  Logger.GetStackTrace(),
835
855
  `ToStreamer->${messageType} protocol definition was malformed as it didn't contain at least an id\n
836
856
  Definition was: ${JSON.stringify(
837
- message,
838
- null,
839
- 2
840
- )}`
857
+ message,
858
+ null,
859
+ 2
860
+ )}`
841
861
  );
842
862
  // return in a forEach is equivalent to a continue in a normal for loop
843
863
  return;
844
864
  }
845
865
 
846
866
  // UE5.1 and UE5.2 don't send a structure for these message types, but they actually do have a structure so ignore updating them
847
- if ((messageType === "UIInteraction" || messageType === "Command" || messageType === "LatencyTest")) {
867
+ if (
868
+ messageType === 'UIInteraction' ||
869
+ messageType === 'Command' ||
870
+ messageType === 'LatencyTest'
871
+ ) {
848
872
  return;
849
873
  }
850
874
 
@@ -931,13 +955,17 @@ export class WebRtcPlayerController {
931
955
  }
932
956
 
933
957
  /**
934
- *
935
- * @param message
958
+ *
959
+ * @param message
936
960
  */
937
961
  onGamepadResponse(message: ArrayBuffer) {
938
- const responseString = new TextDecoder('utf-16').decode(message.slice(1));
962
+ const responseString = new TextDecoder('utf-16').decode(
963
+ message.slice(1)
964
+ );
939
965
  const responseJSON = JSON.parse(responseString);
940
- this.gamePadController.onGamepadResponseReceived(responseJSON.controllerId);
966
+ this.gamePadController.onGamepadResponseReceived(
967
+ responseJSON.controllerId
968
+ );
941
969
  }
942
970
 
943
971
  onAfkTriggered(): void {
@@ -976,7 +1004,10 @@ export class WebRtcPlayerController {
976
1004
 
977
1005
  // 如果连接是打开的,首先关闭它。等待一段时间再试一次
978
1006
  this.isReconnecting = true;
979
- if (this.webSocketController.webSocket && this.webSocketController.webSocket.readyState != WebSocket.CLOSED) {
1007
+ if (
1008
+ this.webSocketController.webSocket &&
1009
+ this.webSocketController.webSocket.readyState != WebSocket.CLOSED
1010
+ ) {
980
1011
  this.closeSignalingServer(`${message} Restarting stream...`);
981
1012
  setTimeout(() => {
982
1013
  this.tryReconnect(message);
@@ -1036,9 +1067,7 @@ export class WebRtcPlayerController {
1036
1067
  6
1037
1068
  );
1038
1069
  setTimeout(() => {
1039
- this.pixelStreaming.dispatchEvent(
1040
- new HideFreezeFrameEvent()
1041
- );
1070
+ this.pixelStreaming.dispatchEvent(new HideFreezeFrameEvent());
1042
1071
  this.freezeFrameController.hideFreezeFrame();
1043
1072
  }, this.freezeFrameController.freezeFrameDelay);
1044
1073
  if (this.videoPlayer.getVideoElement()) {
@@ -1102,7 +1131,7 @@ export class WebRtcPlayerController {
1102
1131
  this.pixelStreaming.dispatchEvent(new PlayStreamEvent());
1103
1132
 
1104
1133
  if (this.streamController.audioElement.srcObject) {
1105
- const startMuted = this.config.isFlagEnabled(Flags.StartVideoMuted)
1134
+ const startMuted = this.config.isFlagEnabled(Flags.StartVideoMuted);
1106
1135
  this.streamController.audioElement.muted = startMuted;
1107
1136
 
1108
1137
  if (startMuted) {
@@ -1194,7 +1223,9 @@ export class WebRtcPlayerController {
1194
1223
  Logger.GetStackTrace(),
1195
1224
  'No turn server was found in the Peer Connection Options. TURN cannot be forced, closing connection. Please use STUN instead'
1196
1225
  );
1197
- this.closeSignalingServer('TURN cannot be forced, closing connection. Please use STUN instead.');
1226
+ this.closeSignalingServer(
1227
+ 'TURN cannot be forced, closing connection. Please use STUN instead.'
1228
+ );
1198
1229
  return;
1199
1230
  }
1200
1231
  }
@@ -1240,8 +1271,13 @@ export class WebRtcPlayerController {
1240
1271
  // Browsers emit "connected" when getting first connection and "completed" when finishing
1241
1272
  // candidate checking. However, sometimes browsers can skip "connected" and only emit "completed".
1242
1273
  // Therefore need to check both cases and emit onWebRtcConnected only once on the first hit.
1243
- if (!webRtcConnectedSent &&
1244
- ["connected", "completed"].includes(this.peerConnectionController.peerConnection.iceConnectionState)) {
1274
+ if (
1275
+ !webRtcConnectedSent &&
1276
+ ['connected', 'completed'].includes(
1277
+ this.peerConnectionController.peerConnection
1278
+ .iceConnectionState
1279
+ )
1280
+ ) {
1245
1281
  this.pixelStreaming._onWebRtcConnected();
1246
1282
  webRtcConnectedSent = true;
1247
1283
  }
@@ -1339,33 +1375,32 @@ export class WebRtcPlayerController {
1339
1375
  `Got streamer list ${messageStreamerList.ids}`,
1340
1376
  6
1341
1377
  );
1342
-
1343
- const streamerBusyList = messageStreamerList.streamerBusyList ?? []
1378
+ const streamerBusyList =
1379
+ (
1380
+ messageStreamerList as unknown as {
1381
+ streamerBusyList?: Array<{ streamerId: string }>;
1382
+ }
1383
+ ).streamerBusyList ?? [];
1344
1384
 
1345
1385
  if (streamerBusyList.length > 0) {
1346
1386
  console.log(window.location.href, '======');
1347
- if (window.location.href.indexOf('home') != -1) {
1348
- return
1349
- } else {
1350
- ElMessageBox.confirm(
1351
- '监测到当前窗口有人在使用,是否强制进入?',
1352
- '警告',
1353
- {
1354
- confirmButtonText: '确定',
1355
- cancelButtonText: '取消',
1356
- type: 'warning',
1357
- }
1358
- )
1359
- .then(() => {
1360
- this.webSocketController.sendSubscribe(streamerBusyList[0].streamerId);
1361
- })
1362
- .catch(() => {
1363
-
1364
- })
1365
- }
1387
+ ElMessageBox.confirm(
1388
+ '监测到当前窗口有人在使用,是否强制进入?',
1389
+ '警告',
1390
+ {
1391
+ confirmButtonText: '确定',
1392
+ cancelButtonText: '取消',
1393
+ type: 'warning'
1394
+ }
1395
+ )
1396
+ .then(() => {
1397
+ this.webSocketController.sendSubscribe(
1398
+ streamerBusyList[0].streamerId
1399
+ );
1400
+ })
1401
+ .catch(() => {});
1366
1402
  }
1367
1403
 
1368
-
1369
1404
  // 将streamer添加到UI中
1370
1405
  const settingOptions = [...messageStreamerList.ids]; // 复制原始的messageStreamerList.ids
1371
1406
  // settingOptions.unshift(''); // 在顶部添加一个空选项
@@ -1379,9 +1414,15 @@ export class WebRtcPlayerController {
1379
1414
  let wantedStreamerId: string = null;
1380
1415
  let autoSelectedStreamerId: string = null;
1381
1416
 
1382
- const waitForStreamer = this.config.isFlagEnabled(Flags.WaitForStreamer);
1383
- const reconnectLimit = this.config.getNumericSettingValue(NumericParameters.MaxReconnectAttempts);
1384
- const reconnectDelay = this.config.getNumericSettingValue(NumericParameters.StreamerAutoJoinInterval);
1417
+ const waitForStreamer = this.config.isFlagEnabled(
1418
+ Flags.WaitForStreamer
1419
+ );
1420
+ const reconnectLimit = this.config.getNumericSettingValue(
1421
+ NumericParameters.MaxReconnectAttempts
1422
+ );
1423
+ const reconnectDelay = this.config.getNumericSettingValue(
1424
+ NumericParameters.StreamerAutoJoinInterval
1425
+ );
1385
1426
 
1386
1427
  // 首先,我们通过各种方式找出一个通缉的主播id
1387
1428
  const urlParams = new URLSearchParams(window.location.search);
@@ -1394,10 +1435,16 @@ export class WebRtcPlayerController {
1394
1435
  }
1395
1436
 
1396
1437
  // 现在我们看看能不能选出来。
1397
- if (wantedStreamerId && messageStreamerList.ids.includes(wantedStreamerId)) {
1438
+ if (
1439
+ wantedStreamerId &&
1440
+ messageStreamerList.ids.includes(wantedStreamerId)
1441
+ ) {
1398
1442
  // 如果想要的流在列表中。我们选择它
1399
1443
  autoSelectedStreamerId = wantedStreamerId;
1400
- } else if ((!wantedStreamerId || !waitForStreamer) && messageStreamerList.ids.length == 1) {
1444
+ } else if (
1445
+ (!wantedStreamerId || !waitForStreamer) &&
1446
+ messageStreamerList.ids.length == 1
1447
+ ) {
1401
1448
  // 否则,如果我们没有等待想要的streamer,而且只有一个streamer,请连接到它
1402
1449
  autoSelectedStreamerId = messageStreamerList.ids[0];
1403
1450
  }
@@ -1541,8 +1588,12 @@ export class WebRtcPlayerController {
1541
1588
 
1542
1589
  /* */
1543
1590
  this.setMouseInputEnabled(this.config.isFlagEnabled(Flags.MouseInput));
1544
- this.setKeyboardInputEnabled(this.config.isFlagEnabled(Flags.KeyboardInput));
1545
- this.setGamePadInputEnabled(this.config.isFlagEnabled(Flags.GamepadInput));
1591
+ this.setKeyboardInputEnabled(
1592
+ this.config.isFlagEnabled(Flags.KeyboardInput)
1593
+ );
1594
+ this.setGamePadInputEnabled(
1595
+ this.config.isFlagEnabled(Flags.GamepadInput)
1596
+ );
1546
1597
  }
1547
1598
 
1548
1599
  /**
@@ -1671,11 +1722,11 @@ export class WebRtcPlayerController {
1671
1722
  sendLatencyTest() {
1672
1723
  this.latencyStartTime = Date.now();
1673
1724
 
1674
- this.streamMessageController.toStreamerHandlers.get(
1675
- 'LatencyTest'
1676
- )([JSON.stringify({
1677
- StartTime: this.latencyStartTime
1678
- })]);
1725
+ this.streamMessageController.toStreamerHandlers.get('LatencyTest')([
1726
+ JSON.stringify({
1727
+ StartTime: this.latencyStartTime
1728
+ })
1729
+ ]);
1679
1730
  }
1680
1731
 
1681
1732
  /**
@@ -1700,11 +1751,11 @@ export class WebRtcPlayerController {
1700
1751
  Logger.Log(Logger.GetStackTrace(), `MinQP=${minQP}\n`, 6);
1701
1752
 
1702
1753
  if (minQP != null) {
1703
- this.streamMessageController.toStreamerHandlers.get(
1704
- 'Command'
1705
- )([JSON.stringify({
1706
- 'Encoder.MinQP': minQP
1707
- })]);
1754
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1755
+ JSON.stringify({
1756
+ 'Encoder.MinQP': minQP
1757
+ })
1758
+ ]);
1708
1759
  }
1709
1760
  }
1710
1761
 
@@ -1721,65 +1772,73 @@ export class WebRtcPlayerController {
1721
1772
  Logger.Log(Logger.GetStackTrace(), `MaxQP=${maxQP}\n`, 6);
1722
1773
 
1723
1774
  if (maxQP != null) {
1724
- this.streamMessageController.toStreamerHandlers.get(
1725
- 'Command'
1726
- )([JSON.stringify({
1727
- 'Encoder.MaxQP': maxQP
1728
- })]);
1775
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1776
+ JSON.stringify({
1777
+ 'Encoder.MaxQP': maxQP
1778
+ })
1779
+ ]);
1729
1780
  }
1730
1781
  }
1731
1782
 
1732
1783
  /**
1733
- * Send the { WebRTC.MinBitrate: SomeNumber }} command to UE to set
1734
- * the minimum bitrate that we allow WebRTC to use
1784
+ * Send the { WebRTC.MinBitrate: SomeNumber }} command to UE to set
1785
+ * the minimum bitrate that we allow WebRTC to use
1735
1786
  * (note setting this too high in poor networks can be problematic).
1736
1787
  * @param minBitrate - The minimum bitrate we would like WebRTC to not fall below.
1737
1788
  */
1738
1789
  sendWebRTCMinBitrate(minBitrate: number) {
1739
- Logger.Log(Logger.GetStackTrace(), `WebRTC Min Bitrate=${minBitrate}`, 6);
1790
+ Logger.Log(
1791
+ Logger.GetStackTrace(),
1792
+ `WebRTC Min Bitrate=${minBitrate}`,
1793
+ 6
1794
+ );
1740
1795
  if (minBitrate != null) {
1741
- this.streamMessageController.toStreamerHandlers.get(
1742
- 'Command'
1743
- )([JSON.stringify({
1744
- 'WebRTC.MinBitrate': minBitrate
1745
- })]);
1796
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1797
+ JSON.stringify({
1798
+ 'WebRTC.MinBitrate': minBitrate
1799
+ })
1800
+ ]);
1746
1801
  }
1747
1802
  }
1748
1803
 
1749
1804
  /**
1750
- * Send the { WebRTC.MaxBitrate: SomeNumber }} command to UE to set
1751
- * the minimum bitrate that we allow WebRTC to use
1805
+ * Send the { WebRTC.MaxBitrate: SomeNumber }} command to UE to set
1806
+ * the minimum bitrate that we allow WebRTC to use
1752
1807
  * (note setting this too low could result in blocky video).
1753
1808
  * @param minBitrate - The minimum bitrate we would like WebRTC to not fall below.
1754
1809
  */
1755
1810
  sendWebRTCMaxBitrate(maxBitrate: number) {
1756
- Logger.Log(Logger.GetStackTrace(), `WebRTC Max Bitrate=${maxBitrate}`, 6);
1811
+ Logger.Log(
1812
+ Logger.GetStackTrace(),
1813
+ `WebRTC Max Bitrate=${maxBitrate}`,
1814
+ 6
1815
+ );
1757
1816
  if (maxBitrate != null) {
1758
- this.streamMessageController.toStreamerHandlers.get(
1759
- 'Command'
1760
- )([JSON.stringify({
1761
- 'WebRTC.MaxBitrate': maxBitrate
1762
- })]);
1817
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1818
+ JSON.stringify({
1819
+ 'WebRTC.MaxBitrate': maxBitrate
1820
+ })
1821
+ ]);
1763
1822
  }
1764
1823
  }
1765
1824
 
1766
1825
  /**
1767
1826
  * Send the { WebRTC.Fps: SomeNumber }} UE 5.0+
1768
- * and { WebRTC.MaxFps } UE 4.27 command to set
1769
- * the maximum fps we would like WebRTC to stream at.
1827
+ * and { WebRTC.MaxFps } UE 4.27 command to set
1828
+ * the maximum fps we would like WebRTC to stream at.
1770
1829
  * @param fps - The maximum stream fps.
1771
1830
  */
1772
1831
  sendWebRTCFps(fps: number) {
1773
1832
  Logger.Log(Logger.GetStackTrace(), `WebRTC FPS=${fps}`, 6);
1774
1833
  if (fps != null) {
1775
- this.streamMessageController.toStreamerHandlers.get(
1776
- 'Command'
1777
- )([JSON.stringify({ 'WebRTC.Fps': fps })]);
1834
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1835
+ JSON.stringify({ 'WebRTC.Fps': fps })
1836
+ ]);
1778
1837
 
1779
1838
  /* TODO: Remove when UE 4.27 unsupported. */
1780
- this.streamMessageController.toStreamerHandlers.get(
1781
- 'Command'
1782
- )([JSON.stringify({ 'WebRTC.MaxFps': fps })]);
1839
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1840
+ JSON.stringify({ 'WebRTC.MaxFps': fps })
1841
+ ]);
1783
1842
  }
1784
1843
  }
1785
1844
 
@@ -1793,9 +1852,9 @@ export class WebRtcPlayerController {
1793
1852
  6
1794
1853
  );
1795
1854
 
1796
- this.streamMessageController.toStreamerHandlers.get(
1797
- 'Command'
1798
- )([JSON.stringify({ 'stat.fps': '' })]);
1855
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1856
+ JSON.stringify({ 'stat.fps': '' })
1857
+ ]);
1799
1858
  }
1800
1859
 
1801
1860
  /**
@@ -1820,9 +1879,9 @@ export class WebRtcPlayerController {
1820
1879
  6
1821
1880
  );
1822
1881
 
1823
- this.streamMessageController.toStreamerHandlers.get(
1824
- 'UIInteraction'
1825
- )([JSON.stringify(descriptor)]);
1882
+ this.streamMessageController.toStreamerHandlers.get('UIInteraction')([
1883
+ JSON.stringify(descriptor)
1884
+ ]);
1826
1885
  }
1827
1886
 
1828
1887
  /**
@@ -1835,9 +1894,9 @@ export class WebRtcPlayerController {
1835
1894
  6
1836
1895
  );
1837
1896
 
1838
- this.streamMessageController.toStreamerHandlers.get(
1839
- 'Command'
1840
- )([JSON.stringify(descriptor)]);
1897
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1898
+ JSON.stringify(descriptor)
1899
+ ]);
1841
1900
  }
1842
1901
 
1843
1902
  /**
@@ -1850,11 +1909,11 @@ export class WebRtcPlayerController {
1850
1909
  6
1851
1910
  );
1852
1911
 
1853
- this.streamMessageController.toStreamerHandlers.get(
1854
- 'Command'
1855
- )([JSON.stringify({
1856
- ConsoleCommand: command,
1857
- })]);
1912
+ this.streamMessageController.toStreamerHandlers.get('Command')([
1913
+ JSON.stringify({
1914
+ ConsoleCommand: command
1915
+ })
1916
+ ]);
1858
1917
  }
1859
1918
 
1860
1919
  /**
@@ -1909,7 +1968,7 @@ export class WebRtcPlayerController {
1909
1968
  latencyTestResults.endToEndLatency =
1910
1969
  ~~(latencyTestResults.frameDisplayDeltaTimeMs +
1911
1970
  latencyTestResults.networkLatency,
1912
- +latencyTestResults.CaptureToSendMs);
1971
+ +latencyTestResults.CaptureToSendMs);
1913
1972
  }
1914
1973
  this.pixelStreaming._onLatencyTestResult(latencyTestResults);
1915
1974
  }
@@ -1927,8 +1986,11 @@ export class WebRtcPlayerController {
1927
1986
  const responseAsString = new TextDecoder('utf-16').decode(
1928
1987
  message.slice(1)
1929
1988
  );
1930
- const latencyTestResponse: DataChannelLatencyTestResponse = JSON.parse(responseAsString);
1931
- this.pixelStreaming._onDataChannelLatencyTestResponse(latencyTestResponse);
1989
+ const latencyTestResponse: DataChannelLatencyTestResponse =
1990
+ JSON.parse(responseAsString);
1991
+ this.pixelStreaming._onDataChannelLatencyTestResponse(
1992
+ latencyTestResponse
1993
+ );
1932
1994
  }
1933
1995
 
1934
1996
  /**
@@ -1961,7 +2023,10 @@ export class WebRtcPlayerController {
1961
2023
  parsedInitialSettings.PixelStreaming;
1962
2024
  }
1963
2025
 
1964
- if (parsedInitialSettings.ConfigOptions && parsedInitialSettings.ConfigOptions.DefaultToHover !== undefined) {
2026
+ if (
2027
+ parsedInitialSettings.ConfigOptions &&
2028
+ parsedInitialSettings.ConfigOptions.DefaultToHover !== undefined
2029
+ ) {
1965
2030
  this.config.setFlagEnabled(
1966
2031
  Flags.HoveringMouseMode,
1967
2032
  !!parsedInitialSettings.ConfigOptions.DefaultToHover
@@ -2098,11 +2163,17 @@ export class WebRtcPlayerController {
2098
2163
  if (isEnabled) {
2099
2164
  this.gamePadController = this.inputClassesFactory.registerGamePad();
2100
2165
  this.gamePadController.onGamepadConnected = () => {
2101
- this.streamMessageController.toStreamerHandlers.get('GamepadConnected')();
2102
- }
2103
- this.gamePadController.onGamepadDisconnected = (controllerIdx: number) => {
2104
- this.streamMessageController.toStreamerHandlers.get('GamepadDisconnected')([controllerIdx]);
2105
- }
2166
+ this.streamMessageController.toStreamerHandlers.get(
2167
+ 'GamepadConnected'
2168
+ )();
2169
+ };
2170
+ this.gamePadController.onGamepadDisconnected = (
2171
+ controllerIdx: number
2172
+ ) => {
2173
+ this.streamMessageController.toStreamerHandlers.get(
2174
+ 'GamepadDisconnected'
2175
+ )([controllerIdx]);
2176
+ };
2106
2177
  }
2107
2178
  }
2108
2179
 
@@ -2121,24 +2192,32 @@ export class WebRtcPlayerController {
2121
2192
  );
2122
2193
  }
2123
2194
 
2124
- public registerMessageHandler(name: string, direction: MessageDirection, handler?: (data: ArrayBuffer | Array<number | string>) => void) {
2125
- if (direction === MessageDirection.FromStreamer && typeof handler === 'undefined') {
2195
+ public registerMessageHandler(
2196
+ name: string,
2197
+ direction: MessageDirection,
2198
+ handler?: (data: ArrayBuffer | Array<number | string>) => void
2199
+ ) {
2200
+ if (
2201
+ direction === MessageDirection.FromStreamer &&
2202
+ typeof handler === 'undefined'
2203
+ ) {
2126
2204
  Logger.Warning(
2127
2205
  Logger.GetStackTrace(),
2128
2206
  `Unable to register handler for ${name} as no handler was passed`
2129
2207
  );
2130
2208
  }
2131
2209
 
2132
-
2133
2210
  this.streamMessageController.registerMessageHandler(
2134
2211
  direction,
2135
2212
  name,
2136
- (data: Array<number | string>) => (typeof handler === 'undefined' && direction === MessageDirection.ToStreamer) ?
2137
- this.sendMessageController.sendMessageToStreamer(
2138
- name,
2139
- data
2140
- ) :
2141
- handler(data)
2213
+ (data: Array<number | string>) =>
2214
+ typeof handler === 'undefined' &&
2215
+ direction === MessageDirection.ToStreamer
2216
+ ? this.sendMessageController.sendMessageToStreamer(
2217
+ name,
2218
+ data
2219
+ )
2220
+ : handler(data)
2142
2221
  );
2143
2222
  }
2144
2223
  }