@3dsource/angular-unreal-module 0.0.84-dev.1 → 0.0.85

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.
@@ -3,7 +3,7 @@ import { InjectionToken, inject, Injectable, signal, makeEnvironmentProviders, p
3
3
  import { filter, withLatestFrom, distinctUntilChanged, switchMap, catchError, timeout, tap, map as map$1, takeUntil, exhaustMap, debounceTime, takeWhile, delay, skip as skip$1 } from 'rxjs/operators';
4
4
  import { createAction, props, Store, provideState, createReducer, on, createFeature, createSelector } from '@ngrx/store';
5
5
  import { Actions, ofType, provideEffects, createEffect } from '@ngrx/effects';
6
- import { skip, share, merge, Subject, interval, of, map, from, take, fromEvent, timer, throwError, defer, Observable, switchMap as switchMap$1, retry, timeout as timeout$1, tap as tap$1, startWith, combineLatestWith, takeUntil as takeUntil$1, auditTime, EMPTY, debounceTime as debounceTime$1, mergeMap, scan, concatMap, animationFrameScheduler, BehaviorSubject, distinctUntilChanged as distinctUntilChanged$1, concat } from 'rxjs';
6
+ import { skip, share, merge, Subject, interval, of, map, from, take, fromEvent, timer, throwError, defer, Observable, switchMap as switchMap$1, retry, timeout as timeout$1, tap as tap$1, startWith, takeUntil as takeUntil$1, auditTime, EMPTY, debounceTime as debounceTime$1, mergeMap, scan, concatMap, animationFrameScheduler, BehaviorSubject, combineLatestWith, distinctUntilChanged as distinctUntilChanged$1, concat } from 'rxjs';
7
7
  import { Falsy, Truthy, Logger, calculateMedian, clampf, Signal, tapLog, generateUuid, COLOR_CODES, where, KeyboardNumericCode, InvertedKeyMap, Semaphore, lerp, getCanvasCached, getSnapshot, whereNot, HEXtoRGB, RGBtoHSV, inverseLerp, HSVtoRGB, RGBtoHEX, fpIsASameAsB, fitIntoRectangle } from '@3dsource/utils';
8
8
  import { HttpClient } from '@angular/common/http';
9
9
  import { DialogRef, DIALOG_DATA, Dialog } from '@angular/cdk/dialog';
@@ -1626,8 +1626,7 @@ class WebRtcPlayerService extends SubService {
1626
1626
  this.dcClient?.send(data);
1627
1627
  }
1628
1628
  else {
1629
- const error = `DataChannel connection not prepared or in state: ${this.dcClient?.readyState}`;
1630
- throw new Error(error);
1629
+ Logger.colored('black', 'yellow', `DataChannel connection not prepared or in state: ${this.dcClient?.readyState}`);
1631
1630
  }
1632
1631
  }
