timmson / node-lgtv-api

Node.js API for the remote control of LG SmartTV (2012+)
MIT License
26 stars 8 forks source link

Help getting app auid to launch apps (and question about Promises) #6

Closed chearmstrong closed 7 years ago

chearmstrong commented 7 years ago

Hi. Firstly, I wanted to say that this module is really useful and has helped a lot. Good work. :)

Anyway, I want to launch an app directly, and I'm doing it with the code below - to launch an app I need the auid of the app. I managed to find the auid for Netflix on the original PHP version that inspired this version. However, I'm struggling to find the auids for other apps (AMazon Instant Video and iPlayer for example).

My code which successfully works to open Netflix.

openApp(app) {

  if (!appMap[app]) {
    return Promise.reject(new Error(`${app} doesn't exist`));
  }

  let requestedApp = {
    appname: appMap[app].name, // Netflix
    auid: appMap[app].id // 00000000000112ae
  };

  return this.lg.authenticateAsync()
    .then(() => {
      // I'm using Bluebird's promisifyAll() with the LG API. However, processCommand()
      // doesn't work so I'm having to fudge it and use the synchronous version.
      // Not sure why as I've not fully looked in to it.
      return this.lg.processCommand(this.lg.TV_LAUNCH_APP, [requestedApp], (err, data) => {
        if (err) {
          return Promise.reject(err);
        }
        return data;
      });
    })
    .catch(err => Logger.error(err.message || err));
}

As you can see, I'm also trying to use Promises with your module. I've used Bluebird's promisifyAll() which works for most methods, but not processCommand() though. I'm not sure why. I was wondering though, are there any plans properly support Promises (I'm having to fudge it atm).

Thanks in advance.

timmson commented 7 years ago

Honestly, i dont use this feature, but it would be great if you will show the results of your research.

chearmstrong commented 7 years ago

If I get any further, I will do. :)

timmson commented 7 years ago

I've just pushed v0.9.0. It has Promise support. Please, give me feedback if any will go wrong))