Fix controls and seeking bugs.

This commit is contained in:
Dermot Duffy
2024-04-14 19:47:44 -07:00
parent e13a7bed6b
commit b4ed40e6c7
3 changed files with 30 additions and 0 deletions
+1
View File
@@ -138,6 +138,7 @@ export class FrigateCardSurround extends LitElement {
...(media.getCameraID() && { camera: media.getCameraID() }), ...(media.getCameraID() && { camera: media.getCameraID() }),
}) })
.removeContext('timeline') .removeContext('timeline')
.removeContext('mediaViewer')
// Send the view change from the source of the tap event, so // Send the view change from the source of the tap event, so
// the view change will be caught by the handler above (to // the view change will be caught by the handler above (to
// close the drawer). // close the drawer).
+11
View File
@@ -44,6 +44,17 @@ export const hideMediaControlsTemporarily = (
setControlsOnVideo(video, false); setControlsOnVideo(video, false);
video._controlsHideTimer ??= new Timer(); video._controlsHideTimer ??= new Timer();
video._controlsOriginalValue = oldValue; video._controlsOriginalValue = oldValue;
// LitElement may change the src attribute of the video element during
// rendering, so we need to ensure that the controls are reset on the 'old'
// video. See:
// https://github.com/dermotduffy/frigate-hass-card/issues/1310
const resetIfReloaded = () => {
setControlsOnVideo(video, oldValue);
video.removeEventListener('loadstart', resetIfReloaded);
};
video.addEventListener('loadstart', resetIfReloaded);
video._controlsHideTimer.start(seconds, () => { video._controlsHideTimer.start(seconds, () => {
setControlsOnVideo(video, oldValue); setControlsOnVideo(video, oldValue);
}); });
+18
View File
@@ -51,6 +51,24 @@ describe('hideMediaControlsTemporarily', () => {
expect(video.controls).toBeTruthy(); expect(video.controls).toBeTruthy();
expect(video._controlsHideTimer).toBeFalsy(); expect(video._controlsHideTimer).toBeFalsy();
}); });
it('should add event listener that resets controls', () => {
const video: FrigateCardHTMLVideoElement = document.createElement('video');
video.controls = true;
hideMediaControlsTemporarily(video);
expect(video.controls).toBeFalsy();
// After a new media starts to load, the controls should reset.
video.dispatchEvent(new Event('loadstart'));
expect(video.controls).toBeTruthy();
// ... but only once, future loadstart events without subsequent calls to
// hideMediaControlsTemporarily() should do nothing.
video.controls = false;
video.dispatchEvent(new Event('loadstart'));
expect(video._controlsHideTimer).toBeFalsy();
});
}); });
class NotAllowedError extends Error { class NotAllowedError extends Error {