From 6b7a848f204b54fdee54657e970e0613bf6b3bbb Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Tue, 8 Jul 2014 13:49:20 +0200 Subject: [PATCH] Handle case where page change event is received while file is still downloading. --- static/js/directives/presentation.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/static/js/directives/presentation.js b/static/js/directives/presentation.js index 998872f3..845f814a 100644 --- a/static/js/directives/presentation.js +++ b/static/js/directives/presentation.js @@ -30,13 +30,19 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($, $scope.layout.presentation = false; $scope.isPresenter = false; $scope.hideControlsBar = false; + $scope.pendingPageRequest = null; + $scope.presentationLoaded = false; $scope.$on("pdfLoaded", function(event, source, doc) { if ($scope.isPresenter) { $scope.$emit("showPdfPage", 1); + } else if ($scope.pendingPageRequest !== null) { + $scope.$emit("showPdfPage", $scope.pendingPageRequest); + $scope.pendingPageRequest = null; } else { $scope.$emit("showQueuedPdfPage"); } + $scope.presentationLoaded = true; }); var downloadScope = $scope.$new(); @@ -68,6 +74,8 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($, finishDownloadPresentation(); var token = fileInfo.id; + $scope.presentationLoaded = false; + $scope.pendingPageRequest = null; downloadScope.info = fileInfo; downloadScope.handler = mediaStream.tokens.on(token, function(event, currenttoken, to, data, type, to2, from, xfer) { //console.log("Presentation token request", currenttoken, data, type); @@ -117,8 +125,13 @@ define(['jquery', 'underscore', 'text!partials/presentation.html'], function($, break; case "Page": - console.log("Received presentation page request", data); - $scope.$emit("showPdfPage", data.Page); + if (!$scope.presentationLoaded) { + console.log("Queuing presentation page request, not loaded yet", data); + $scope.pendingPageRequest = data.Page; + } else { + console.log("Received presentation page request", data); + $scope.$emit("showPdfPage", data.Page); + } break; default: