GUACAMOLE-346: Use internal seekToFrame() to handle frame timing.

This commit is contained in:
Michael Jumper
2017-07-15 17:10:47 -07:00
parent ed3c022f7e
commit 519daeebe2

View File

@@ -151,16 +151,6 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
*/ */
var startRealTimestamp = null; var startRealTimestamp = null;
/**
* The ID of the timeout which will play the next frame, if playback is in
* progress. If playback is not in progress, the ID stored here (if any)
* will not be valid.
*
* @private
* @type {Number}
*/
var playbackTimeout = null;
/** /**
* The ID of the timeout which will continue the in-progress seek * The ID of the timeout which will continue the in-progress seek
* operation. If no seek operation is in progress, the ID stored here (if * operation. If no seek operation is in progress, the ID stored here (if
@@ -327,8 +317,12 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
* *
* @param {function} callback * @param {function} callback
* The callback to invoke once the seek operation has completed. * 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.
*/ */
var seekToFrame = function seekToFrame(index, callback) { var seekToFrame = function seekToFrame(index, callback, delay) {
// Abort any in-progress seek // Abort any in-progress seek
abortSeek(); abortSeek();
@@ -382,13 +376,14 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
// If the seek operation has not yet completed, schedule continuation // If the seek operation has not yet completed, schedule continuation
if (currentFrame !== index) if (currentFrame !== index)
seekToFrame(index, callback); seekToFrame(index, callback,
Math.max(delay - (new Date().getTime() - startTime), 0));
// Notify that the requested seek has completed // Notify that the requested seek has completed
else else
callback(); callback();
}, 0); }, delay || 0);
}; };
@@ -411,9 +406,6 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
*/ */
var continuePlayback = function continuePlayback() { var continuePlayback = function continuePlayback() {
// Advance to next frame
seekToFrame(currentFrame + 1, function playbackSeekComplete() {
// If frames remain after advancing, schedule next frame // If frames remain after advancing, schedule next frame
if (currentFrame + 1 < frames.length) { if (currentFrame + 1 < frames.length) {
@@ -429,7 +421,7 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
var delay = Math.max(nextRealTimestamp - new Date().getTime(), 0); var delay = Math.max(nextRealTimestamp - new Date().getTime(), 0);
// Advance to next frame after enough time has elapsed // Advance to next frame after enough time has elapsed
playbackTimeout = window.setTimeout(function frameDelayElapsed() { seekToFrame(currentFrame + 1, function frameDelayElapsed() {
continuePlayback(); continuePlayback();
}, delay); }, delay);
@@ -439,8 +431,6 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
else else
recording.pause(); recording.pause();
});
}; };
/** /**
@@ -641,7 +631,7 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
*/ */
this.pause = function pause() { this.pause = function pause() {
// Abort any in-progress seek // Abort any in-progress seek / playback
abortSeek(); abortSeek();
// Stop playback only if playback is in progress // Stop playback only if playback is in progress
@@ -651,8 +641,7 @@ Guacamole.SessionRecording = function SessionRecording(tunnel) {
if (recording.onpause) if (recording.onpause)
recording.onpause(); recording.onpause();
// Stop playback // Playback is stopped
window.clearTimeout(playbackTimeout);
startVideoTimestamp = null; startVideoTimestamp = null;
startRealTimestamp = null; startRealTimestamp = null;