Fix preview signalR due to browser throttling background tabs

This commit is contained in:
Stephan
2018-10-08 10:53:19 +02:00
parent 0726ee1a39
commit 69f4f0c8a8

View File

@@ -22,6 +22,20 @@ var app = angular.module("umbraco.preview", ['umbraco.resources', 'umbraco.servi
// signalr hub
var previewHub = $.connection.previewHub;
// visibility tracking
var dirtyContent = false;
var visibleContent = true;
document.addEventListener('visibilitychange', function () {
visibleContent = !document.hidden;
if (visibleContent && dirtyContent) {
dirtyContent = false;
console.log("Visible, reloading.")
var iframeDoc = (iframe.contentWindow || iframe.contentDocument);
iframeDoc.location.reload();
}
});
previewHub.client.refreshed = function (message, sender) {
console.log("Notified by SignalR preview hub (" + message + ").");
@@ -30,6 +44,13 @@ var app = angular.module("umbraco.preview", ['umbraco.resources', 'umbraco.servi
return;
}
if (!visibleContent) {
console.log("Not visible, will reload.");
dirtyContent = true;
return;
}
console.log("Reloading.");
var iframeDoc = (iframe.contentWindow || iframe.contentDocument);
iframeDoc.location.reload();
};