Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

gnattu
Copy link
Member

@gnattu gnattu commented May 17, 2024

These events are already handled by MediaSession. On some operating systems, like Windows, the browser will send both the MediaSession event and the keydown event to the webpage, causing the event to be handled twice and resulting in issues.

Changes

Remove media key binding in keyboardNavigation

Issues

Fixes #5523

These events are already handled by MediaSession. On some operating systems, like Windows, the browser will send both the MediaSession event and the keydown event to the webpage, causing the event to be handled twice and resulting in issues.
@gnattu gnattu requested a review from a team as a code owner May 17, 2024 08:10
@jellyfin-bot
Copy link
Collaborator

Cloudflare Pages deployment

Latest commit bdce41c
Status ✅ Deployed!
Preview URL https://0a269a58.jellyfin-web.pages.dev
Type 🔀 Preview

View build logs
View bot logs

@dmitrylyzo
Copy link
Contributor

dmitrylyzo commented May 17, 2024

This needs to be tested on TV with keyboard connected. keyboardNavigation.js is primarily for TV.
Btw, Media* key codes are also come from the remote.

@dmitrylyzo dmitrylyzo added the needs testing This PR requires additional testing label May 17, 2024
@gnattu
Copy link
Member Author

gnattu commented May 17, 2024

This needs to be tested on TV with keyboard connected. keyboardNavigation.js is primarily for TV. Btw, Media* key codes are also come from the remote.

If the TVs really work that bad with that then this should be TV only, having both listeners will clearly conflicts with each other.

@dmitrylyzo
Copy link
Contributor

We could do something like this:

const hasMediaSession = 'mediaSession' in navigator;

...

case 'MediaPlayPause':
    if (!hasMediaSession) inputManager.handleCommand('playpause');
    break;

But I have no idea if modern TVs have MediaSession.

@gnattu
Copy link
Member Author

gnattu commented May 17, 2024

But I have no idea if modern TVs have MediaSession.

Even if they do, is it really reliable is also questionable.

Do we have the double event issue for TV yet? If we don't then probably one of the event handler is not really working for the TVs, but which one is unknown.

@dmitrylyzo
Copy link
Contributor

I'm sure keydown works for Media* keys on Tizen - that's how Samsung recommends handling them.
https://developer.samsung.com/smarttv/develop/api-references/tizen-web-device-api-references/tvinputdevice-api.html

var i, keyCode = {}, supportedKeys;
supportedKeys = tizen.tvinputdevice.getSupportedKeys();
for (i = 0; i < supportedKeys.length; i++) {
    keyCode[supportedKeys[i].name] = supportedKeys[i].code;
}
if(keyCode.hasOwnProperty("ChannelUp")) {
    tizen.tvinputdevice.registerKey("ChannelUp");
}
window.addEventListener("keydown", function(keyEvent) {
    // identify the key by the numeric code from the keyEvent
    if(keyEvent.keyCode === keyCode.ChannelUp) {
        console.log("The CHANNEL UP was pressed");
    }
});

After a quick look, there is no MediaSession API.
https://developer.samsung.com/smarttv/develop/specifications/web-engine-specifications.html

@gnattu
Copy link
Member Author

gnattu commented May 19, 2024

@GeorgeH005 Can you do me a favor for this as well? Can you test if webOS have MediaSession and is its MediaSession reliable? So that we can have some level of confidence for two major smart TV platforms.

@GeorgeH005
Copy link
Contributor

@gnattu MediaSession does seem to exist in the webOS app runtime. Couldn't test its reliability right now, but I'll try to in the following days. The remote also doesn't have any media keys, so I can't test if they bind to those events or not.

@gnattu
Copy link
Member Author

gnattu commented May 21, 2024

Updated to make the compatibility better. Now it only binds media keys on TV and browsers not having mediaSession. Should work good enough and cover most use cases.

@gnattu gnattu changed the title Don’t bind to keyevents of media keys Don’t bind to keyevents of media keys when browser support mediaSession May 21, 2024
src/scripts/keyboardNavigation.js Outdated Show resolved Hide resolved
src/scripts/keyboardNavigation.js Outdated Show resolved Hide resolved
@dmitrylyzo dmitrylyzo added bug Something isn't working and removed needs testing This PR requires additional testing labels May 21, 2024
@dmitrylyzo dmitrylyzo added this to the v10.9.3 milestone May 21, 2024
@dmitrylyzo dmitrylyzo added this to In progress in Release 10.9.z via automation May 21, 2024
src/scripts/keyboardNavigation.js Outdated Show resolved Hide resolved
Co-authored-by: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com>
Copy link

sonarcloud bot commented May 21, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@thornbill thornbill added the stable backport Backport into the next stable release label May 21, 2024
@thornbill thornbill merged commit 6da3dd7 into jellyfin:release-10.9.z May 21, 2024
12 checks passed
Release 10.9.z automation moved this from In progress to Done May 21, 2024
joshuaboniface pushed a commit that referenced this pull request May 25, 2024
Don’t bind to keyevents of media keys when browser support mediaSession

Original-merge: 6da3dd7

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

Backported-by: Joshua M. Boniface <joshua@boniface.me>
@jellyfin-bot jellyfin-bot removed the stable backport Backport into the next stable release label May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants