https://github.com/dabolus/webos-tv
A promise-based package to control LGTVs with JavaScript.
https://github.com/dabolus/webos-tv
async javascript lgtv promise typescript webos webos-tv
Last synced: about 1 year ago
JSON representation
A promise-based package to control LGTVs with JavaScript.
- Host: GitHub
- URL: https://github.com/dabolus/webos-tv
- Owner: Dabolus
- Created: 2018-10-20T18:54:04.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2023-10-29T15:10:25.000Z (over 2 years ago)
- Last Synced: 2025-03-30T09:31:32.227Z (about 1 year ago)
- Topics: async, javascript, lgtv, promise, typescript, webos, webos-tv
- Language: TypeScript
- Homepage: https://dabolus.github.io/webos-tv
- Size: 3.15 MB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# webOS TV
A promise-based package to control webOS based TVs with JavaScript.
## Installation
```bash
npm install webos-tv
# or
yarn add webos-tv
```
If you want to use the library in a Node.js environment, make
sure to install also the optional peer dependencies:
```bash
npm install ws
# or
yarn add ws
# plus the optional native peer dependencies for ws,
# if you want to improve performance
# see: https://npmjs.com/package/ws#user-content-opt-in-for-performance
npm install --save-optional bufferutil utf-8-validate
# or
yarn add --optional bufferutil utf-8-validate
```
On browser, the native Fetch and WebSocket APIs are used,
so nothing else is needed.
## Usage
### Simple usage
```js
import { TV } from 'webos-tv';
const ip = '';
const tv = new TV(ip);
// On first authentication, no token is required.
// The `authenticate` function will return a token
// once the pairing is accepted on the TV.
const token = await tv.authenticate();
// The received token should be stored somewhere so
// that it can be used in subsequent connections.
// e.g. await tv.authenticate(token);
console.log('Software information: ', await tv.getCurrentSWInformation());
await tv.showNotification('Hello, World!');
await tv.disconnect();
```
### Pointer and keyboard control
The TV class allows opening specialized input sockets that allow
to have a dedicated channel to control the TV pointer and keyboard.
```js
import { TV } from 'webos-tv';
const ip = '';
const tv = new TV(ip);
await tv.authenticate();
// This method will return a PointerInputSocket instance
const pointerSocket = await tv.getPointerInputSocket();
pointerSocket.move(20, 30);
pointerSocket.click();
pointerSocket.scroll(0, 10);
```
### Wake-on-LAN
If your TV supports Wake-on-LAN, you can use the `wake` function
to turn it on:
```js
import { TV } from 'webos-tv';
const ip = '';
const mac = '';
const password = '';
// `turnOn` is a static method of the TV class, so it must be called
// before setting up the connection to the TV (obviously).
await TV.turnOn(ip, mac, password);
// If everything went well, the TV should be turned on now,
// so you should be able to connect to it normally (see above).
// Note that after being turned on, the TV might require some
// seconds before being ready to accept WebSocket connections.
```