From 79401f15978264c9674e7be20cde98488684588d Mon Sep 17 00:00:00 2001 From: zepumph Date: Wed, 9 Feb 2022 17:24:00 -0700 Subject: [PATCH] add debug option to UtteranceQueue, https://github.com/phetsims/sun/issues/726 --- js/UtteranceQueue.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/js/UtteranceQueue.js b/js/UtteranceQueue.js index d450871..2b6c5cd 100644 --- a/js/UtteranceQueue.js +++ b/js/UtteranceQueue.js @@ -43,6 +43,7 @@ class UtteranceQueue extends PhetioObject { assert && assert( announcer instanceof Announcer, 'announcer must be an Announcer' ); options = merge( { + debug: false, // add extra logging, helpful during debugging // {boolean} - if true, all functions will be no ops. Used to support runtimes that don't use aria-live as well as // those that do. When true this type will not be instrumented for PhET-iO either. @@ -94,6 +95,9 @@ class UtteranceQueue extends PhetioObject { // announcing that Utterance at the same time. See https://github.com/phetsims/utterance-queue/issues/46. this.announcingUtteranceWrapper = null; + // @private {boolean} + this.debug = options.debug; + // When the Announcer is done with an Utterance, remove priority listeners and remove from the // utteranceToPriorityListenerMap. this.announcer.announcementCompleteEmitter.addListener( utterance => { @@ -156,6 +160,8 @@ class UtteranceQueue extends PhetioObject { // Add to the queue before prioritizing so that we know which Utterances to prioritize against this.queue.push( utteranceWrapper ); + this.debug && console.log( 'addToBack: ', utteranceWrapper.utterance.getAlertText( this.announcer.respectResponseCollectorProperties ) ); + // Add listeners that will re-prioritize the queue when the priorityProperty changes this.addPriorityListenerAndPrioritizeQueue( utteranceWrapper ); } @@ -604,10 +610,12 @@ class UtteranceQueue extends PhetioObject { * @param {UtteranceWrapper} utteranceWrapper */ attemptToAnnounce( utteranceWrapper ) { + const utterance = utteranceWrapper.utterance; + + this.debug && console.log( 'attemptToAnnounce: ', utterance.getAlertText( this.announcer.respectResponseCollectorProperties ) ); // only query and remove the next utterance if the announcer indicates it is ready for speech if ( this.announcer.readyToAnnounce ) { - const utterance = utteranceWrapper.utterance; // only announce the utterance if not muted and the Utterance predicate returns true if ( !this._muted && utterance.predicate() && utterance.getAlertText( this.announcer.respectResponseCollectorProperties ) !== '' ) { @@ -621,6 +629,7 @@ class UtteranceQueue extends PhetioObject { }; utteranceWrapper.utterance.priorityProperty.link( this.announcingUtteranceWrapper.announcingUtterancePriorityListener ); + this.debug && console.log( 'announcing: ', utterance.getAlertText( this.announcer.respectResponseCollectorProperties ) ); this.announcer.announce( utterance, utterance.announcerOptions ); }