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): stream fails to resume after being suspended (#692)
Browse files Browse the repository at this point in the history
* fix(CAMERA_STREAM): stream fails to resume after being suspended

Appears to be a regression in v1 of hls.js. An upstream issue created
at video-dev/hls.js#3732

But I also found similar issue (video-dev/hls.js#2473)
that seems to suggest that it's best to just re-initialize the Hls
instance instead of re-attaching the media so I'll just go with that
for now.

Fixes #688

* revert debugging code

* debug code
  • Loading branch information
rchl committed Apr 7, 2021
1 parent 0a1f78b commit bed202a
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions scripts/directives/cameraStream.js
Expand Up @@ -40,8 +40,8 @@ export default function (Api, $timeout) {
current.pause();
suspendPromise = $timeout(() => {
if (hls) {
hls.stopLoad();
hls.detachMedia();
hls.destroy();
hls = null;
}
}, SUSPEND_TIMEOUT_MS);
}
Expand All @@ -51,9 +51,10 @@ export default function (Api, $timeout) {
$timeout.cancel(suspendPromise);
if (current.paused) {
if (hls) {
hls.attachMedia(current);
Promise.resolve(current.play()).catch(() => {});
} else {
requestStream();
}
Promise.resolve(current.play()).catch(() => {});
}
}

Expand All @@ -80,14 +81,14 @@ export default function (Api, $timeout) {
hls.loadSource(url);
});
hls.on(Hls.Events.MANIFEST_PARSED, function () {
el.play();
Promise.resolve(el.play()).catch(() => {});
});
hls.attachMedia(el);
} else {
el.src = url;
el.setAttribute('playsinline', 'playsinline');
el.addEventListener('loadedmetadata', function () {
el.play();
Promise.resolve(el.play()).catch(() => {});
});
}

Expand All @@ -104,16 +105,18 @@ export default function (Api, $timeout) {
return;
}

Api.send({
type: 'camera/stream',
entity_id: $scope.entity.entity_id,
},
function (res) {
if (!res.result) {
return;
}
appendVideo(toAbsoluteServerURL(res.result.url));
});
Api.send(
{
type: 'camera/stream',
entity_id: $scope.entity.entity_id,
},
function (res) {
if (!res.result) {
return;
}
appendVideo(toAbsoluteServerURL(res.result.url));
},
);
};

$scope.$watch('entity', requestStream);
Expand Down

0 comments on commit bed202a

Please sign in to comment.