@spatialwalk/avatarkit-rtc 1.0.0-beta.4 → 1.0.0-beta.6
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.
- package/dist/core/AvatarPlayer.d.ts +13 -0
- package/dist/core/AvatarPlayer.d.ts.map +1 -1
- package/dist/core/RTCProvider.d.ts +2 -13
- package/dist/core/RTCProvider.d.ts.map +1 -1
- package/dist/index10.js +47 -80
- package/dist/index10.js.map +1 -1
- package/dist/index11.js +386 -14
- package/dist/index11.js.map +1 -1
- package/dist/index12.js +64 -346
- package/dist/index12.js.map +1 -1
- package/dist/index13.js +14 -174
- package/dist/index13.js.map +1 -1
- package/dist/index2.js +2 -2
- package/dist/index2.js.map +1 -1
- package/dist/index3.js +136 -27
- package/dist/index3.js.map +1 -1
- package/dist/index4.js +6 -18
- package/dist/index4.js.map +1 -1
- package/dist/index6.js +246 -5
- package/dist/index6.js.map +1 -1
- package/dist/index8.js +1 -1
- package/dist/index9.js +163 -60
- package/dist/index9.js.map +1 -1
- package/dist/providers/agora/AgoraProvider.d.ts +0 -13
- package/dist/providers/agora/AgoraProvider.d.ts.map +1 -1
- package/dist/providers/base/BaseProvider.d.ts +47 -1
- package/dist/providers/base/BaseProvider.d.ts.map +1 -1
- package/dist/providers/livekit/LiveKitProvider.d.ts +0 -13
- package/dist/providers/livekit/LiveKitProvider.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index6.js
CHANGED
|
@@ -4,7 +4,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
import { decodeAnimationKeyframes } from "./index8.js";
|
|
5
5
|
import { logger } from "./index7.js";
|
|
6
6
|
const _AnimationHandler = class _AnimationHandler {
|
|
7
|
-
// True when fallback to idle was triggered due to stall
|
|
8
7
|
/**
|
|
9
8
|
* @internal
|
|
10
9
|
*/
|
|
@@ -57,11 +56,36 @@ const _AnimationHandler = class _AnimationHandler {
|
|
|
57
56
|
__publicField(this, "onStreamStalledCallback", null);
|
|
58
57
|
/** @internal */
|
|
59
58
|
__publicField(this, "isStalledFallback", false);
|
|
59
|
+
// True when fallback to idle was triggered due to stall
|
|
60
|
+
// Playback stats
|
|
61
|
+
/** @internal */
|
|
62
|
+
__publicField(this, "playbackStatsTimer", null);
|
|
63
|
+
/** @internal */
|
|
64
|
+
__publicField(this, "playbackFrameCount", 0);
|
|
65
|
+
/** @internal */
|
|
66
|
+
__publicField(this, "playbackFrameTimestamps", []);
|
|
67
|
+
/** @internal */
|
|
68
|
+
__publicField(this, "playbackGapCount", 0);
|
|
69
|
+
/** @internal */
|
|
70
|
+
__publicField(this, "playbackExpectedSeq", -1);
|
|
71
|
+
// Jitter buffer
|
|
72
|
+
/** @internal */
|
|
73
|
+
__publicField(this, "bufferState", "direct");
|
|
74
|
+
/** @internal */
|
|
75
|
+
__publicField(this, "frameBuffer", /* @__PURE__ */ new Map());
|
|
76
|
+
/** @internal */
|
|
77
|
+
__publicField(this, "bufferNextSeq", -1);
|
|
78
|
+
/** @internal */
|
|
79
|
+
__publicField(this, "bufferDrainTimer", null);
|
|
80
|
+
/** @internal */
|
|
81
|
+
__publicField(this, "bufferLastDrainTime", 0);
|
|
60
82
|
this.renderer = renderer;
|
|
61
83
|
this.decoder = config.decoder ?? decodeAnimationKeyframes;
|
|
62
84
|
this.config = {
|
|
63
85
|
transitionStartFrameCount: config.transitionStartFrameCount ?? 8,
|
|
64
|
-
transitionEndFrameCount: config.transitionEndFrameCount ?? 12
|
|
86
|
+
transitionEndFrameCount: config.transitionEndFrameCount ?? 12,
|
|
87
|
+
enableJitterBuffer: config.enableJitterBuffer ?? true,
|
|
88
|
+
maxBufferDelayMs: config.maxBufferDelayMs ?? 80
|
|
65
89
|
};
|
|
66
90
|
this.onStreamStalledCallback = config.onStreamStalled ?? null;
|
|
67
91
|
}
|
|
@@ -88,6 +112,14 @@ const _AnimationHandler = class _AnimationHandler {
|
|
|
88
112
|
}
|
|
89
113
|
this.lastFrameReceivedTime = now;
|
|
90
114
|
this.animationFrameCount++;
|
|
115
|
+
const keyframes = this.decoder(protobufData);
|
|
116
|
+
if (!keyframes || keyframes.length === 0) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (this.config.enableJitterBuffer && frameSeq !== void 0) {
|
|
120
|
+
this.bufferFrame(keyframes[0], frameSeq);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
91
123
|
this.renderedFrameCount++;
|
|
92
124
|
if (frameSeq !== void 0 && this.lastRenderedFrameSeq !== -1) {
|
|
93
125
|
if (frameSeq < this.lastRenderedFrameSeq) {
|
|
@@ -109,9 +141,14 @@ const _AnimationHandler = class _AnimationHandler {
|
|
|
109
141
|
if (frameSeq !== void 0) {
|
|
110
142
|
this.lastRenderedFrameSeq = frameSeq;
|
|
111
143
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
144
|
+
this.renderer.renderFrame(keyframes[0]);
|
|
145
|
+
this.playbackFrameTimestamps.push(performance.now());
|
|
146
|
+
this.playbackFrameCount++;
|
|
147
|
+
if (frameSeq !== void 0) {
|
|
148
|
+
if (this.playbackExpectedSeq >= 0 && frameSeq > this.playbackExpectedSeq) {
|
|
149
|
+
this.playbackGapCount += frameSeq - this.playbackExpectedSeq;
|
|
150
|
+
}
|
|
151
|
+
this.playbackExpectedSeq = frameSeq + 1;
|
|
115
152
|
}
|
|
116
153
|
}
|
|
117
154
|
/**
|
|
@@ -146,6 +183,7 @@ const _AnimationHandler = class _AnimationHandler {
|
|
|
146
183
|
this.lastFrameReceivedTime = Date.now();
|
|
147
184
|
this.hasReportedStall = false;
|
|
148
185
|
this.startWatchdog();
|
|
186
|
+
this.startPlaybackStats();
|
|
149
187
|
const targetFrame = keyframes[0];
|
|
150
188
|
const frames = frameCount ?? this.config.transitionStartFrameCount;
|
|
151
189
|
logger.info("AnimationHandler", `Generating ${frames} transition frames to target`);
|
|
@@ -239,6 +277,8 @@ const _AnimationHandler = class _AnimationHandler {
|
|
|
239
277
|
this.animationFrameCount = 0;
|
|
240
278
|
this.hasHandledTransitionStart = false;
|
|
241
279
|
this.hasHandledTransitionEnd = false;
|
|
280
|
+
this.resetPlaybackStats();
|
|
281
|
+
this.flushBuffer();
|
|
242
282
|
logger.info("AnimationHandler", "Frame tracking reset");
|
|
243
283
|
}
|
|
244
284
|
/**
|
|
@@ -266,6 +306,7 @@ const _AnimationHandler = class _AnimationHandler {
|
|
|
266
306
|
clearTimeout(this.transitionTimeoutId);
|
|
267
307
|
this.transitionTimeoutId = null;
|
|
268
308
|
}
|
|
309
|
+
this.flushBuffer();
|
|
269
310
|
}
|
|
270
311
|
/**
|
|
271
312
|
* Clean up resources.
|
|
@@ -320,6 +361,200 @@ const _AnimationHandler = class _AnimationHandler {
|
|
|
320
361
|
}
|
|
321
362
|
this.hasReportedStall = false;
|
|
322
363
|
this.isStalledFallback = false;
|
|
364
|
+
this.stopPlaybackStats();
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Start the playback stats reporting timer.
|
|
368
|
+
* @internal
|
|
369
|
+
*/
|
|
370
|
+
startPlaybackStats() {
|
|
371
|
+
if (this.playbackStatsTimer) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
this.resetPlaybackStats();
|
|
375
|
+
this.playbackStatsTimer = setInterval(() => {
|
|
376
|
+
this.reportPlaybackStats();
|
|
377
|
+
}, 1e3);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Stop the playback stats reporting timer.
|
|
381
|
+
* @internal
|
|
382
|
+
*/
|
|
383
|
+
stopPlaybackStats() {
|
|
384
|
+
if (this.playbackStatsTimer) {
|
|
385
|
+
clearInterval(this.playbackStatsTimer);
|
|
386
|
+
this.playbackStatsTimer = null;
|
|
387
|
+
}
|
|
388
|
+
this.resetPlaybackStats();
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Reset playback stats counters.
|
|
392
|
+
* @internal
|
|
393
|
+
*/
|
|
394
|
+
resetPlaybackStats() {
|
|
395
|
+
this.playbackFrameCount = 0;
|
|
396
|
+
this.playbackFrameTimestamps = [];
|
|
397
|
+
this.playbackGapCount = 0;
|
|
398
|
+
this.playbackExpectedSeq = -1;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Report playback stats (called every 1s by timer).
|
|
402
|
+
* Logs FPS, frame loss rate, and playback jitter.
|
|
403
|
+
* @internal
|
|
404
|
+
*/
|
|
405
|
+
reportPlaybackStats() {
|
|
406
|
+
if (this.isPlayingTransition) {
|
|
407
|
+
this.resetPlaybackStats();
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
if (this.playbackFrameCount === 0) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
const fps = this.playbackFrameCount;
|
|
414
|
+
const totalExpected = this.playbackFrameCount + this.playbackGapCount;
|
|
415
|
+
const lossRate = totalExpected > 0 ? this.playbackGapCount / totalExpected * 100 : 0;
|
|
416
|
+
let jitter = 0;
|
|
417
|
+
if (this.playbackFrameTimestamps.length >= 2) {
|
|
418
|
+
const intervals = [];
|
|
419
|
+
for (let i = 1; i < this.playbackFrameTimestamps.length; i++) {
|
|
420
|
+
intervals.push(this.playbackFrameTimestamps[i] - this.playbackFrameTimestamps[i - 1]);
|
|
421
|
+
}
|
|
422
|
+
const mean = intervals.reduce((a, b) => a + b, 0) / intervals.length;
|
|
423
|
+
const variance = intervals.reduce((sum, v) => sum + (v - mean) ** 2, 0) / intervals.length;
|
|
424
|
+
jitter = Math.sqrt(variance);
|
|
425
|
+
}
|
|
426
|
+
logger.info(
|
|
427
|
+
"AnimationHandler",
|
|
428
|
+
`Playback stats: fps=${fps}, lossRate=${lossRate.toFixed(1)}%, jitter=${jitter.toFixed(1)}ms`
|
|
429
|
+
);
|
|
430
|
+
this.playbackFrameCount = 0;
|
|
431
|
+
this.playbackFrameTimestamps = [];
|
|
432
|
+
this.playbackGapCount = 0;
|
|
433
|
+
}
|
|
434
|
+
// ── Jitter Buffer ──
|
|
435
|
+
/**
|
|
436
|
+
* Insert a decoded frame into the jitter buffer.
|
|
437
|
+
* Handles dedup, enforces max size, and drives the buffer state machine.
|
|
438
|
+
* @internal
|
|
439
|
+
*/
|
|
440
|
+
bufferFrame(flame, seq) {
|
|
441
|
+
if (this.frameBuffer.has(seq)) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
this.frameBuffer.set(seq, { flame, seq, receivedAt: performance.now() });
|
|
445
|
+
if (this.frameBuffer.size > _AnimationHandler.BUFFER_MAX_SIZE) {
|
|
446
|
+
let oldestSeq = Infinity;
|
|
447
|
+
for (const k of this.frameBuffer.keys()) {
|
|
448
|
+
if (k < oldestSeq) oldestSeq = k;
|
|
449
|
+
}
|
|
450
|
+
this.frameBuffer.delete(oldestSeq);
|
|
451
|
+
}
|
|
452
|
+
switch (this.bufferState) {
|
|
453
|
+
case "direct":
|
|
454
|
+
this.bufferState = "filling";
|
|
455
|
+
if (this.bufferNextSeq < 0) {
|
|
456
|
+
this.bufferNextSeq = seq;
|
|
457
|
+
}
|
|
458
|
+
logger.info("AnimationHandler", `Jitter buffer: filling (first frame seq=${seq})`);
|
|
459
|
+
if (this.frameBuffer.size >= _AnimationHandler.BUFFER_INITIAL_FILL) {
|
|
460
|
+
this.startBufferDrain();
|
|
461
|
+
}
|
|
462
|
+
break;
|
|
463
|
+
case "filling":
|
|
464
|
+
if (this.frameBuffer.size >= _AnimationHandler.BUFFER_INITIAL_FILL) {
|
|
465
|
+
this.startBufferDrain();
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
case "starved":
|
|
469
|
+
this.startBufferDrain();
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Begin draining the buffer at 25fps.
|
|
475
|
+
* @internal
|
|
476
|
+
*/
|
|
477
|
+
startBufferDrain() {
|
|
478
|
+
this.bufferState = "draining";
|
|
479
|
+
if (this.bufferNextSeq < 0) {
|
|
480
|
+
let minSeq = Infinity;
|
|
481
|
+
for (const k of this.frameBuffer.keys()) {
|
|
482
|
+
if (k < minSeq) minSeq = k;
|
|
483
|
+
}
|
|
484
|
+
this.bufferNextSeq = minSeq;
|
|
485
|
+
}
|
|
486
|
+
logger.info("AnimationHandler", `Jitter buffer: draining (${this.frameBuffer.size} frames buffered)`);
|
|
487
|
+
this.bufferLastDrainTime = performance.now();
|
|
488
|
+
this.drainBufferFrame();
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Drain one frame from the buffer and schedule the next drain.
|
|
492
|
+
* Handles missing frames (skip-ahead after maxBufferDelayMs) and starvation.
|
|
493
|
+
* @internal
|
|
494
|
+
*/
|
|
495
|
+
drainBufferFrame() {
|
|
496
|
+
this.bufferDrainTimer = null;
|
|
497
|
+
if (this.bufferState !== "draining") {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const frame = this.frameBuffer.get(this.bufferNextSeq);
|
|
501
|
+
if (frame) {
|
|
502
|
+
this.renderBufferedFrame(frame);
|
|
503
|
+
this.frameBuffer.delete(this.bufferNextSeq);
|
|
504
|
+
this.bufferNextSeq++;
|
|
505
|
+
} else if (this.frameBuffer.size > 0) {
|
|
506
|
+
let oldestSeq = Infinity;
|
|
507
|
+
for (const k of this.frameBuffer.keys()) {
|
|
508
|
+
if (k < oldestSeq) oldestSeq = k;
|
|
509
|
+
}
|
|
510
|
+
const oldestFrame = this.frameBuffer.get(oldestSeq);
|
|
511
|
+
const waitTime = performance.now() - oldestFrame.receivedAt;
|
|
512
|
+
if (waitTime > this.config.maxBufferDelayMs) {
|
|
513
|
+
const gap = oldestSeq - this.bufferNextSeq;
|
|
514
|
+
this.playbackGapCount += gap;
|
|
515
|
+
logger.warn(
|
|
516
|
+
"AnimationHandler",
|
|
517
|
+
`Jitter buffer: skipping ${gap} frame(s) from seq ${this.bufferNextSeq} to ${oldestSeq}`
|
|
518
|
+
);
|
|
519
|
+
this.renderBufferedFrame(oldestFrame);
|
|
520
|
+
this.frameBuffer.delete(oldestSeq);
|
|
521
|
+
this.bufferNextSeq = oldestSeq + 1;
|
|
522
|
+
}
|
|
523
|
+
} else {
|
|
524
|
+
this.bufferState = "starved";
|
|
525
|
+
logger.warn("AnimationHandler", "Jitter buffer: starved, pausing drain");
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const now = performance.now();
|
|
529
|
+
const nextTarget = this.bufferLastDrainTime + _AnimationHandler.BUFFER_FRAME_INTERVAL_MS;
|
|
530
|
+
const delay = Math.max(0, nextTarget - now);
|
|
531
|
+
this.bufferLastDrainTime = nextTarget;
|
|
532
|
+
this.bufferDrainTimer = setTimeout(() => this.drainBufferFrame(), delay);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Render a single frame from the buffer and collect playback stats.
|
|
536
|
+
* @internal
|
|
537
|
+
*/
|
|
538
|
+
renderBufferedFrame(frame) {
|
|
539
|
+
this.renderer.renderFrame(frame.flame);
|
|
540
|
+
this.lastRenderedFrameSeq = frame.seq;
|
|
541
|
+
this.renderedFrameCount++;
|
|
542
|
+
this.playbackFrameTimestamps.push(performance.now());
|
|
543
|
+
this.playbackFrameCount++;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Flush the jitter buffer, stop the drain loop, and revert to direct mode.
|
|
547
|
+
* @internal
|
|
548
|
+
*/
|
|
549
|
+
flushBuffer() {
|
|
550
|
+
this.frameBuffer.clear();
|
|
551
|
+
this.bufferState = "direct";
|
|
552
|
+
this.bufferNextSeq = -1;
|
|
553
|
+
this.bufferLastDrainTime = 0;
|
|
554
|
+
if (this.bufferDrainTimer !== null) {
|
|
555
|
+
clearTimeout(this.bufferDrainTimer);
|
|
556
|
+
this.bufferDrainTimer = null;
|
|
557
|
+
}
|
|
323
558
|
}
|
|
324
559
|
/**
|
|
325
560
|
* Play a single transition frame and schedule the next one.
|
|
@@ -360,6 +595,12 @@ const _AnimationHandler = class _AnimationHandler {
|
|
|
360
595
|
};
|
|
361
596
|
/** @internal */
|
|
362
597
|
__publicField(_AnimationHandler, "STALL_TIMEOUT_MS", 3e3);
|
|
598
|
+
/** @internal */
|
|
599
|
+
__publicField(_AnimationHandler, "BUFFER_MAX_SIZE", 4);
|
|
600
|
+
/** @internal */
|
|
601
|
+
__publicField(_AnimationHandler, "BUFFER_INITIAL_FILL", 2);
|
|
602
|
+
/** @internal */
|
|
603
|
+
__publicField(_AnimationHandler, "BUFFER_FRAME_INTERVAL_MS", 40);
|
|
363
604
|
let AnimationHandler = _AnimationHandler;
|
|
364
605
|
export {
|
|
365
606
|
AnimationHandler
|
package/dist/index6.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index6.js","sources":["../src/core/AnimationHandler.ts"],"sourcesContent":["/**\n * Animation Handler - Orchestrates animation playback and transitions.\n *\n * This module handles:\n * - Animation frame rendering\n * - Transition playback from idle to animation and back\n * - Frame timing at 25fps\n * - Session state tracking\n *\n * The handler relies on server-sent packet flags (Transition, TransitionEnd, Idle)\n * to determine when to generate transitions, rather than maintaining complex internal state.\n *\n * @internal\n * @packageDocumentation\n */\n\nimport type { Flame } from '../proto/animation';\nimport { decodeAnimationKeyframes } from '../proto/animation';\nimport { logger } from '../utils';\n\n/**\n * Interface for decoding protobuf animation data.\n * Allows custom decoder implementation if needed.\n * @internal\n */\nexport type AnimationDecoder = (protobufData: ArrayBuffer) => Flame[] | null;\n\n/**\n * Interface that applications must implement to render avatar frames.\n * The SDK calls these methods to control the avatar.\n * @internal\n */\nexport interface AvatarRenderer {\n /**\n * Render a single animation frame.\n * @param flame - The frame to render, or undefined to render idle\n * @param startIdle - If true and flame is undefined, start idle animation loop\n */\n renderFrame(flame: Flame | undefined, startIdle?: boolean): void;\n\n /**\n * Generate transition frames from idle position to target frame.\n * @param targetFrame - The target frame to transition to\n * @param frameCount - Number of transition frames to generate\n * @returns Promise resolving to array of transition frames\n */\n generateTransitionFromIdle(\n targetFrame: Flame,\n frameCount: number\n ): Promise<Flame[]>;\n\n /**\n * Check if the renderer is available and ready.\n * @returns true if renderer is ready to accept frames\n */\n isReady(): boolean;\n}\n\n/**\n * Configuration for AnimationHandler.\n * @internal\n */\nexport interface AnimationHandlerConfig {\n /**\n * Number of transition frames when starting animation.\n * Default: 8 (~320ms at 25fps)\n */\n transitionStartFrameCount?: number;\n\n /**\n * Number of transition frames when ending animation.\n * Default: 12 (~480ms at 25fps)\n */\n transitionEndFrameCount?: number;\n\n /**\n * Custom decoder function.\n * Uses built-in protobuf decoder if not provided.\n */\n decoder?: AnimationDecoder;\n\n /**\n * Callback when data stream stalls and fallback to idle is triggered.\n * Called when no animation frames received for 3 seconds during speaking session.\n */\n onStreamStalled?: () => void;\n}\n\n/**\n * AnimationHandler manages all animation playback and transition logic.\n *\n * @internal\n * This class is used internally by AvatarPlayer.\n * Applications should not instantiate this class directly.\n */\nexport class AnimationHandler {\n /** @internal */\n private renderer: AvatarRenderer;\n /** @internal */\n private decoder: AnimationDecoder;\n /** @internal */\n private config: Required<Omit<AnimationHandlerConfig, 'decoder' | 'onStreamStalled'>>;\n\n // Frame tracking\n /** @internal */\n private animationFrameCount = 0;\n /** @internal */\n private lastRenderedFrameSeq = -1;\n /** @internal */\n private renderedFrameCount = 0;\n\n // Transition state\n /** @internal */\n private isPlayingTransition = false;\n /** @internal */\n private isTransitioningToIdle = false;\n /** @internal */\n private transitionFrames: Flame[] = [];\n /** @internal */\n private transitionFrameIndex = 0;\n /** @internal */\n private transitionTimeoutId: ReturnType<typeof setTimeout> | null = null;\n\n // Guards against race conditions during async transition generation\n /** @internal */\n private isGeneratingStartTransition = false;\n /** @internal */\n private isGeneratingEndTransition = false;\n\n // Session-level flags to prevent duplicate handling\n // These are reset in resetTracking() for new sessions\n /** @internal */\n private hasHandledTransitionStart = false;\n /** @internal */\n private hasHandledTransitionEnd = false;\n\n // Watchdog for detecting stalled data stream\n /** @internal */\n private lastFrameReceivedTime = 0;\n /** @internal */\n private isInSession = false;\n /** @internal */\n private watchdogTimer: ReturnType<typeof setInterval> | null = null;\n /** @internal */\n private hasReportedStall = false;\n /** @internal */\n private static readonly STALL_TIMEOUT_MS = 3000;\n /** @internal */\n private onStreamStalledCallback: (() => void) | null = null;\n /** @internal */\n private isStalledFallback = false; // True when fallback to idle was triggered due to stall\n\n /**\n * @internal\n */\n constructor(renderer: AvatarRenderer, config: AnimationHandlerConfig = {}) {\n this.renderer = renderer;\n this.decoder = config.decoder ?? decodeAnimationKeyframes;\n this.config = {\n transitionStartFrameCount: config.transitionStartFrameCount ?? 8,\n transitionEndFrameCount: config.transitionEndFrameCount ?? 12,\n };\n this.onStreamStalledCallback = config.onStreamStalled ?? null;\n }\n\n /**\n * Handle animation data received from RTC provider.\n * @param protobufData - Raw protobuf bytes\n * @param frameSeq - Frame sequence number (optional)\n * @param isRecovered - Whether this frame was recovered via ALR\n * @internal\n */\n handleAnimationData(\n protobufData: ArrayBuffer,\n frameSeq?: number,\n isRecovered?: boolean\n ): void {\n // If we were in transition, stop it and play normal animation\n if (this.isPlayingTransition) {\n this.stopTransition();\n }\n\n // Update watchdog state\n const now = Date.now();\n if (this.hasReportedStall) {\n // Recovered from stall\n const stallDuration = now - this.lastFrameReceivedTime;\n logger.info('AnimationHandler', `Data stream resumed after ${stallDuration}ms stall`);\n this.hasReportedStall = false;\n }\n // If we were in stalled fallback, clear the flag (data has resumed, no transition needed)\n if (this.isStalledFallback) {\n logger.info('AnimationHandler', 'Resuming from stall fallback, rendering directly without transition');\n this.isStalledFallback = false;\n }\n this.lastFrameReceivedTime = now;\n\n this.animationFrameCount++;\n this.renderedFrameCount++;\n\n // Check for out-of-order delivery\n if (frameSeq !== undefined && this.lastRenderedFrameSeq !== -1) {\n if (frameSeq < this.lastRenderedFrameSeq) {\n // Out-of-order frame - discard (already rendered a later frame)\n logger.warn(\n 'AnimationHandler',\n `OUT-OF-ORDER: seq=${frameSeq}, lastRendered=${this.lastRenderedFrameSeq}${isRecovered ? ' [RECOVERED]' : ''}, discarding`\n );\n return;\n } else if (frameSeq === this.lastRenderedFrameSeq) {\n // Duplicate frame - skip silently (expected when server sends redundant frames)\n return;\n } else if (frameSeq > this.lastRenderedFrameSeq + 1) {\n const gap = frameSeq - this.lastRenderedFrameSeq - 1;\n logger.warn(\n 'AnimationHandler',\n `GAP: ${gap} frame(s) between ${this.lastRenderedFrameSeq} and ${frameSeq}${isRecovered ? ' [RECOVERED]' : ''}`\n );\n }\n }\n\n if (frameSeq !== undefined) {\n this.lastRenderedFrameSeq = frameSeq;\n }\n\n // Decode and render\n const keyframes = this.decoder(protobufData);\n\n if (keyframes && keyframes.length > 0) {\n this.renderer.renderFrame(keyframes[0]);\n }\n }\n\n /**\n * Handle transition packet - generate and play transition from idle to target.\n * Only starts transition on the first packet; subsequent packets are ignored while transitioning.\n * @param protobufData - Protobuf data containing target frame\n * @param frameCount - Number of transition frames (overrides config if provided)\n * @internal\n */\n async handleTransitionData(\n protobufData: ArrayBuffer,\n frameCount?: number\n ): Promise<void> {\n // Ignore if we've already handled a transition start for this session\n if (this.hasHandledTransitionStart) {\n return;\n }\n // Ignore if already playing or generating a start transition\n if (this.isPlayingTransition && !this.isTransitioningToIdle) {\n return;\n }\n if (this.isGeneratingStartTransition) {\n return;\n }\n\n if (!this.renderer.isReady()) {\n logger.warn('AnimationHandler', 'Renderer not ready for transition');\n return;\n }\n\n // Decode target frame\n const keyframes = this.decoder(protobufData);\n if (!keyframes || keyframes.length === 0) {\n logger.warn('AnimationHandler', 'No target keyframe in transition data');\n return;\n }\n\n // Mark that we've handled transition start for this session\n this.hasHandledTransitionStart = true;\n // Reset transition end flag since we're starting a new transition\n this.hasHandledTransitionEnd = false;\n\n // Start session and watchdog\n this.isInSession = true;\n this.lastFrameReceivedTime = Date.now();\n this.hasReportedStall = false;\n this.startWatchdog();\n\n const targetFrame = keyframes[0];\n const frames = frameCount ?? this.config.transitionStartFrameCount;\n logger.info('AnimationHandler', `Generating ${frames} transition frames to target`);\n\n // Set guard flag before async operation\n this.isGeneratingStartTransition = true;\n\n try {\n // Generate transition frames from idle to target\n const transitionFrames = await this.renderer.generateTransitionFromIdle(\n targetFrame,\n frames\n );\n logger.info('AnimationHandler', `Generated ${transitionFrames.length} transition frames`);\n\n // Start playing transition frames at 25fps\n this.isPlayingTransition = true;\n this.isTransitioningToIdle = false;\n this.transitionFrames = transitionFrames;\n this.transitionFrameIndex = 0;\n\n this.playTransitionFrame();\n } catch (error) {\n logger.error('AnimationHandler', 'Failed to generate transition:', error);\n // Fallback: render target directly\n this.renderer.renderFrame(targetFrame);\n } finally {\n this.isGeneratingStartTransition = false;\n }\n }\n\n /**\n * Handle transition end - generate and play reverse transition back to idle.\n * Only starts transition on the first packet; subsequent packets are ignored while transitioning.\n * @param protobufData - Protobuf data containing last animation frame\n * @param frameCount - Number of transition frames (overrides config if provided)\n * @internal\n */\n async handleTransitionToIdle(\n protobufData: ArrayBuffer,\n frameCount?: number\n ): Promise<void> {\n // Ignore if we've already handled a transition end for this session\n if (this.hasHandledTransitionEnd) {\n return;\n }\n // Ignore if already playing or generating an end transition\n if (this.isPlayingTransition && this.isTransitioningToIdle) {\n return;\n }\n if (this.isGeneratingEndTransition) {\n return;\n }\n\n if (!this.renderer.isReady()) {\n logger.warn('AnimationHandler', 'Renderer not ready for transition to idle');\n this.renderer.renderFrame(undefined, true);\n return;\n }\n\n // Decode last animation frame\n const keyframes = this.decoder(protobufData);\n if (!keyframes || keyframes.length === 0) {\n logger.warn('AnimationHandler', 'No last keyframe in transition end data, starting idle directly');\n this.renderer.renderFrame(undefined, true);\n return;\n }\n\n // Mark that we've handled transition end for this session\n this.hasHandledTransitionEnd = true;\n\n const lastFrame = keyframes[0];\n const frames = frameCount ?? this.config.transitionEndFrameCount;\n logger.info('AnimationHandler', `Generating ${frames} reverse transition frames to idle`);\n\n // Set guard flag before async operation\n this.isGeneratingEndTransition = true;\n\n try {\n // Generate transition frames from idle to last frame, then reverse\n const transitionFrames = await this.renderer.generateTransitionFromIdle(\n lastFrame,\n frames\n );\n logger.info('AnimationHandler', `Generated ${transitionFrames.length} transition frames, reversing for playback`);\n\n // Reverse frames to play from last animation frame back to idle\n const reversedFrames = transitionFrames.slice().reverse();\n\n // Start playing reversed transition at 25fps\n this.isPlayingTransition = true;\n this.isTransitioningToIdle = true;\n this.transitionFrames = reversedFrames;\n this.transitionFrameIndex = 0;\n\n this.playTransitionFrame();\n } catch (error) {\n logger.error('AnimationHandler', 'Failed to generate reverse transition:', error);\n this.renderer.renderFrame(undefined, true);\n } finally {\n this.isGeneratingEndTransition = false;\n }\n }\n\n /**\n * Start idle animation.\n * @internal\n */\n startIdle(): void {\n this.isInSession = false;\n this.hasReportedStall = false;\n this.renderer.renderFrame(undefined, true);\n }\n\n /**\n * Reset animation frame tracking (call on session start).\n * @internal\n */\n resetTracking(): void {\n this.lastRenderedFrameSeq = -1;\n this.renderedFrameCount = 0;\n this.animationFrameCount = 0;\n // Reset session-level transition flags for new session\n this.hasHandledTransitionStart = false;\n this.hasHandledTransitionEnd = false;\n logger.info('AnimationHandler', 'Frame tracking reset');\n }\n\n /**\n * Check if currently playing transition frames.\n * @internal\n */\n isInTransition(): boolean {\n return this.isPlayingTransition;\n }\n\n /**\n * Stop transition playback.\n * @internal\n */\n stopTransition(): void {\n if (\n this.isPlayingTransition ||\n this.isGeneratingStartTransition ||\n this.isGeneratingEndTransition\n ) {\n logger.info('AnimationHandler', 'Stopping transition playback');\n }\n this.isPlayingTransition = false;\n this.isTransitioningToIdle = false;\n this.isGeneratingStartTransition = false;\n this.isGeneratingEndTransition = false;\n // Note: We intentionally do NOT reset hasHandledTransitionStart/End here\n // Those are session-level flags, only reset in resetTracking()\n this.transitionFrames = [];\n this.transitionFrameIndex = 0;\n if (this.transitionTimeoutId !== null) {\n clearTimeout(this.transitionTimeoutId);\n this.transitionTimeoutId = null;\n }\n }\n\n /**\n * Clean up resources.\n * @internal\n */\n dispose(): void {\n this.stopTransition();\n this.stopWatchdog();\n }\n\n /**\n * Start the watchdog timer to detect stalled data streams.\n * @internal\n */\n private startWatchdog(): void {\n if (this.watchdogTimer) {\n return; // Already running\n }\n\n this.watchdogTimer = setInterval(() => {\n if (!this.isInSession) {\n return;\n }\n\n // Don't check during transition playback (we're playing generated frames, not receiving)\n if (this.isPlayingTransition) {\n return;\n }\n\n const elapsed = Date.now() - this.lastFrameReceivedTime;\n if (elapsed > AnimationHandler.STALL_TIMEOUT_MS && !this.hasReportedStall) {\n logger.error(\n 'AnimationHandler',\n `Data stream stalled: no frames received for ${elapsed}ms, falling back to idle`\n );\n this.hasReportedStall = true;\n this.isStalledFallback = true;\n\n // Trigger fallback to idle\n this.startIdle();\n\n // Notify external listener\n if (this.onStreamStalledCallback) {\n try {\n this.onStreamStalledCallback();\n } catch (e) {\n logger.error('AnimationHandler', 'Error in onStreamStalled callback:', e);\n }\n }\n }\n }, 1000); // Check every 1 second\n }\n\n /**\n * Stop the watchdog timer.\n * @internal\n */\n private stopWatchdog(): void {\n if (this.watchdogTimer) {\n clearInterval(this.watchdogTimer);\n this.watchdogTimer = null;\n }\n this.hasReportedStall = false;\n this.isStalledFallback = false;\n }\n\n /**\n * Play a single transition frame and schedule the next one.\n * @internal\n */\n private playTransitionFrame(): void {\n if (\n !this.isPlayingTransition ||\n this.transitionFrameIndex >= this.transitionFrames.length\n ) {\n // Transition complete\n const wasTransitioningToIdle = this.isTransitioningToIdle;\n this.isPlayingTransition = false;\n this.isTransitioningToIdle = false;\n this.transitionFrames = [];\n this.transitionFrameIndex = 0;\n if (this.transitionTimeoutId !== null) {\n clearTimeout(this.transitionTimeoutId);\n this.transitionTimeoutId = null;\n }\n logger.info('AnimationHandler', 'Transition playback complete');\n\n // If transitioning to idle, start idle animation\n if (wasTransitioningToIdle) {\n logger.info('AnimationHandler', 'Starting idle animation after transition');\n this.renderer.renderFrame(undefined, true);\n }\n return;\n }\n\n if (!this.renderer.isReady()) {\n this.isPlayingTransition = false;\n this.isTransitioningToIdle = false;\n return;\n }\n\n const frame = this.transitionFrames[this.transitionFrameIndex];\n this.renderer.renderFrame(frame);\n this.transitionFrameIndex++;\n\n // Schedule next frame at 25fps (40ms)\n this.transitionTimeoutId = setTimeout(() => {\n if (this.isPlayingTransition) {\n this.playTransitionFrame();\n }\n }, 40);\n }\n}\n"],"names":[],"mappings":";;;;;AA+FO,MAAM,oBAAN,MAAM,kBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA,EA4D5B,YAAY,UAA0B,SAAiC,IAAI;AA1DnE;AAAA;AAEA;AAAA;AAEA;AAAA;AAIA;AAAA;AAAA,+CAAsB;AAEtB;AAAA,gDAAuB;AAEvB;AAAA,8CAAqB;AAIrB;AAAA;AAAA,+CAAsB;AAEtB;AAAA,iDAAwB;AAExB;AAAA,4CAA4B,CAAA;AAE5B;AAAA,gDAAuB;AAEvB;AAAA,+CAA4D;AAI5D;AAAA;AAAA,uDAA8B;AAE9B;AAAA,qDAA4B;AAK5B;AAAA;AAAA;AAAA,qDAA4B;AAE5B;AAAA,mDAA0B;AAI1B;AAAA;AAAA,iDAAwB;AAExB;AAAA,uCAAc;AAEd;AAAA,yCAAuD;AAEvD;AAAA,4CAAmB;AAInB;AAAA,mDAA+C;AAE/C;AAAA,6CAAoB;AAM1B,SAAK,WAAW;AAChB,SAAK,UAAU,OAAO,WAAW;AACjC,SAAK,SAAS;AAAA,MACZ,2BAA2B,OAAO,6BAA6B;AAAA,MAC/D,yBAAyB,OAAO,2BAA2B;AAAA,IAAA;AAE7D,SAAK,0BAA0B,OAAO,mBAAmB;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,oBACE,cACA,UACA,aACM;AAEN,QAAI,KAAK,qBAAqB;AAC5B,WAAK,eAAA;AAAA,IACP;AAGA,UAAM,MAAM,KAAK,IAAA;AACjB,QAAI,KAAK,kBAAkB;AAEzB,YAAM,gBAAgB,MAAM,KAAK;AACjC,aAAO,KAAK,oBAAoB,6BAA6B,aAAa,UAAU;AACpF,WAAK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B,WAAK,mBAAmB,CAAA;AACxB,WAAK,uBAAuB;AAC5B,UAAI,KAAK,wBAAwB,MAAM;AACrC,qBAAa,KAAK,mBAAmB;AACrC,aAAK,sBAAsB;AAAA,MAC7B;AACA,aAAO,KAAK,oBAAoB,8BAA8B;AAG9D,UAAI,wBAAwB;AAC1B,eAAO,KAAK,oBAAoB,0CAA0C;AAC1E,aAAK,SAAS,YAAY,QAAW,IAAI;AAAA,MAC3C;AACA;AAAA,IACF;AAEA,QAAI,CAAC,KAAK,SAAS,WAAW;AAC5B,WAAK,sBAAsB;AAC3B,WAAK,wBAAwB;AAC7B;AAAA,IACF;AAEA,UAAM,QAAQ,KAAK,iBAAiB,KAAK,oBAAoB;AAC7D,SAAK,SAAS,YAAY,KAAK;AAC/B,SAAK;AAGL,SAAK,sBAAsB,WAAW,MAAM;AAC1C,UAAI,KAAK,qBAAqB;AAC5B,aAAK,oBAAA;AAAA,MACP;AAAA,IACF,GAAG,EAAE;AAAA,EACP;AACF;AAAA;AAtZE,cAnDW,mBAmDa,oBAAmB;AAnDtC,IAAM,mBAAN;"}
|
|
1
|
+
{"version":3,"file":"index6.js","sources":["../src/core/AnimationHandler.ts"],"sourcesContent":["/**\n * Animation Handler - Orchestrates animation playback and transitions.\n *\n * This module handles:\n * - Animation frame rendering\n * - Transition playback from idle to animation and back\n * - Frame timing at 25fps\n * - Session state tracking\n *\n * The handler relies on server-sent packet flags (Transition, TransitionEnd, Idle)\n * to determine when to generate transitions, rather than maintaining complex internal state.\n *\n * @internal\n * @packageDocumentation\n */\n\nimport type { Flame } from '../proto/animation';\nimport { decodeAnimationKeyframes } from '../proto/animation';\nimport { logger } from '../utils';\n\n/**\n * Interface for decoding protobuf animation data.\n * Allows custom decoder implementation if needed.\n * @internal\n */\nexport type AnimationDecoder = (protobufData: ArrayBuffer) => Flame[] | null;\n\n/**\n * Interface that applications must implement to render avatar frames.\n * The SDK calls these methods to control the avatar.\n * @internal\n */\nexport interface AvatarRenderer {\n /**\n * Render a single animation frame.\n * @param flame - The frame to render, or undefined to render idle\n * @param startIdle - If true and flame is undefined, start idle animation loop\n */\n renderFrame(flame: Flame | undefined, startIdle?: boolean): void;\n\n /**\n * Generate transition frames from idle position to target frame.\n * @param targetFrame - The target frame to transition to\n * @param frameCount - Number of transition frames to generate\n * @returns Promise resolving to array of transition frames\n */\n generateTransitionFromIdle(\n targetFrame: Flame,\n frameCount: number\n ): Promise<Flame[]>;\n\n /**\n * Check if the renderer is available and ready.\n * @returns true if renderer is ready to accept frames\n */\n isReady(): boolean;\n}\n\n/**\n * Configuration for AnimationHandler.\n * @internal\n */\nexport interface AnimationHandlerConfig {\n /**\n * Number of transition frames when starting animation.\n * Default: 8 (~320ms at 25fps)\n */\n transitionStartFrameCount?: number;\n\n /**\n * Number of transition frames when ending animation.\n * Default: 12 (~480ms at 25fps)\n */\n transitionEndFrameCount?: number;\n\n /**\n * Custom decoder function.\n * Uses built-in protobuf decoder if not provided.\n */\n decoder?: AnimationDecoder;\n\n /**\n * Callback when data stream stalls and fallback to idle is triggered.\n * Called when no animation frames received for 3 seconds during speaking session.\n */\n onStreamStalled?: () => void;\n\n /**\n * Enable jitter buffer for smoother playback.\n * When enabled, frames are buffered and rendered in sequence order at a steady 25fps,\n * absorbing network jitter and out-of-order delivery.\n * Default: true\n */\n enableJitterBuffer?: boolean;\n\n /**\n * Maximum delay (in ms) a frame can sit in the jitter buffer before being rendered.\n * Also controls how long to wait for a missing frame before skipping ahead.\n * Default: 80 (2 frames at 25fps)\n */\n maxBufferDelayMs?: number;\n}\n\n/**\n * Jitter buffer state machine.\n * @internal\n */\ntype BufferState = 'direct' | 'filling' | 'draining' | 'starved';\n\n/**\n * A frame held in the jitter buffer awaiting playback.\n * @internal\n */\ninterface BufferedFrame {\n flame: Flame;\n seq: number;\n receivedAt: number;\n}\n\n/**\n * AnimationHandler manages all animation playback and transition logic.\n *\n * @internal\n * This class is used internally by AvatarPlayer.\n * Applications should not instantiate this class directly.\n */\nexport class AnimationHandler {\n /** @internal */\n private renderer: AvatarRenderer;\n /** @internal */\n private decoder: AnimationDecoder;\n /** @internal */\n private config: Required<Omit<AnimationHandlerConfig, 'decoder' | 'onStreamStalled'>>;\n\n // Frame tracking\n /** @internal */\n private animationFrameCount = 0;\n /** @internal */\n private lastRenderedFrameSeq = -1;\n /** @internal */\n private renderedFrameCount = 0;\n\n // Transition state\n /** @internal */\n private isPlayingTransition = false;\n /** @internal */\n private isTransitioningToIdle = false;\n /** @internal */\n private transitionFrames: Flame[] = [];\n /** @internal */\n private transitionFrameIndex = 0;\n /** @internal */\n private transitionTimeoutId: ReturnType<typeof setTimeout> | null = null;\n\n // Guards against race conditions during async transition generation\n /** @internal */\n private isGeneratingStartTransition = false;\n /** @internal */\n private isGeneratingEndTransition = false;\n\n // Session-level flags to prevent duplicate handling\n // These are reset in resetTracking() for new sessions\n /** @internal */\n private hasHandledTransitionStart = false;\n /** @internal */\n private hasHandledTransitionEnd = false;\n\n // Watchdog for detecting stalled data stream\n /** @internal */\n private lastFrameReceivedTime = 0;\n /** @internal */\n private isInSession = false;\n /** @internal */\n private watchdogTimer: ReturnType<typeof setInterval> | null = null;\n /** @internal */\n private hasReportedStall = false;\n /** @internal */\n private static readonly STALL_TIMEOUT_MS = 3000;\n /** @internal */\n private onStreamStalledCallback: (() => void) | null = null;\n /** @internal */\n private isStalledFallback = false; // True when fallback to idle was triggered due to stall\n\n // Playback stats\n /** @internal */\n private playbackStatsTimer: ReturnType<typeof setInterval> | null = null;\n /** @internal */\n private playbackFrameCount = 0;\n /** @internal */\n private playbackFrameTimestamps: number[] = [];\n /** @internal */\n private playbackGapCount = 0;\n /** @internal */\n private playbackExpectedSeq = -1;\n\n // Jitter buffer\n /** @internal */\n private bufferState: BufferState = 'direct';\n /** @internal */\n private frameBuffer = new Map<number, BufferedFrame>();\n /** @internal */\n private bufferNextSeq = -1;\n /** @internal */\n private bufferDrainTimer: ReturnType<typeof setTimeout> | null = null;\n /** @internal */\n private bufferLastDrainTime = 0;\n /** @internal */\n private static readonly BUFFER_MAX_SIZE = 4;\n /** @internal */\n private static readonly BUFFER_INITIAL_FILL = 2;\n /** @internal */\n private static readonly BUFFER_FRAME_INTERVAL_MS = 40;\n\n /**\n * @internal\n */\n constructor(renderer: AvatarRenderer, config: AnimationHandlerConfig = {}) {\n this.renderer = renderer;\n this.decoder = config.decoder ?? decodeAnimationKeyframes;\n this.config = {\n transitionStartFrameCount: config.transitionStartFrameCount ?? 8,\n transitionEndFrameCount: config.transitionEndFrameCount ?? 12,\n enableJitterBuffer: config.enableJitterBuffer ?? true,\n maxBufferDelayMs: config.maxBufferDelayMs ?? 80,\n };\n this.onStreamStalledCallback = config.onStreamStalled ?? null;\n }\n\n /**\n * Handle animation data received from RTC provider.\n * @param protobufData - Raw protobuf bytes\n * @param frameSeq - Frame sequence number (optional)\n * @param isRecovered - Whether this frame was recovered via ALR\n * @internal\n */\n handleAnimationData(\n protobufData: ArrayBuffer,\n frameSeq?: number,\n isRecovered?: boolean\n ): void {\n // If we were in transition, stop it and play normal animation\n if (this.isPlayingTransition) {\n this.stopTransition();\n }\n\n // Update watchdog state\n const now = Date.now();\n if (this.hasReportedStall) {\n // Recovered from stall\n const stallDuration = now - this.lastFrameReceivedTime;\n logger.info('AnimationHandler', `Data stream resumed after ${stallDuration}ms stall`);\n this.hasReportedStall = false;\n }\n // If we were in stalled fallback, clear the flag (data has resumed, no transition needed)\n if (this.isStalledFallback) {\n logger.info('AnimationHandler', 'Resuming from stall fallback, rendering directly without transition');\n this.isStalledFallback = false;\n }\n this.lastFrameReceivedTime = now;\n\n this.animationFrameCount++;\n\n // Decode\n const keyframes = this.decoder(protobufData);\n if (!keyframes || keyframes.length === 0) {\n return;\n }\n\n // Jitter buffer path: insert into buffer instead of rendering directly\n if (this.config.enableJitterBuffer && frameSeq !== undefined) {\n this.bufferFrame(keyframes[0], frameSeq);\n return;\n }\n\n // Direct path (no buffer)\n this.renderedFrameCount++;\n\n // Check for out-of-order delivery\n if (frameSeq !== undefined && this.lastRenderedFrameSeq !== -1) {\n if (frameSeq < this.lastRenderedFrameSeq) {\n // Out-of-order frame - discard (already rendered a later frame)\n logger.warn(\n 'AnimationHandler',\n `OUT-OF-ORDER: seq=${frameSeq}, lastRendered=${this.lastRenderedFrameSeq}${isRecovered ? ' [RECOVERED]' : ''}, discarding`\n );\n return;\n } else if (frameSeq === this.lastRenderedFrameSeq) {\n // Duplicate frame - skip silently (expected when server sends redundant frames)\n return;\n } else if (frameSeq > this.lastRenderedFrameSeq + 1) {\n const gap = frameSeq - this.lastRenderedFrameSeq - 1;\n logger.warn(\n 'AnimationHandler',\n `GAP: ${gap} frame(s) between ${this.lastRenderedFrameSeq} and ${frameSeq}${isRecovered ? ' [RECOVERED]' : ''}`\n );\n }\n }\n\n if (frameSeq !== undefined) {\n this.lastRenderedFrameSeq = frameSeq;\n }\n\n // Render directly\n this.renderer.renderFrame(keyframes[0]);\n\n // Collect playback stats\n this.playbackFrameTimestamps.push(performance.now());\n this.playbackFrameCount++;\n if (frameSeq !== undefined) {\n if (this.playbackExpectedSeq >= 0 && frameSeq > this.playbackExpectedSeq) {\n this.playbackGapCount += frameSeq - this.playbackExpectedSeq;\n }\n this.playbackExpectedSeq = frameSeq + 1;\n }\n }\n\n /**\n * Handle transition packet - generate and play transition from idle to target.\n * Only starts transition on the first packet; subsequent packets are ignored while transitioning.\n * @param protobufData - Protobuf data containing target frame\n * @param frameCount - Number of transition frames (overrides config if provided)\n * @internal\n */\n async handleTransitionData(\n protobufData: ArrayBuffer,\n frameCount?: number\n ): Promise<void> {\n // Ignore if we've already handled a transition start for this session\n if (this.hasHandledTransitionStart) {\n return;\n }\n // Ignore if already playing or generating a start transition\n if (this.isPlayingTransition && !this.isTransitioningToIdle) {\n return;\n }\n if (this.isGeneratingStartTransition) {\n return;\n }\n\n if (!this.renderer.isReady()) {\n logger.warn('AnimationHandler', 'Renderer not ready for transition');\n return;\n }\n\n // Decode target frame\n const keyframes = this.decoder(protobufData);\n if (!keyframes || keyframes.length === 0) {\n logger.warn('AnimationHandler', 'No target keyframe in transition data');\n return;\n }\n\n // Mark that we've handled transition start for this session\n this.hasHandledTransitionStart = true;\n // Reset transition end flag since we're starting a new transition\n this.hasHandledTransitionEnd = false;\n\n // Start session and watchdog\n this.isInSession = true;\n this.lastFrameReceivedTime = Date.now();\n this.hasReportedStall = false;\n this.startWatchdog();\n this.startPlaybackStats();\n\n const targetFrame = keyframes[0];\n const frames = frameCount ?? this.config.transitionStartFrameCount;\n logger.info('AnimationHandler', `Generating ${frames} transition frames to target`);\n\n // Set guard flag before async operation\n this.isGeneratingStartTransition = true;\n\n try {\n // Generate transition frames from idle to target\n const transitionFrames = await this.renderer.generateTransitionFromIdle(\n targetFrame,\n frames\n );\n logger.info('AnimationHandler', `Generated ${transitionFrames.length} transition frames`);\n\n // Start playing transition frames at 25fps\n this.isPlayingTransition = true;\n this.isTransitioningToIdle = false;\n this.transitionFrames = transitionFrames;\n this.transitionFrameIndex = 0;\n\n this.playTransitionFrame();\n } catch (error) {\n logger.error('AnimationHandler', 'Failed to generate transition:', error);\n // Fallback: render target directly\n this.renderer.renderFrame(targetFrame);\n } finally {\n this.isGeneratingStartTransition = false;\n }\n }\n\n /**\n * Handle transition end - generate and play reverse transition back to idle.\n * Only starts transition on the first packet; subsequent packets are ignored while transitioning.\n * @param protobufData - Protobuf data containing last animation frame\n * @param frameCount - Number of transition frames (overrides config if provided)\n * @internal\n */\n async handleTransitionToIdle(\n protobufData: ArrayBuffer,\n frameCount?: number\n ): Promise<void> {\n // Ignore if we've already handled a transition end for this session\n if (this.hasHandledTransitionEnd) {\n return;\n }\n // Ignore if already playing or generating an end transition\n if (this.isPlayingTransition && this.isTransitioningToIdle) {\n return;\n }\n if (this.isGeneratingEndTransition) {\n return;\n }\n\n if (!this.renderer.isReady()) {\n logger.warn('AnimationHandler', 'Renderer not ready for transition to idle');\n this.renderer.renderFrame(undefined, true);\n return;\n }\n\n // Decode last animation frame\n const keyframes = this.decoder(protobufData);\n if (!keyframes || keyframes.length === 0) {\n logger.warn('AnimationHandler', 'No last keyframe in transition end data, starting idle directly');\n this.renderer.renderFrame(undefined, true);\n return;\n }\n\n // Mark that we've handled transition end for this session\n this.hasHandledTransitionEnd = true;\n\n const lastFrame = keyframes[0];\n const frames = frameCount ?? this.config.transitionEndFrameCount;\n logger.info('AnimationHandler', `Generating ${frames} reverse transition frames to idle`);\n\n // Set guard flag before async operation\n this.isGeneratingEndTransition = true;\n\n try {\n // Generate transition frames from idle to last frame, then reverse\n const transitionFrames = await this.renderer.generateTransitionFromIdle(\n lastFrame,\n frames\n );\n logger.info('AnimationHandler', `Generated ${transitionFrames.length} transition frames, reversing for playback`);\n\n // Reverse frames to play from last animation frame back to idle\n const reversedFrames = transitionFrames.slice().reverse();\n\n // Start playing reversed transition at 25fps\n this.isPlayingTransition = true;\n this.isTransitioningToIdle = true;\n this.transitionFrames = reversedFrames;\n this.transitionFrameIndex = 0;\n\n this.playTransitionFrame();\n } catch (error) {\n logger.error('AnimationHandler', 'Failed to generate reverse transition:', error);\n this.renderer.renderFrame(undefined, true);\n } finally {\n this.isGeneratingEndTransition = false;\n }\n }\n\n /**\n * Start idle animation.\n * @internal\n */\n startIdle(): void {\n this.isInSession = false;\n this.hasReportedStall = false;\n this.renderer.renderFrame(undefined, true);\n }\n\n /**\n * Reset animation frame tracking (call on session start).\n * @internal\n */\n resetTracking(): void {\n this.lastRenderedFrameSeq = -1;\n this.renderedFrameCount = 0;\n this.animationFrameCount = 0;\n // Reset session-level transition flags for new session\n this.hasHandledTransitionStart = false;\n this.hasHandledTransitionEnd = false;\n this.resetPlaybackStats();\n this.flushBuffer();\n logger.info('AnimationHandler', 'Frame tracking reset');\n }\n\n /**\n * Check if currently playing transition frames.\n * @internal\n */\n isInTransition(): boolean {\n return this.isPlayingTransition;\n }\n\n /**\n * Stop transition playback.\n * @internal\n */\n stopTransition(): void {\n if (\n this.isPlayingTransition ||\n this.isGeneratingStartTransition ||\n this.isGeneratingEndTransition\n ) {\n logger.info('AnimationHandler', 'Stopping transition playback');\n }\n this.isPlayingTransition = false;\n this.isTransitioningToIdle = false;\n this.isGeneratingStartTransition = false;\n this.isGeneratingEndTransition = false;\n // Note: We intentionally do NOT reset hasHandledTransitionStart/End here\n // Those are session-level flags, only reset in resetTracking()\n this.transitionFrames = [];\n this.transitionFrameIndex = 0;\n if (this.transitionTimeoutId !== null) {\n clearTimeout(this.transitionTimeoutId);\n this.transitionTimeoutId = null;\n }\n this.flushBuffer();\n }\n\n /**\n * Clean up resources.\n * @internal\n */\n dispose(): void {\n this.stopTransition();\n this.stopWatchdog();\n }\n\n /**\n * Start the watchdog timer to detect stalled data streams.\n * @internal\n */\n private startWatchdog(): void {\n if (this.watchdogTimer) {\n return; // Already running\n }\n\n this.watchdogTimer = setInterval(() => {\n if (!this.isInSession) {\n return;\n }\n\n // Don't check during transition playback (we're playing generated frames, not receiving)\n if (this.isPlayingTransition) {\n return;\n }\n\n const elapsed = Date.now() - this.lastFrameReceivedTime;\n if (elapsed > AnimationHandler.STALL_TIMEOUT_MS && !this.hasReportedStall) {\n logger.error(\n 'AnimationHandler',\n `Data stream stalled: no frames received for ${elapsed}ms, falling back to idle`\n );\n this.hasReportedStall = true;\n this.isStalledFallback = true;\n\n // Trigger fallback to idle\n this.startIdle();\n\n // Notify external listener\n if (this.onStreamStalledCallback) {\n try {\n this.onStreamStalledCallback();\n } catch (e) {\n logger.error('AnimationHandler', 'Error in onStreamStalled callback:', e);\n }\n }\n }\n }, 1000); // Check every 1 second\n }\n\n /**\n * Stop the watchdog timer.\n * @internal\n */\n private stopWatchdog(): void {\n if (this.watchdogTimer) {\n clearInterval(this.watchdogTimer);\n this.watchdogTimer = null;\n }\n this.hasReportedStall = false;\n this.isStalledFallback = false;\n this.stopPlaybackStats();\n }\n\n /**\n * Start the playback stats reporting timer.\n * @internal\n */\n private startPlaybackStats(): void {\n if (this.playbackStatsTimer) {\n return; // Already running\n }\n this.resetPlaybackStats();\n this.playbackStatsTimer = setInterval(() => {\n this.reportPlaybackStats();\n }, 1000);\n }\n\n /**\n * Stop the playback stats reporting timer.\n * @internal\n */\n private stopPlaybackStats(): void {\n if (this.playbackStatsTimer) {\n clearInterval(this.playbackStatsTimer);\n this.playbackStatsTimer = null;\n }\n this.resetPlaybackStats();\n }\n\n /**\n * Reset playback stats counters.\n * @internal\n */\n private resetPlaybackStats(): void {\n this.playbackFrameCount = 0;\n this.playbackFrameTimestamps = [];\n this.playbackGapCount = 0;\n this.playbackExpectedSeq = -1;\n }\n\n /**\n * Report playback stats (called every 1s by timer).\n * Logs FPS, frame loss rate, and playback jitter.\n * @internal\n */\n private reportPlaybackStats(): void {\n // Skip reporting during transitions (locally generated frames)\n if (this.isPlayingTransition) {\n this.resetPlaybackStats();\n return;\n }\n\n // Skip if no frames were rendered this interval\n if (this.playbackFrameCount === 0) {\n return;\n }\n\n const fps = this.playbackFrameCount;\n const totalExpected = this.playbackFrameCount + this.playbackGapCount;\n const lossRate = totalExpected > 0 ? (this.playbackGapCount / totalExpected) * 100 : 0;\n\n // Calculate jitter: std deviation of inter-frame intervals\n let jitter = 0;\n if (this.playbackFrameTimestamps.length >= 2) {\n const intervals: number[] = [];\n for (let i = 1; i < this.playbackFrameTimestamps.length; i++) {\n intervals.push(this.playbackFrameTimestamps[i] - this.playbackFrameTimestamps[i - 1]);\n }\n const mean = intervals.reduce((a, b) => a + b, 0) / intervals.length;\n const variance = intervals.reduce((sum, v) => sum + (v - mean) ** 2, 0) / intervals.length;\n jitter = Math.sqrt(variance);\n }\n\n logger.info(\n 'AnimationHandler',\n `Playback stats: fps=${fps}, lossRate=${lossRate.toFixed(1)}%, jitter=${jitter.toFixed(1)}ms`\n );\n\n // Reset counters for next interval\n this.playbackFrameCount = 0;\n this.playbackFrameTimestamps = [];\n this.playbackGapCount = 0;\n }\n\n // ── Jitter Buffer ──\n\n /**\n * Insert a decoded frame into the jitter buffer.\n * Handles dedup, enforces max size, and drives the buffer state machine.\n * @internal\n */\n private bufferFrame(flame: Flame, seq: number): void {\n // Dedup — server sends each frame twice for resilience\n if (this.frameBuffer.has(seq)) {\n return;\n }\n\n this.frameBuffer.set(seq, { flame, seq, receivedAt: performance.now() });\n\n // Enforce max buffer size — drop oldest when full\n if (this.frameBuffer.size > AnimationHandler.BUFFER_MAX_SIZE) {\n let oldestSeq = Infinity;\n for (const k of this.frameBuffer.keys()) {\n if (k < oldestSeq) oldestSeq = k;\n }\n this.frameBuffer.delete(oldestSeq);\n }\n\n // State machine transitions\n switch (this.bufferState) {\n case 'direct':\n this.bufferState = 'filling';\n if (this.bufferNextSeq < 0) {\n this.bufferNextSeq = seq;\n }\n logger.info('AnimationHandler', `Jitter buffer: filling (first frame seq=${seq})`);\n if (this.frameBuffer.size >= AnimationHandler.BUFFER_INITIAL_FILL) {\n this.startBufferDrain();\n }\n break;\n case 'filling':\n if (this.frameBuffer.size >= AnimationHandler.BUFFER_INITIAL_FILL) {\n this.startBufferDrain();\n }\n break;\n case 'starved':\n this.startBufferDrain();\n break;\n case 'draining':\n // Already draining, frame will be picked up by drain loop\n break;\n }\n }\n\n /**\n * Begin draining the buffer at 25fps.\n * @internal\n */\n private startBufferDrain(): void {\n this.bufferState = 'draining';\n if (this.bufferNextSeq < 0) {\n let minSeq = Infinity;\n for (const k of this.frameBuffer.keys()) {\n if (k < minSeq) minSeq = k;\n }\n this.bufferNextSeq = minSeq;\n }\n logger.info('AnimationHandler', `Jitter buffer: draining (${this.frameBuffer.size} frames buffered)`);\n this.bufferLastDrainTime = performance.now();\n this.drainBufferFrame();\n }\n\n /**\n * Drain one frame from the buffer and schedule the next drain.\n * Handles missing frames (skip-ahead after maxBufferDelayMs) and starvation.\n * @internal\n */\n private drainBufferFrame(): void {\n this.bufferDrainTimer = null;\n\n if (this.bufferState !== 'draining') {\n return;\n }\n\n const frame = this.frameBuffer.get(this.bufferNextSeq);\n\n if (frame) {\n // Expected frame found — render it\n this.renderBufferedFrame(frame);\n this.frameBuffer.delete(this.bufferNextSeq);\n this.bufferNextSeq++;\n } else if (this.frameBuffer.size > 0) {\n // Expected frame missing — check if we should skip ahead\n let oldestSeq = Infinity;\n for (const k of this.frameBuffer.keys()) {\n if (k < oldestSeq) oldestSeq = k;\n }\n const oldestFrame = this.frameBuffer.get(oldestSeq)!;\n const waitTime = performance.now() - oldestFrame.receivedAt;\n\n if (waitTime > this.config.maxBufferDelayMs) {\n // Oldest frame has waited too long — skip ahead\n const gap = oldestSeq - this.bufferNextSeq;\n this.playbackGapCount += gap;\n logger.warn(\n 'AnimationHandler',\n `Jitter buffer: skipping ${gap} frame(s) from seq ${this.bufferNextSeq} to ${oldestSeq}`\n );\n this.renderBufferedFrame(oldestFrame);\n this.frameBuffer.delete(oldestSeq);\n this.bufferNextSeq = oldestSeq + 1;\n }\n // else: wait for the missing frame (render nothing this cycle)\n } else {\n // Buffer empty — starvation\n this.bufferState = 'starved';\n logger.warn('AnimationHandler', 'Jitter buffer: starved, pausing drain');\n return; // Don't schedule next drain\n }\n\n // Schedule next drain with drift correction\n const now = performance.now();\n const nextTarget = this.bufferLastDrainTime + AnimationHandler.BUFFER_FRAME_INTERVAL_MS;\n const delay = Math.max(0, nextTarget - now);\n this.bufferLastDrainTime = nextTarget;\n this.bufferDrainTimer = setTimeout(() => this.drainBufferFrame(), delay);\n }\n\n /**\n * Render a single frame from the buffer and collect playback stats.\n * @internal\n */\n private renderBufferedFrame(frame: BufferedFrame): void {\n this.renderer.renderFrame(frame.flame);\n this.lastRenderedFrameSeq = frame.seq;\n this.renderedFrameCount++;\n\n // Playback stats\n this.playbackFrameTimestamps.push(performance.now());\n this.playbackFrameCount++;\n }\n\n /**\n * Flush the jitter buffer, stop the drain loop, and revert to direct mode.\n * @internal\n */\n private flushBuffer(): void {\n this.frameBuffer.clear();\n this.bufferState = 'direct';\n this.bufferNextSeq = -1;\n this.bufferLastDrainTime = 0;\n if (this.bufferDrainTimer !== null) {\n clearTimeout(this.bufferDrainTimer);\n this.bufferDrainTimer = null;\n }\n }\n\n /**\n * Play a single transition frame and schedule the next one.\n * @internal\n */\n private playTransitionFrame(): void {\n if (\n !this.isPlayingTransition ||\n this.transitionFrameIndex >= this.transitionFrames.length\n ) {\n // Transition complete\n const wasTransitioningToIdle = this.isTransitioningToIdle;\n this.isPlayingTransition = false;\n this.isTransitioningToIdle = false;\n this.transitionFrames = [];\n this.transitionFrameIndex = 0;\n if (this.transitionTimeoutId !== null) {\n clearTimeout(this.transitionTimeoutId);\n this.transitionTimeoutId = null;\n }\n logger.info('AnimationHandler', 'Transition playback complete');\n\n // If transitioning to idle, start idle animation\n if (wasTransitioningToIdle) {\n logger.info('AnimationHandler', 'Starting idle animation after transition');\n this.renderer.renderFrame(undefined, true);\n }\n return;\n }\n\n if (!this.renderer.isReady()) {\n this.isPlayingTransition = false;\n this.isTransitioningToIdle = false;\n return;\n }\n\n const frame = this.transitionFrames[this.transitionFrameIndex];\n this.renderer.renderFrame(frame);\n this.transitionFrameIndex++;\n\n // Schedule next frame at 25fps (40ms)\n this.transitionTimeoutId = setTimeout(() => {\n if (this.isPlayingTransition) {\n this.playTransitionFrame();\n }\n }, 40);\n }\n}\n"],"names":[],"mappings":";;;;;AA8HO,MAAM,oBAAN,MAAM,kBAAiB;AAAA;AAAA;AAAA;AAAA,EA0F5B,YAAY,UAA0B,SAAiC,IAAI;AAxFnE;AAAA;AAEA;AAAA;AAEA;AAAA;AAIA;AAAA;AAAA,+CAAsB;AAEtB;AAAA,gDAAuB;AAEvB;AAAA,8CAAqB;AAIrB;AAAA;AAAA,+CAAsB;AAEtB;AAAA,iDAAwB;AAExB;AAAA,4CAA4B,CAAA;AAE5B;AAAA,gDAAuB;AAEvB;AAAA,+CAA4D;AAI5D;AAAA;AAAA,uDAA8B;AAE9B;AAAA,qDAA4B;AAK5B;AAAA;AAAA;AAAA,qDAA4B;AAE5B;AAAA,mDAA0B;AAI1B;AAAA;AAAA,iDAAwB;AAExB;AAAA,uCAAc;AAEd;AAAA,yCAAuD;AA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