From 445172049694cf002d448811953500d786908c78 Mon Sep 17 00:00:00 2001 From: PaulaScharf Date: Wed, 10 Nov 2021 18:38:45 +0100 Subject: [PATCH 1/2] fix initial loading of overlays --- .../remote/js/controllers/mainController.js | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/public/remote/js/controllers/mainController.js b/public/remote/js/controllers/mainController.js index 35c17aa..edf5867 100644 --- a/public/remote/js/controllers/mainController.js +++ b/public/remote/js/controllers/mainController.js @@ -47,7 +47,7 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara }; $scope.onSelectVideo = async function(video){ - await setCurrentVideo(video); + await setCurrentVideoOverlays(video, undefined); // sync other remote clients & server state $socket.emit('/set/video', { video_id: video.video_id, overlays: $scope.overlays }); }; @@ -109,7 +109,11 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara if(preferredVideo === -1){ delete $scope.current.video; } elseĀ { - await setCurrentVideo(preferredVideo); + let overlays = {}; + for (let i = 0; i < $scope.overlays.length; i++) { + overlays[data.overlay_id] = $scope.overlays[i].display + } + await setCurrentVideoOverlays(preferredVideo, overlays); $socket.emit('/set/video', { video_id: preferredVideo.video_id, overlays: $scope.overlays}); } } @@ -130,7 +134,7 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara }); }; - function setCurrentVideo (video) { + function setCurrentVideoOverlays (video, overlay) { if (!video) return $scope.current.video = video; @@ -152,11 +156,19 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara exists = true; } if(j === $scope.overlays.length - 1 && !exists){ + console.log(overlay) + if (overlay && Object.keys(overlay).length > 0 && typeof overlay[response.data[i].overlay_id] !== "undefined") { + response.data[i].display = overlay[response.data[i].overlay_id]; + } $scope.overlays.push(response.data[i]); } } } else{ + console.log(overlay) + if (overlay && Object.keys(overlay).length > 0 && typeof overlay[response.data[i].overlay_id] !== "undefined") { + response.data[i].display = overlay[response.data[i].overlay_id]; + } $scope.overlays.push(response.data[i]); } } @@ -191,7 +203,7 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara $socket.on('/set/video', function(data) { $videoService.retrieve(data.video_id) .then(function onSuccess(response) { - return setCurrentVideo(response.data); + return setCurrentVideo(response.data, undefined); }).catch(function onError(response) { $scope.err = response.data; }); @@ -207,7 +219,7 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara Promise.all([ setCurrentScenario(scenario), setCurrentLocation(location), - setCurrentVideo(video), + setCurrentVideoOverlays(video, overlay) ]).catch(res => { $scope.err = res.data }) From d9e01bffa5d99c3710cafa9ac2f3c7b316e7798d Mon Sep 17 00:00:00 2001 From: PaulaScharf Date: Wed, 10 Nov 2021 20:05:10 +0100 Subject: [PATCH 2/2] fix syncing of overlays --- .../remote/js/controllers/mainController.js | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/public/remote/js/controllers/mainController.js b/public/remote/js/controllers/mainController.js index edf5867..546e010 100644 --- a/public/remote/js/controllers/mainController.js +++ b/public/remote/js/controllers/mainController.js @@ -37,7 +37,7 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara }; $scope.onSelectLocation = function(location){ - setCurrentLocation(location); + setCurrentLocation(location, undefined); // sync other remote clients & server state if(location.location_type == "transition") { $socket.emit('/set/location', { location_id: location.location_id, location_type: location.location_type, length: location.length }); @@ -91,7 +91,7 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara }); }; - function setCurrentLocation (location) { + function setCurrentLocation (location, overlays) { if (!location) return $scope.current.location = location; @@ -109,10 +109,6 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara if(preferredVideo === -1){ delete $scope.current.video; } elseĀ { - let overlays = {}; - for (let i = 0; i < $scope.overlays.length; i++) { - overlays[data.overlay_id] = $scope.overlays[i].display - } await setCurrentVideoOverlays(preferredVideo, overlays); $socket.emit('/set/video', { video_id: preferredVideo.video_id, overlays: $scope.overlays}); } @@ -156,7 +152,6 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara exists = true; } if(j === $scope.overlays.length - 1 && !exists){ - console.log(overlay) if (overlay && Object.keys(overlay).length > 0 && typeof overlay[response.data[i].overlay_id] !== "undefined") { response.data[i].display = overlay[response.data[i].overlay_id]; } @@ -165,7 +160,6 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara } } else{ - console.log(overlay) if (overlay && Object.keys(overlay).length > 0 && typeof overlay[response.data[i].overlay_id] !== "undefined") { response.data[i].display = overlay[response.data[i].overlay_id]; } @@ -193,7 +187,7 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara $socket.on('/set/location', function(data) { $locationService.retrieve(data.location_id) .then(function onSuccess(response) { - return setCurrentLocation(response.data); + return setCurrentLocation(response.data, undefined); }).catch(function onError(response) { $scope.err = response.data; }); @@ -203,12 +197,26 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara $socket.on('/set/video', function(data) { $videoService.retrieve(data.video_id) .then(function onSuccess(response) { - return setCurrentVideo(response.data, undefined); + let overlays = {}; + if (data.overlays) { + for (let i=0; i < data.overlays.length; i++) { + overlays[data.overlays[i].overlay_id] = data.overlays[i].display; + } + } + return setCurrentVideoOverlays(response.data, overlays); }).catch(function onError(response) { $scope.err = response.data; }); }); + $socket.on('/toggle/overlay', function(data) { + for (let i = 0; i < $scope.overlays.length; i++) { + if ($scope.overlays[i].overlay_id === data.overlay_id) { + $scope.overlays[i].display = data.display + } + } + }); + // apply state $socket.on('/get/state', function(state) { @@ -218,7 +226,7 @@ app.controller("mainController", function($scope, $rootScope, config, $routePara Promise.all([ setCurrentScenario(scenario), - setCurrentLocation(location), + setCurrentLocation(location, overlay), setCurrentVideoOverlays(video, overlay) ]).catch(res => { $scope.err = res.data