@3dsource/angular-unreal-module 0.0.200-dev.1 → 0.0.200-dev.2

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,9 +3,9 @@ import { ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef,
3
3
  import { JsonPipe, NgOptimizedImage, NgTemplateOutlet } from "@angular/common";
4
4
  import { Store, createAction, createFeature, createReducer, createSelector, on, props, provideState } from "@ngrx/store";
5
5
  import { Actions, createEffect, ofType, provideEffects } from "@ngrx/effects";
6
- import { BehaviorSubject, EMPTY, NEVER, Observable, Subject, Subscription, TimeoutError, animationFrameScheduler, asyncScheduler, bufferTime, combineLatestWith, concat, concatMap, debounceTime, defer, delay, filter, firstValueFrom, from, fromEvent, ignoreElements, interval, map, merge, mergeMap, of, pairwise, repeat, retry, scan, share, shareReplay, skip, startWith, switchMap, take, takeUntil, takeWhile, tap, throttleTime, throwError, timeout, timer, timestamp, withLatestFrom } from "rxjs";
6
+ import { BehaviorSubject, EMPTY, NEVER, Observable, Subject, Subscription, TimeoutError, animationFrameScheduler, asyncScheduler, bufferTime, combineLatestWith, concat, concatMap, debounceTime, defer, delay, exhaustMap, filter, firstValueFrom, from, fromEvent, ignoreElements, interval, map, merge, mergeMap, of, pairwise, repeat, retry, scan, share, shareReplay, skip, startWith, switchMap, take, takeUntil, takeWhile, tap, throttleTime, throwError, timeout, timer, timestamp, withLatestFrom } from "rxjs";
7
7
  import { UNREAL_CONFIG } from "@3dsource/angular-unreal-module/config";
8
- import { catchError, debounceTime as debounceTime$1, distinctUntilChanged, exhaustMap, filter as filter$1, finalize, first, map as map$1, startWith as startWith$1, switchMap as switchMap$1, take as take$1, takeUntil as takeUntil$1, takeWhile as takeWhile$1, tap as tap$1, timeout as timeout$1, withLatestFrom as withLatestFrom$1 } from "rxjs/operators";
8
+ import { catchError, debounceTime as debounceTime$1, distinctUntilChanged, exhaustMap as exhaustMap$1, filter as filter$1, finalize, first, map as map$1, startWith as startWith$1, switchMap as switchMap$1, take as take$1, takeUntil as takeUntil$1, takeWhile as takeWhile$1, tap as tap$1, timeout as timeout$1, withLatestFrom as withLatestFrom$1 } from "rxjs/operators";
9
9
  import { v4 } from "uuid";
10
10
  import { DIALOG_DATA, Dialog, DialogRef } from "@angular/cdk/dialog";
11
11
  import { HttpClient } from "@angular/common/http";
@@ -2847,13 +2847,6 @@ var WebRtcPlayerService = class WebRtcPlayerService extends SubService {
2847
2847
  try {
2848
2848
  Logger.log(`[DATACHANNEL] Setting up datachannel "${datachannel.label}" callbacks...`);
2849
2849
  datachannel.binaryType = "arraybuffer";
2850
- fromEvent(datachannel, "close").pipe(filter$1(() => !this.isReconnecting()), take(1), takeUntil$1(this.destroy$)).subscribe((e) => {
2851
- Logger.warn(`[DATACHANNEL] Data channel disconnected: ${datachannel.label}(${datachannel.id})`, e);
2852
- this.store.dispatch(disconnectStream({
2853
- reason: DisconnectReason.DataChannelClosed,
2854
- message: "DataChannelClosed"
2855
- }));
2856
- });
2857
2850
  fromEvent(datachannel, "error").pipe(takeUntil$1(merge(this.disconnect$, this.destroy$))).subscribe((e) => {
2858
2851
  const message = `[DATACHANNEL] Data channel "${datachannel.label}" error. id:${datachannel.id}`;
2859
2852
  Logger.error(message, e);
@@ -2864,18 +2857,19 @@ var WebRtcPlayerService = class WebRtcPlayerService extends SubService {
2864
2857
  open$.pipe(tap(() => {
2865
2858
  Logger.info(`[DATACHANNEL] Data channel "${datachannel.label}" connected. id:${datachannel.id}`);
2866
2859
  }), switchMap$1(() => this.videoService.video$.pipe(filter$1(Truthy), take(1))), takeUntil$1(merge(this.disconnect$, this.destroy$))).subscribe(() => this.onDataChannelConnected());
2867
- this.watchForStuckClose(datachannel, open$);
2860
+ const stuckClose$ = open$.pipe(switchMap$1(() => interval(DC_WATCH_INTERVAL_MS)), map$1(() => datachannel.readyState), filter$1((state) => state === "closing" || state === "closed"), take(1), delay(DC_CLOSING_GRACE_MS), map$1(() => `stuck in "${datachannel.readyState}"`));
2861
+ merge(fromEvent(datachannel, "close").pipe(map$1(() => "close event")), stuckClose$).pipe(filter$1(() => this.dcClient === datachannel && !this.isReconnecting()), take(1), takeUntil$1(this.destroy$)).subscribe((cause) => {
2862
+ Logger.warn(`[DATACHANNEL] Data channel disconnected: ${datachannel.label}(${datachannel.id}), ${cause}`);
2863
+ this.store.dispatch(disconnectStream({
2864
+ reason: DisconnectReason.DataChannelClosed,
2865
+ message: "DataChannelClosed"
2866
+ }));
2867
+ });
2868
2868
  } catch (e) {
2869
2869
  Logger.warn("[DATACHANNEL] Datachannel setup caused an exception: ", e);
2870
2870
  this.dcClient = null;
2871
2871
  }
2872
2872
  }
2873
- watchForStuckClose(datachannel, open$) {
2874
- open$.pipe(switchMap$1(() => interval(DC_WATCH_INTERVAL_MS)), filter$1(() => datachannel.readyState === "closing" || datachannel.readyState === "closed"), take(1), switchMap$1(() => timer(DC_CLOSING_GRACE_MS)), filter$1(() => this.dcClient === datachannel && datachannel.readyState !== "open"), takeUntil$1(merge(fromEvent(datachannel, "close"), this.disconnect$, this.destroy$))).subscribe(() => {
2875
- Logger.warn(`[DATACHANNEL] "${datachannel.label}" stuck in "${datachannel.readyState}" with no close event, reconnecting the peer`);
2876
- this.tryReconnectOnSendFailure();
2877
- });
2878
- }
2879
2873
  onDataChannelConnected() {
2880
2874
  let statusMessage = "Session connected, video stream starting.";
2881
2875
  if (navigator.userAgent.includes("Firefox")) statusMessage += "\n If you are experiencing connection problems please try Google Chrome";
@@ -3419,14 +3413,14 @@ var UnrealEffects = class UnrealEffects {
3419
3413
  }), takeWhile((action) => action.type === initSignalling.type, true))));
3420
3414
  });