1633
1632
  setConfig(parOptions = {}) {
@@ -2339,6 +2338,9 @@ class TouchEmulator {
2339
2338
  this.host.emitMouseWheel(this.delta, center.x, center.y);
2340
2339
  }
2341
2340
  registerTouchEvents(playerElement) {
2341
+ if (!playerElement) {
2342
+ return;
2343
+ }
2342
2344
  let finger;
2343
2345
  fromEvent(playerElement, 'touchstart', {
2344
2346
  passive: false,
@@ -2539,6 +2541,7 @@ class InputService extends SubService {
2539
2541
  super();
2540
2542
  this.commandsSender = inject(UnrealCommunicatorService);
2541
2543
  this.isDevMode = inject(DevModeService).isDevMode;
2544
+ this.videoService = inject(VideoService);
2542
2545
  this.defaultKeys = [
2543
2546
  KeyboardNumericCode.KeyW,
2544
2547
  KeyboardNumericCode.KeyS,
@@ -2575,18 +2578,21 @@ class InputService extends SubService {
2575
2578
  const visibilityHiddenTrigger$ = fromEvent(document, 'visibilitychange').pipe(map$1(() => document.visibilityState === 'hidden'), filter(Truthy));
2576
2579
  const visibilityVisibleTrigger$ = fromEvent(document, 'visibilitychange').pipe(map$1(() => document.visibilityState === 'visible'), filter(Truthy), startWith(true));
2577
2580
  this.deactivatedVideoTrigger$ = merge(this.disconnect$, this.reInit$, visibilityHiddenTrigger$);
2578
- fromSignal(UnrealInternalSignalEvents.OnVideoInitialized)
2579
- .pipe(combineLatestWith(visibilityVisibleTrigger$, this.store
2580
- .select(unrealFeature.selectViewportReady)
2581
- .pipe(filter(Truthy), startWith(true))), filter(([video]) => !!video))
2582
- .subscribe(([video]) => this.setup(video));
2581
+ merge(visibilityVisibleTrigger$, this.store.select(unrealFeature.selectViewportReady).pipe(filter(Truthy))).subscribe(() => this.setup());
2583
2582
  }
2584
2583
  useKeyboardKeys(keys) {
2585
2584
  this.availableKeys = keys || [];
2586
2585
  }
2587
- setup(video) {
2586
+ get video() {
2587
+ return this.videoService.video;
2588
+ }
2589
+ setup() {
2590
+ const video = this.video;
2591
+ if (!video) {
2592
+ return;
2593
+ }
2594
+ Logger.log('DEBUG: video initialized: ', video);
2588
2595
  this.options = InputOptions;
2589
- this.video = video;
2590
2596
  this.reInit$.next();
2591
2597
  merge(fromResizeObserver(video), fromSignal(UnrealInternalSignalEvents.VideoAdaptedToContainer))
2592
2598
  .pipe(debounceTime(300), takeUntil$1(this.deactivatedVideoTrigger$))
@@ -2594,7 +2600,7 @@ class InputService extends SubService {
2594
2600
  this.setupNormalizeAndQuantize(video);
2595
2601
  });
2596
2602
  this.setupNormalizeAndQuantize(video);
2597
- this.registerInputs();
2603
+ this.registerInputs(video);
2598
2604
  }
2599
2605
  /**
2600
2606
  * We use `object-fit: cover` on the video element. Since the video can have
@@ -2692,20 +2698,20 @@ class InputService extends SubService {
2692
2698
  sendInputData(data) {
2693
2699
  this.commandsSender.sendInputData(data);
2694
2700
  }
2695
- registerInputs() {
2701
+ registerInputs(video) {
2696
2702
  merge(this.store
2697
2703
  .select(unrealFeature.selectLowBandwidth)
2698
2704
  .pipe(distinctUntilChanged(), filter(Truthy)), fromEvent(window, 'blur'))
2699
- .pipe(filter(() => !!this.video), takeUntil$1(this.deactivatedVideoTrigger$))
2705
+ .pipe(filter(() => !!video), takeUntil$1(this.deactivatedVideoTrigger$))
2700
2706
  .subscribe(() => this.releaseMouseButtons(255, 0, 0));
2701
- this.registerMouseEnterAndLeaveEvents(this.video);
2702
- this.registerHoveringMouseEvents(this.video);
2707
+ this.registerMouseEnterAndLeaveEvents(video);
2708
+ this.registerHoveringMouseEvents(video);
2703
2709
  this.registerKeyboardEvents(this.availableKeys);
2704
2710
  if (InputOptions.fakeMouseWithTouches) {
2705
2711
  new TouchEmulator(this);
2706
2712
  }
2707
2713
  else {
2708
- this.registerTouchEvents(this.video);
2714
+ this.registerTouchEvents(video);
2709
2715
  }
2710
2716
  }
2711
2717
  getTouchPositionWithOffset({ clientX, clientY }) {
@@ -2728,7 +2734,7 @@ class InputService extends SubService {
2728
2734
  const rememberTouch = (touch) => {
2729
2735
  const finger = this.fingers.pop();
2730
2736
  if (finger === undefined) {
2731
- Logger.info('exhausted touch indentifiers');
2737
+ Logger.info('exhausted touch identifiers');
2732
2738
  return;
2733
2739
  }
2734
2740
  this.fingerIds.set(touch.identifier, finger);
@@ -2759,7 +2765,7 @@ class InputService extends SubService {
2759
2765
  byte += 2;
2760
2766
  data.setUint8(byte, this.fingerIds.get(touch.identifier));
2761
2767
  byte += 1;
2762
- // force is between 0.0 and 1.0 so quantize into byte.
2768
+ // force is between 0.0 and 1.0, so quantize into byte.
2763
2769
  // iOs bug: Forced to be always 0.5 on all devices as we do not use forced touch any way;/
2764
2770
  data.setUint8(byte, this.maxByteValue * 0.5);
2765
2771
  byte += 1;
@@ -2897,9 +2903,9 @@ class InputService extends SubService {
2897
2903
  this.emitMouseUp(e.button, x, y);
2898
2904
  e.preventDefault();
2899
2905
  };
2900
- // When the context menu is shown then it is safest to release the button
2901
- // which was pressed when the event happened. This will guarantee we will
2902
- // get at least one mouse up corresponding to a mouse down event. Otherwise
2906
+ // When the context menu is shown, then it is safest to release the button
2907
+ // pressed when the event happened. This will guarantee we will
2908
+ // get at least one mouse up corresponding to a mouse down event. Otherwise,
2903
2909
  // the mouse can get stuck.
2904
2910
  // https://github.com/facebook/react/issues/5531
2905
2911
  // playerElement.oncontextmenu = (e) => {
@@ -2982,7 +2988,7 @@ class InputService extends SubService {
2982
2988
  this.getKeyCode(e),
2983
2989
  Number(e.repeat),
2984
2990
  ]).buffer);
2985
- // Backspace is not considered a keypress in JavaScript but we need it
2991
+ // Backspace is not considered a keypress in JavaScript, but we need it
2986
2992
  // to be so characters may be deleted in a UE4 text entry field.
2987
2993
  if (e.keyCode === SpecialKeyCodes.BackSpace) {
2988
2994
  document.onkeypress({
@@ -3393,6 +3399,7 @@ function provideAngularUnrealModule(config) {
3393
3399
  },
3394
3400
  provideEnvironmentInitializer(() => {
3395
3401
  inject(AggregatorService);
3402
+ inject(InputService);
3396
3403
  inject(StreamStatusTelemetryService);
3397
3404
  inject(ConsoleExtensionsService);
3398
3405
  inject(AFKService);
@@ -4870,11 +4877,9 @@ class UnrealSceneComponent {
4870
4877
  this.lightMode = this.store.selectSignal(unrealFeature.selectLowBandwidth);
4871
4878
  this.isFreezeFrameLoading = this.store.selectSignal(selectIsFreezeFrameLoading);
4872
4879
  this.commandsSender = inject(UnrealCommunicatorService);
4873
- this.inputService = inject(InputService);
4874
4880
  this.videoService = inject(VideoService);
4875
4881
  this.element = inject(ElementRef);
4876
4882
  this.destroyRef = inject(DestroyRef);
4877
- this.inputService.useKeyboardKeys(this.inputService.defaultKeys);
4878
4883
  this.destroyRef.onDestroy(() => this.store.dispatch(destroyUnrealScene()));
4879
4884
  effect(() => {
4880
4885
  const videoElement = this.videoElement();