@w4f/lgtv

0.2.0 • Public • Published

LGTV

Installation

npm install @w4f/lgtv and set up the TV per below.

Discovering the TV

const { discover } = require('@w4f/lgtv');
discover(2000).then(tvInfo => {
  console.log(tvInfo);
});

Connecting to the TV

const { connect } = require('@w4f/lgtv');
connect(address).then(tv => {
  console.log(tv);
});

Sending a command

const { discover, connect, commands } = require('@w4f/lgtv');
const { setVolume } = commands;

async function run() {
  let { address } = await discover(2000);
  let tv = await connect(address);

  await tv.send(setVolume(15));
  tv.disconnect();
}

run();

Subscribing to events

const { discover, connect, commands } = require('@w4f/lgtv');
const { getVolume } = commands;

function listener({ payload }) {
  const { changed, action, muted, volume } = payload;
  if (typeof changed === 'undefined' || action !== 'changed') {
    return;
  }
  if (changed.includes('muted')) {
    console.log('Muted', muted);
  }
  if (changed.includes('volume')) {
    console.log('Volume', volume);
  }
}
async function run() {
  let { address } = await discover(2000);
  let tv = await connect(address);
  let unsubscribe = await tv.send(getVolume(listener));
}

run();

Package Sidebar

Install

npm i @w4f/lgtv

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

88.7 kB

Total Files

15

Last publish

Collaborators

  • w4f