(
resolution: TimelineResolution,
reason: "loop_guard" | "manual",
)
| 1470 | }; |
| 1471 | |
| 1472 | const rebindTimelineFromResolution = ( |
| 1473 | resolution: TimelineResolution, |
| 1474 | reason: "loop_guard" | "manual", |
| 1475 | ): boolean => { |
| 1476 | if (!resolution.timeline) return false; |
| 1477 | const previousTimeline = state.capturedTimeline; |
| 1478 | if (previousTimeline && previousTimeline === resolution.timeline) { |
| 1479 | return false; |
| 1480 | } |
| 1481 | const previousTime = Math.max(0, state.currentTime || 0); |
| 1482 | const wasPlaying = state.isPlaying; |
| 1483 | state.capturedTimeline = resolution.timeline; |
| 1484 | if (typeof state.capturedTimeline.timeScale === "function") { |
| 1485 | state.capturedTimeline.timeScale(state.playbackRate); |
| 1486 | } |
| 1487 | try { |
| 1488 | state.capturedTimeline.pause(); |
| 1489 | state.capturedTimeline.seek(previousTime, false); |
| 1490 | if (wasPlaying) { |
| 1491 | state.capturedTimeline.play(); |
| 1492 | } |
| 1493 | } catch (err) { |
| 1494 | // keep runtime resilient even if a timeline implementation throws |
| 1495 | swallow("runtime.init.site7", err); |
| 1496 | } |
| 1497 | postRuntimeMessage({ |
| 1498 | source: "hf-preview", |
| 1499 | type: "diagnostic", |
| 1500 | code: "timeline_loop_guard_rebind", |
| 1501 | details: { |
| 1502 | reason, |
| 1503 | previousTime, |
| 1504 | selectedTimelineIds: resolution.selectedTimelineIds ?? [], |
| 1505 | selectedDurationSeconds: resolution.selectedDurationSeconds ?? null, |
| 1506 | mediaDurationFloorSeconds: resolution.mediaDurationFloorSeconds ?? null, |
| 1507 | }, |
| 1508 | }); |
| 1509 | return true; |
| 1510 | }; |
| 1511 | |
| 1512 | let metadataRebindDebounceTimerId: number | null = null; |
| 1513 | let metadataRebindApplied = false; |
no test coverage detected