PromptQueue object


The PromptQueue object is a browser object used to control prompt playback. It is accessible from script and has no markup element on the SALT page. Not all browsers need to support the PromptQueue module. In an HTML profile where the PromptQueue module is supported, the PromptQueue object will be a child of the window object.

The PromptQueue is maintained as a browser object rather than a markup element for two reasons:

  1. It maintains a central object for playback control. The asynchronous nature of the call to prompt.Queue() means that with multiple queued prompts, the application cannot know (without explicit maintenance scripts) which prompt is currently being played back, and therefore which to pause/stop/resume, etc. when necessary. The PromptQueue object provides a single object for doing this.
  2. This permits prompt playback to be uninterrupted across page transitions, since the PromptQueue object persists across the loading and unloading of individual pages. That is, unlike the markup elements in the DOM, it is not destroyed when its containing page is unloaded (although events which would otherwise be thrown to the prompt elements, are lost if the containing page has been unloaded). An example of this is shown below.

The PromptQueue object operates in the following manner:

It will be seen below that actions of the PromptQueue are local to a subqueue rather than the entire PromptQueue object, with the exception of the Flush() and Change() methods. The events supported by PromptQueue have scope at the level of subqueue. For example, the completion of playback of each subqueue is signaled by the onempty event (see event handlers, below). An onerror event on a single prompt will flush the subqueue in which that prompt was held, but will not affect any other subqueues in the PromptQueue (and therefore does not necessarily halt playback as seen in the event handlers, below). Bargein behavior is also local to a subqueue: that where bargein is set true, an onBargein event on a single prompt will stop playback and flush the current subqueue. Similarly, all PromptQueue methods take effect in the scope of the subqueue rather than that of the PromptQueue object, except PromptQueue.Flush(), which is a global action to flush all the subqueues from the PromptQueue object, and PromptQueue.Change(), which applies adjustments of speed and volume to all subqueues on the PromptQueue.


Properties

Methods

Event Handlers

Examples

This example shows how the PromptQueue is used to ensure seamless prompt playback across page transitions in an HTML profile:

<html xmlns:salt="http://www.saltforum.org/2002/SALT">
    <body>
        <form id="form1" action="nextpage.html">
            <input type="button" onclick="transition();" value="go to next page" />
        </form>

        <salt:prompt id="transitionPrompt">
            Let's go to the next page!
        </salt:prompt>

         <script>
            function transition() {
                transitionPrompt.Queue();
                PromptQueue.Start();
                form1.submit();
            }
        </script>
    </body>
</html>


The prompt will play back during the transition to the next page, because although the transitionPrompt element itself is destroyed when the DOM is torn down for the next page, it has been queued onto the PromptQueue object which is persistent across pages. Subsequent prompts from the next page will be played once the transitionPrompt prompt has been played out.

Notice that the transition() function could be replaced by the simple shorthand transitionPrompt.Start() in the onclick event handler.

 

Certain applications may require not only the content of prompts to be prefetched, but also the earliest possible queuing of prompts in advance of playback, in the interests of efficient operation. The following example shows how individual prompts (or subqueues) which are known to follow the current prompt can be queued while the current prompt is being played back.

This example shows two prompts which are marked with the prefetch attribute (to indicate to the browser that their content should be retrieved at an early opportunity). The first is queued for playback on page load. The second is queued as soon as the first is scheduled for playback by a click on the play button, and is itself played back by a click on the next button.


<prompt id="p1" prefetch="true">
    <content href="http://mybank/getStockName.asp?id=1" />
    <content href="http://mybank/getStockValue.asp?id=1" />
</prompt>
<prompt id="p2" prefetch="true">
    <content href="http://mybank/getStockName.asp?id=2" />
    <content href="http://mybank/getStockValue.asp?id=2" />
</prompt>

<body onload="p1.Queue();">
...
    <input type="button" value="play"
            onclick="PromptQueue.Start(); p2.Queue();" />
    <input type="button" value="next"
            onclick="PromptQueue.Stop(); PromptQueue.Start;"/>
...
</body>

This model can be scaled up to N prompts by ensuring that the next button always queues the following prompt, by calling the relevant function after the PromptQueue.Start() call, e.g.:

<input type="button"
        value="next"
        onclick="PromptQueue.Stop(); PromptQueue.Start(); QueueNextPrompt();" />

where QueueNextPrompt() is a function that decides which prompt needs to be queued next.

A simpler solution for the case where the ordering of the prompts is known in advance would be to call Start on each subqueue in sequential order. That is, not only queue each subqueue but also schedule it for playback in advance. This permits the queuing of multiple subqueues in advance, and, in this case, the 'next' functionality would be a simple call to
PromptQueue
.Stop(), which has the effect of ceasing playback, flushing the current subqueue, and allowing the next to begin playback. (This also allows each subqueue to begin playback immediately after the previous subqueue has finished, without needing to wire the next Start call to the onempty event handler.)

 

Extra info

For details on usage of this element, see the SALT Specification, Version 1.0.