Skip to content

Latest commit

 

History

History
67 lines (52 loc) · 1.22 KB

README.md

File metadata and controls

67 lines (52 loc) · 1.22 KB

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();