Skip to content

Commit c52fa8d

Browse files
committed
Auto scroll
1 parent f99378f commit c52fa8d

1 file changed

Lines changed: 23 additions & 12 deletions

File tree

src/index.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,12 @@ class TeleprompterManager {
283283
if (timeAtEnd < 10000) { // Show END OF TEXT for 10 seconds
284284
return `${progressText}\n\n*** END OF TEXT ***`;
285285
} else {
286-
// After 10 seconds, either reset or schedule replay
286+
// After 10 seconds, just reset the flags
287+
// The actual restart will be handled by the scrolling logic
287288
this.showingEndMessage = false;
288289
this.endTimestamp = null;
289290
this.finalLineTimestamp = null;
290291
this.showingFinalLine = false;
291-
292-
if (this.autoReplay) {
293-
this.scheduleReplay();
294-
} else {
295-
this.resetPosition();
296-
}
297292
}
298293
}
299294
}
@@ -644,12 +639,28 @@ class TeleprompterApp extends TpaServer {
644639
const endText = teleprompterManager.getCurrentVisibleText();
645640
this.showTextToUser(session, sessionId, endText);
646641

647-
// If we're showing the end message, stop this interval and clean up
642+
// If we're showing the end message, check if we should restart
648643
if (teleprompterManager.isShowingEndMessage()) {
649-
clearInterval(endInterval);
650-
this.stopScrolling(sessionId);
651-
this.userTeleprompterManagers.delete(userId);
652-
console.log(`[Session ${sessionId}]: Finished showing end message and cleaned up teleprompter manager for user ${userId}`);
644+
const shouldRestart = teleprompterManager.getAutoReplay();
645+
if (shouldRestart) {
646+
// Stop the current intervals
647+
clearInterval(endInterval);
648+
clearInterval(scrollInterval);
649+
this.sessionScrollers.delete(sessionId);
650+
651+
// Wait 5 seconds then restart
652+
setTimeout(() => {
653+
console.log(`[Session ${sessionId}]: Restarting teleprompter for auto-replay`);
654+
teleprompterManager.resetPosition();
655+
this.startScrolling(session, sessionId, userId);
656+
}, 5000);
657+
} else {
658+
// If not auto-replaying, just stop everything
659+
clearInterval(endInterval);
660+
this.stopScrolling(sessionId);
661+
this.userTeleprompterManagers.delete(userId);
662+
console.log(`[Session ${sessionId}]: Finished showing end message and cleaned up teleprompter manager for user ${userId}`);
663+
}
653664
}
654665
} catch (error: any) {
655666
// If there's an error (likely WebSocket closed), stop the interval

0 commit comments

Comments
 (0)