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

Detect back button event from LG Magic remote #127

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

giolaq
Copy link
Contributor

@giolaq giolaq commented May 21, 2024

This to detect the "Back" button of an LG Magic Remote for Web OS.
Tested with the web build of the project.

The appinfo.json of the WebOS project needs to include

"disableBackHistoryAPI": true

More info for LG WebOS here

@@ -19,11 +19,15 @@ class RemoteControlManager implements RemoteControlManagerInterface {
Backspace: SupportedKeys.Back,
Copy link
Member

@pierpo pierpo May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this simple change would be enough, wouldn't it? 😁 No need for the rest below. Or maybe I'm missing something?

Suggested change
Backspace: SupportedKeys.Back,
Backspace: SupportedKeys.Back,
GoBack: SupportedKeys.Back,

Copy link
Contributor Author

@giolaq giolaq May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish not to use that ugly hack in my code 🤪. What is happening when I pressed the back button on the Lg Magic Remote is that an event is raised with
event.code empty and event.key === 'GoBack'
The mappedKey is mapped on event.code so it doesn't trigger the desired key.

Any idea about how to fix this in a proper way?
🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha alright, that's the thing I missed indeed!

Then this will work. It's just the example app anyway.

My suggestion though would be to make the if branch more explicit as an exit condition (following this). What do you think? 😁

    //For LG WebOs Magic Remote
    if (event.key === 'GoBack') {
      this.eventEmitter.emit('keyDown', SupportedKeys.Back);
      return
    }

    if (!mappedKey) {
      return;
    }
    
    this.eventEmitter.emit('keyDown', mappedKey);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes! Far better!
It's a sample app, but it's my favorite TV app around! There are some options for the future we can discuss like:

  • Promoting this sample as a boilerplate for TV!

I have a private repo of this app I use for studying/experimenting/presenting.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a reference for using .key on the event? webOS docs suggest using keyCode === 461

Copy link
Contributor Author

@giolaq giolaq Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested on an LG C2 and experienced they key is code was empty and key is GoBack

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you find that keyCode was empty as well? If that's the case then their docs are wrong (not the first time) 😅

I don't have a smart remote available, but testing on simulator (v24) and with LG 32LQ630BPUA keyCode behaves as documented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes keycode was empty using this app. @matthewcaminiti Can you test the app in this repos with your TV/Emulator and check what code is returned?

Copy link

@matthewcaminiti matthewcaminiti Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good to know! I gotta test on a newer device. May need to use both key/keyCode to cover old+new WebOS.

On my TV device (LG 32LQ630BPUA ... old model with latest software) I've yet to figure out how to get logs from it, but when using key === 'GoBack' it doesn't work, suggesting key is empty.

On simulator it's as follows:

Screen.Recording.2024-06-13.at.4.23.41.PM.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants