src/SessionRecording.js
function seekToFrame(index, callback, delay) {

        // Abort any in-progress seek
        abortSeek();

        // Replay frames asynchronously
        seekTimeout = window.setTimeout(function continueSeek() {

            var startIndex;

            // Back up until startIndex represents current state
            for (startIndex = index; startIndex >= 0; startIndex--) {

                var frame = frames[startIndex];

                // If we've reached the current frame, startIndex represents
                // current state by definition
                if (startIndex === currentFrame)
                    break;

                // If frame has associated absolute state, make that frame the
                // current state
                if (frame.clientState) {
                    playbackClient.importState(frame.clientState);
                    break;
                }

            }

            // Advance to frame index after current state
            startIndex++;

            var startTime = new Date().getTime();

            // Replay any applicable incremental frames
            for (; startIndex <= index; startIndex++) {

                // Stop seeking if the operation is taking too long
                var currentTime = new Date().getTime();
                if (currentTime - startTime >= MAXIMUM_SEEK_TIME)
                    break;

                replayFrame(startIndex);
            }

            // Current frame is now at requested index
            currentFrame = startIndex - 1;

            // Notify of changes in position
            if (recording.onseek)
                recording.onseek(recording.getPosition());

            // If the seek operation has not yet completed, schedule continuation
            if (currentFrame !== index)
                seekToFrame(index, callback,
                    Math.max(delay - (new Date().getTime() - startTime), 0));

            // Notify that the requested seek has completed
            else
                callback();

        }, delay || 0);

    }
function seekToFrame(index, callback, delay) {

        // Abort any in-progress seek
        abortSeek();

        // Replay frames asynchronously
        seekTimeout = window.setTimeout(function continueSeek() {

            var startIndex;

            // Back up until startIndex represents current state
            for (startIndex = index; startIndex >= 0; startIndex--) {

                var frame = frames[startIndex];

                // If we've reached the current frame, startIndex represents
                // current state by definition
                if (startIndex === currentFrame)
                    break;

                // If frame has associated absolute state, make that frame the
                // current state
                if (frame.clientState) {
                    playbackClient.importState(frame.clientState);
                    break;
                }

            }

            // Advance to frame index after current state
            startIndex++;

            var startTime = new Date().getTime();

            // Replay any applicable incremental frames
            for (; startIndex <= index; startIndex++) {

                // Stop seeking if the operation is taking too long
                var currentTime = new Date().getTime();
                if (currentTime - startTime >= MAXIMUM_SEEK_TIME)
                    break;

                replayFrame(startIndex);
            }

            // Current frame is now at requested index
            currentFrame = startIndex - 1;

            // Notify of changes in position
            if (recording.onseek)
                recording.onseek(recording.getPosition());

            // If the seek operation has not yet completed, schedule continuation
            if (currentFrame !== index)
                seekToFrame(index, callback,
                    Math.max(delay - (new Date().getTime() - startTime), 0));

            // Notify that the requested seek has completed
            else
                callback();

        }, delay || 0);

    }
function seekToFrame ( index , callback , delay ) { // Abort any in-progress seek abortSeek ( ) ; // Replay frames asynchronously seekTimeout = window . setTimeout ( function continueSeek ( ) { var startIndex ; // Back up until startIndex represents current state for ( startIndex = index ; startIndex >= 0 ; startIndex -- ) { var frame = frames [ startIndex ] ; // If we've reached the current frame, startIndex represents // current state by definition if ( startIndex === currentFrame ) break ; // If frame has associated absolute state, make that frame the // current state if ( frame . clientState ) { playbackClient . importState ( frame . clientState ) ; break ; } } // Advance to frame index after current state startIndex ++ ; var startTime = new Date ( ) . getTime ( ) ; // Replay any applicable incremental frames for ( ; startIndex <= index ; startIndex ++ ) { // Stop seeking if the operation is taking too long var currentTime = new Date ( ) . getTime ( ) ; if ( currentTime - startTime >= MAXIMUM_SEEK_TIME ) break ; replayFrame ( startIndex ) ; } // Current frame is now at requested index currentFrame = startIndex - 1 ; // Notify of changes in position if ( recording . onseek ) recording . onseek ( recording . getPosition ( ) ) ; // If the seek operation has not yet completed, schedule continuation if ( currentFrame !== index ) seekToFrame ( index , callback , Math . max ( delay - ( new Date ( ) . getTime ( ) - startTime ) , 0 ) ) ; // Notify that the requested seek has completed else callback ( ) ; } , delay || 0 ) ; }
Moves the playback position to the given frame, resetting the state of
the playback client and replaying frames as necessary. The seek
operation will proceed asynchronously. If a seek operation is already in
progress, that seek is first aborted. The progress of the seek operation
can be observed through the onseek handler and the provided callback.

@private
@param {Number} index
The index of the frame which should become the new playback
position.

@param {function} callback
The callback to invoke once the seek operation has completed.

@param {Number} [delay=0]
The number of milliseconds that the seek operation should be
scheduled to take.
Moves the playback position to the given frame resetting the state of the playback client and replaying frames as necessary . The seek operation will proceed asynchronously . If a seek operation is already in progress that seek is first aborted . The progress of the seek operation can be observed through the onseek handler and the provided callback .