1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Backport pull request #5526 from jellyfin-web/release-10.9.z

Don’t bind to keyevents of media keys when browser support mediaSession

Original-merge: 6da3dd7c86

Merged-by: thornbill <thornbill@users.noreply.github.com>

Backported-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
gnattu 2024-05-25 11:50:36 -04:00 committed by Joshua M. Boniface
parent 6e32ea052d
commit 22eb6bf3f6

View file

@ -45,6 +45,11 @@ const KeyNames = {
*/ */
const NavigationKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']; const NavigationKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'];
/**
* Keys used for media playback control.
*/
const MediaKeys = ['MediaRewind', 'MediaStop', 'MediaPlay', 'MediaFastForward', 'MediaTrackPrevious', 'MediaTrackNext', 'MediaPlayPause'];
/** /**
* Elements for which navigation should be constrained. * Elements for which navigation should be constrained.
*/ */
@ -89,6 +94,16 @@ export function isNavigationKey(key) {
return NavigationKeys.indexOf(key) != -1; return NavigationKeys.indexOf(key) != -1;
} }
/**
* Returns _true_ if key is used for media playback control.
*
* @param {string} key - Key name.
* @return {boolean} _true_ if key is used for media playback control.
*/
export function isMediaKey(key) {
return MediaKeys.includes(key);
}
/** /**
* Returns _true_ if the element is interactive. * Returns _true_ if the element is interactive.
* *
@ -108,6 +123,7 @@ export function isInteractiveElement(element) {
} }
export function enable() { export function enable() {
const hasMediaSession = 'mediaSession' in navigator;
window.addEventListener('keydown', function (e) { window.addEventListener('keydown', function (e) {
const key = getKeyName(e); const key = getKeyName(e);
@ -116,6 +132,11 @@ export function enable() {
return; return;
} }
// Ignore Media Keys for non-TV platform having MediaSession API
if (!browser.tv && isMediaKey(key) && hasMediaSession) {
return;
}
let capture = true; let capture = true;
switch (key) { switch (key) {