Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
fix(CAMERA_STREAM): fix frozen streams playing on load (#694)
Browse files Browse the repository at this point in the history
"$scope.$watch('entity', requestStream)" requested the stream and
started playing the stream even when "frozen" was true. Refactored a bit
to fix that. The code is getting kinda messy but whatever.
  • Loading branch information
rchl authored Apr 8, 2021
1 parent 9f10b16 commit d3c51fe
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions scripts/directives/cameraStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,33 @@ export default function (Api, $timeout) {
let hls = null;

$scope.$watch('frozen', frozen => {
if (current) {
if (frozen) {
onFreezed();
} else {
onUnfreezed();
}
if (frozen) {
onFreezed();
} else {
onUnfreezed();
}
});

function onFreezed () {
if (!current.paused) {
if (current && !current.paused) {
current.pause();
suspendPromise = $timeout(() => {
if (hls) {
hls.destroy();
hls = null;
current.remove();
current = null;
}
}, SUSPEND_TIMEOUT_MS);
}
}

function onUnfreezed () {
$timeout.cancel(suspendPromise);
if (current.paused) {
if (hls) {
Promise.resolve(current.play()).catch(() => {});
} else {
requestStream();
}
if (hls) {
Promise.resolve(current.play()).catch(() => {});
} else {
requestStream();
}
}

Expand Down Expand Up @@ -101,7 +99,7 @@ export default function (Api, $timeout) {
};

const requestStream = function () {
if ($scope.entity.state === 'off') {
if ($scope.entity.state === 'off' || $scope.frozen) {
return;
}

Expand Down

0 comments on commit d3c51fe

Please sign in to comment.