@3dsource/angular-unreal-module 0.0.146-dev.8 → 0.0.146-dev.9
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.
|
@@ -3589,8 +3589,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.2", ngImpor
|
|
|
3589
3589
|
args: [{ providedIn: 'root' }]
|
|
3590
3590
|
}], ctorParameters: () => [] });
|
|
3591
3591
|
|
|
3592
|
-
//
|
|
3592
|
+
// Legacy fallback only: poll interval for head-scripts that predate the
|
|
3593
|
+
// `onSettled` hook. The event-driven path (preferred) carries no such latency.
|
|
3593
3594
|
const ADOPT_POLL_MS = 100;
|
|
3595
|
+
// Safety-net re-check for the event path — covers the (unexpected) case where
|
|
3596
|
+
// `onSettled` never fires. Coarse on purpose: it's a backstop, not the hot
|
|
3597
|
+
// path, so it adds no latency to a healthy adoption.
|
|
3598
|
+
const ADOPT_EVENT_SAFETY_MS = 1000;
|
|
3594
3599
|
/**
|
|
3595
3600
|
* Adopts a WebRTC connection prefetched by the `stream-prefetch.js` head-script
|
|
3596
3601
|
* and parked on `window.__stream`, instead of running `connectToSignaling` from
|
|
@@ -3609,7 +3614,9 @@ class StreamAdoptionService {
|
|
|
3609
3614
|
*
|
|
3610
3615
|
* - nothing parked → emit `false` at once (caller connects normally).
|
|
3611
3616
|
* - already settled (`ready`/`failed`/`adopted`) → adopt-if-ready at once.
|
|
3612
|
-
* - still `connecting` →
|
|
3617
|
+
* - still `connecting` → wait for the script's `onSettled` callback (no
|
|
3618
|
+
* polling latency) and adopt-if-ready the instant it fires; on older
|
|
3619
|
+
* scripts without the hook, fall back to a `timer` poll.
|
|
3613
3620
|
*
|
|
3614
3621
|
* Deliberately NO time budget: for DIRECT orchestration the prefetch holds
|
|
3615
3622
|
* the socket open while the orchestrator provisions a machine, which can take
|
|
@@ -3639,12 +3646,48 @@ class StreamAdoptionService {
|
|
|
3639
3646
|
return of(this.tryAdopt());
|
|
3640
3647
|
}
|
|
3641
3648
|
Logger.info('[Adoption] Prefetch in progress — waiting before connecting');
|
|
3649
|
+
// Preferred path: the script fires `onSettled` the moment it parks
|
|
3650
|
+
// `ready`/`failed`, so we adopt with zero polling lag.
|
|
3651
|
+
if (typeof parked.onSettled === 'function') {
|
|
3652
|
+
return this.awaitSettled$(parked);
|
|
3653
|
+
}
|
|
3654
|
+
// Legacy fallback: older head-script without the hook — poll its state.
|
|
3642
3655
|
return timer(0, ADOPT_POLL_MS).pipe(map$1(() => window.__stream?.state ?? 'failed'),
|
|
3643
3656
|
// Keep polling while still connecting; the `true` (inclusive) emits the
|
|
3644
3657
|
// settling value (`ready`/`failed`) that ends the wait.
|
|
3645
3658
|
takeWhile((state) => state === 'connecting', true), last(), map$1(() => this.tryAdopt()));
|
|
3646
3659
|
});
|
|
3647
3660
|
}
|
|
3661
|
+
/**
|
|
3662
|
+
* Event-driven wait: resolve the instant the script's `onSettled` callback
|
|
3663
|
+
* fires (ready/failed), then adopt-if-ready. Emits exactly once.
|
|
3664
|
+
*
|
|
3665
|
+
* A coarse {@link ADOPT_EVENT_SAFETY_MS} interval is a backstop only — if
|
|
3666
|
+
* `onSettled` somehow never fires it still settles, without adding latency to
|
|
3667
|
+
* the normal case. Teardown (route change → unsubscribe) sets `done`, so a
|
|
3668
|
+
* late callback after cancel can't trigger a stray adoption.
|
|
3669
|
+
*/
|
|
3670
|
+
awaitSettled$(parked) {
|
|
3671
|
+
return new Observable((subscriber) => {
|
|
3672
|
+
let done = false;
|
|
3673
|
+
const finish = () => {
|
|
3674
|
+
if (done)
|
|
3675
|
+
return;
|
|
3676
|
+
done = true;
|
|
3677
|
+
subscriber.next(this.tryAdopt());
|
|
3678
|
+
subscriber.complete();
|
|
3679
|
+
};
|
|
3680
|
+
parked.onSettled?.(() => finish());
|
|
3681
|
+
const safety = setInterval(() => {
|
|
3682
|
+
if ((window.__stream?.state ?? 'failed') !== 'connecting')
|
|
3683
|
+
finish();
|
|
3684
|
+
}, ADOPT_EVENT_SAFETY_MS);
|
|
3685
|
+
return () => {
|
|
3686
|
+
done = true;
|
|
3687
|
+
clearInterval(safety);
|
|
3688
|
+
};
|
|
3689
|
+
});
|
|
3690
|
+
}
|
|
3648
3691
|
/**
|
|
3649
3692
|
* @returns `true` if a ready parked stream was adopted (caller must NOT
|
|
3650
3693
|
* start a fresh connection), `false` otherwise.
|