3421
3415
  this.showUnrealError$ = createEffect(() => {
3422
- return this.actions$.pipe(ofType(showUnrealErrorMessage), map(({ code }) => getRtcErrorMessage(code)), distinctUntilChanged(), filter$1(Truthy), exhaustMap((content) => this.dialog.open(UnrealErrorModalComponent, {
3416
+ return this.actions$.pipe(ofType(showUnrealErrorMessage), map(({ code }) => getRtcErrorMessage(code)), distinctUntilChanged(), filter$1(Truthy), exhaustMap$1((content) => this.dialog.open(UnrealErrorModalComponent, {
3423
3417
  scrollStrategy: this.scrollStrategy,
3424
3418
  data: { content }
3425
3419
  }).closed), map(() => showUnrealErrorMessage({ code: null })));
3426
3420
  });
3427
3421
  this.unrealReceiverReady$ = createEffect(() => {
3428
3422
  const sessionEnded$ = this.actions$.pipe(ofType(setCirrusDisconnected, destroyUnrealScene, resetDataChannelForReconnect));
3429
- return this.actions$.pipe(ofType(dataChannelConnected), withLatestFrom$1(this.store.select(unrealFeature.selectIsReconnecting)), filter$1(([, isReconnecting]) => !isReconnecting), exhaustMap(() => concat(of(dataChannelReady()), NEVER).pipe(takeUntil$1(sessionEnded$))));
3423
+ return this.actions$.pipe(ofType(dataChannelConnected), withLatestFrom$1(this.store.select(unrealFeature.selectIsReconnecting)), filter$1(([, isReconnecting]) => !isReconnecting), exhaustMap$1(() => concat(of(dataChannelReady()), NEVER).pipe(takeUntil$1(sessionEnded$))));
3430
3424
  });
3431
3425
  this.initAppByDataChannelReady$ = createEffect(() => {
3432
3426
  return this.actions$.pipe(ofType(dataChannelReady), switchMap(() => {
@@ -3529,7 +3523,7 @@ var UnrealEffects = class UnrealEffects {
3529
3523
  return this.actions$.pipe(ofType(initSignalling), withLatestFrom$1(this.store.select(unrealFeature.selectMatchUrls), this.store.select(selectIsAutostart), this.store.select(unrealFeature.selectCirrusConnected)), filter$1(([, , autoStart, cirrusConnected]) => {
3530
3524
  if (cirrusConnected) Logger.warn(`SIGNALING REQUEST can't be called when cirrus connection is already established.`);
3531
3525
  return autoStart && !cirrusConnected;
3532
- }), map(([, matchMakerUrls]) => [...matchMakerUrls].filter(Truthy)), filter$1((urls) => urls.length > 0), exhaustMap((urls) => this.streamAdoptionService.awaitAndAdopt$().pipe(switchMap((adopted) => adopted ? EMPTY : this.signallingService.connectToSignaling(urls)), takeUntil$1(this.actions$.pipe(ofType(abortEstablishingConnection))), ignoreElements(), startWith(setEstablishingConnection({ value: true })))));
3526
+ }), map(([, matchMakerUrls]) => [...matchMakerUrls].filter(Truthy)), filter$1((urls) => urls.length > 0), exhaustMap$1((urls) => this.streamAdoptionService.awaitAndAdopt$().pipe(switchMap((adopted) => adopted ? EMPTY : this.signallingService.connectToSignaling(urls)), takeUntil$1(this.actions$.pipe(ofType(abortEstablishingConnection))), ignoreElements(), startWith(setEstablishingConnection({ value: true })))));
3533
3527
  });
3534
3528
  }
3535
3529
  canPeerReconnect() {
@@ -4628,18 +4622,18 @@ var InputService = class InputService extends SubService {
4628
4622
  if (this.unrealConfig?.playwright) return;
4629
4623
  const visibilityHiddenTrigger$ = fromEvent(document, "visibilitychange").pipe(map$1(() => document.visibilityState === "hidden"), filter$1(Truthy));
4630
4624
  const visibilityVisibleTrigger$ = fromEvent(document, "visibilitychange").pipe(map$1(() => document.visibilityState === "visible"), filter$1(Truthy), startWith(true));
4631
- this.deactivatedVideoTrigger$ = merge(this.disconnect$, this.reInit$, visibilityHiddenTrigger$, this.destroy$);
4632
- merge(visibilityVisibleTrigger$, this.store.select(unrealFeature.selectViewportReady).pipe(filter$1(Truthy))).pipe(filter$1(() => !!this.video), takeUntil(this.destroy$)).subscribe(() => this.setup());
4625
+ const unbound$ = merge(this.disconnect$, visibilityHiddenTrigger$, this.destroy$);
4626
+ this.deactivatedVideoTrigger$ = merge(unbound$, this.reInit$);
4627
+ const ready$ = merge(visibilityVisibleTrigger$, this.actions$.pipe(ofType(setViewportReady)));
4628
+ this.videoService.video$.pipe(filter$1(Truthy), switchMap((video) => ready$.pipe(exhaustMap(() => {
4629
+ this.setup(video);
4630
+ return unbound$.pipe(take(1));
4631
+ }))), takeUntil(this.destroy$)).subscribe();
4633
4632
  }
4634
4633
  useKeyboardKeys(keys) {
4635
4634
  this.availableKeys = new Set(keys);
4636
4635
  }
4637
- get video() {
4638
- return this.videoService.video;
4639
- }
4640
- setup() {
4641
- const video = this.video;
4642
- if (!video) return;
4636
+ setup(video) {
4643
4637
  this.options = InputOptions;
4644
4638
  this.reInit$.next();
4645
4639
  this.fingerIds.clear();