@sage-rsc/talking-head-react 1.0.61 → 1.0.62

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sage-rsc/talking-head-react",
3
- "version": "1.0.61",
3
+ "version": "1.0.62",
4
4
  "description": "A reusable React component for 3D talking avatars with lip-sync and text-to-speech",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -52,11 +52,17 @@ const TalkingHeadAvatar = forwardRef(({
52
52
  const showFullAvatarRef = useRef(showFullAvatar);
53
53
  const pausedSpeechRef = useRef(null); // Track paused speech for resume
54
54
  const speechEndIntervalRef = useRef(null); // Track onSpeechEnd polling interval
55
+ const isPausedRef = useRef(false); // Track pause state for interval checks
55
56
  const [isLoading, setIsLoading] = useState(true);
56
57
  const [error, setError] = useState(null);
57
58
  const [isReady, setIsReady] = useState(false);
58
59
  const [isPaused, setIsPaused] = useState(false);
59
60
 
61
+ // Keep ref in sync with state
62
+ useEffect(() => {
63
+ isPausedRef.current = isPaused;
64
+ }, [isPaused]);
65
+
60
66
  // Update ref when prop changes
61
67
  useEffect(() => {
62
68
  showFullAvatarRef.current = showFullAvatar;
@@ -311,8 +317,8 @@ const TalkingHeadAvatar = forwardRef(({
311
317
  checkInterval = setInterval(() => {
312
318
  checkCount++;
313
319
 
314
- // Don't fire callback if paused
315
- if (isPaused) {
320
+ // Don't fire callback if paused (check ref for current value)
321
+ if (isPausedRef.current) {
316
322
  return;
317
323
  }
318
324
 
@@ -323,7 +329,7 @@ const TalkingHeadAvatar = forwardRef(({
323
329
  checkInterval = null;
324
330
  speechEndIntervalRef.current = null;
325
331
  }
326
- if (!callbackFired && !isPaused) {
332
+ if (!callbackFired && !isPausedRef.current) {
327
333
  callbackFired = true;
328
334
  try {
329
335
  options.onSpeechEnd();
@@ -348,18 +354,18 @@ const TalkingHeadAvatar = forwardRef(({
348
354
  audioPlaylistEmpty &&
349
355
  talkingHead.isAudioPlaying === false;
350
356
 
351
- if (isFinished && !callbackFired && !isPaused) {
357
+ if (isFinished && !callbackFired && !isPausedRef.current) {
352
358
  // Double-check after a small delay to ensure it's really finished
353
359
  setTimeout(() => {
354
360
  // Re-check one more time to be sure, and make sure we're still not paused
355
361
  const finalCheck = talkingHead &&
356
- !isPaused &&
362
+ !isPausedRef.current &&
357
363
  talkingHead.isSpeaking === false &&
358
364
  (!talkingHead.speechQueue || talkingHead.speechQueue.length === 0) &&
359
365
  (!talkingHead.audioPlaylist || talkingHead.audioPlaylist.length === 0) &&
360
366
  talkingHead.isAudioPlaying === false;
361
367
 
362
- if (finalCheck && !callbackFired && !isPaused) {
368
+ if (finalCheck && !callbackFired && !isPausedRef.current) {
363
369
  callbackFired = true;
364
370
  if (checkInterval) {
365
371
  clearInterval(checkInterval);
@@ -437,6 +443,7 @@ const TalkingHeadAvatar = forwardRef(({
437
443
 
438
444
  // Pause the speaking
439
445
  talkingHeadRef.current.pauseSpeaking();
446
+ isPausedRef.current = true;
440
447
  setIsPaused(true);
441
448
  }
442
449
  }