diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..a98fef0 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,16 @@ +name: Publish + +on: + push: + branches: + - main + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # The OIDC ID token is used for authentication with JSR. + steps: + - uses: actions/checkout@v4 + - run: npx jsr publish diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..317b1fa --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +.vscode +.env diff --git a/README.md b/README.md index 76c617f..22539f2 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,72 @@ # WebOS Client -Simple Deno module for control LG WebOS TV's +[![JSR Scope](https://jsr.io/badges/@bukhalo)](https://jsr.io/@bukhalo) +[![JSR Score](https://jsr.io/badges/@bukhalo/webos-client/score)](https://jsr.io/@bukhalo/webos-client) +[![JSR](https://jsr.io/badges/@bukhalo/webos-client)](https://jsr.io/@bukhalo/webos-client) -Reference: +Add package in your project: -https://github.com/bendavid/aiopylgtv/ -https://github.com/merdok/homebridge-webos-tv -https://github.com/hobbyquaker/lgtv2 -https://github.com/home-assistant/home-assistant.io/issues/17685 -https://community.home-assistant.io/t/lg-webos-change-picture-setting-mode-with-scripts/262915/3 -https://www.webosbrew.org/pages/commands-cheatsheet.html \ No newline at end of file +```bash +deno add @bukhalo/webos-client +``` + +Or add package without install step: + +```typescript +import { Client } from "jsr:@bukhalo/webos-client"; +``` + +Initialize the `Client` class by passing the IP address of the TV as the first +argument, and run `register()` function: + +```typescript +import { Client } from "@bukhalo/webos-client"; + +const client = new Client("192.168.0.1"); +await client.register(); +``` + + +> [!IMPORTANT] +> Once `register()` is executed, it will send a connection request to the TV, don't forget to confirm it. This is the reason why the function returns a promise. +> +> After confirming the request on the TV, you need to save the token. If the code is executed in a Deno environment, the token will be automatically saved to `localStorage`. If the code is not executed in Deno or you want to change the default behavior, create your own class for storage by inheriting the `Storage` abstract class from the package. You can specify your own storage when initializing the client by passing it as the second argument. + +After that you can call one of the available methods, for example `volumeUp()`: + +```typescript +import { Client } from "@bukhalo/webos-client"; + +const client = new Client("192.168.0.1"); +await client.register(); + +await client.volumeUp(); +``` + +Or send a custom request if you know `type`, `uri` and `payload` for that +request: + +```typescript +import { Client, MessageType } from "@bukhalo/webos-client"; + +const client = new Client("192.168.0.1"); +await client.register(); + +await client.sendMessage({ + type: MessageType.REQUEST, + uri: "ssap://audio/volumeUp", +}); +``` + + +> [!NOTE] +> Please note there are a very limited number of ready-made requests available in the client at the moment. + +### Reference + +- https://github.com/bendavid/aiopylgtv/ +- https://github.com/merdok/homebridge-webos-tv +- https://github.com/hobbyquaker/lgtv2 +- https://github.com/home-assistant/home-assistant.io/issues/17685 +- https://community.home-assistant.io/t/lg-webos-change-picture-setting-mode-with-scripts/262915/3 +- https://www.webosbrew.org/pages/commands-cheatsheet.html diff --git a/client_test.ts b/client_test.ts index 7616767..ced2959 100644 --- a/client_test.ts +++ b/client_test.ts @@ -1,6 +1,6 @@ -import { assertObjectMatch } from "./deps_test.ts"; +import { assertObjectMatch } from "jsr:@std/assert"; import { Client } from "./client.ts"; -import { MessageType } from "./message_type.ts"; +import { MessageType } from "./types/message_type.ts"; Deno.test("client", async (test) => { const url = Deno.args[0]; diff --git a/deno.jsonc b/deno.jsonc index 67638be..36a1fc6 100644 --- a/deno.jsonc +++ b/deno.jsonc @@ -1,9 +1,14 @@ { "name": "@bukhalo/webos-client", - "version": "0.2.0", + "version": "0.2.1", "exports": "./mod.ts", "tasks": { + "lint": "deno fmt", // example command for run tests, use you own TV IP address - "test": "deno test --allow-net=192.168.0.10:3000 -- ws://192.168.0.10:3000" + "test": "deno test --allow-net=192.168.0.61:3000 -- ws://192.168.0.61:3000", + "publish": "deno task lint && deno publish" + }, + "publish": { + "exclude": [".github"] } } diff --git a/deno.lock b/deno.lock index 6c3e403..fe3d6af 100644 --- a/deno.lock +++ b/deno.lock @@ -1,9 +1,21 @@ { - "version": "2", - "remote": { - "https://deno.land/std@0.192.0/fmt/colors.ts": "d67e3cd9f472535241a8e410d33423980bec45047e343577554d3356e1f0ef4e", - "https://deno.land/std@0.192.0/testing/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", - "https://deno.land/std@0.192.0/testing/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", - "https://deno.land/std@0.192.0/testing/asserts.ts": "e16d98b4d73ffc4ed498d717307a12500ae4f2cbe668f1a215632d19fcffc22f" - } + "version": "3", + "packages": { + "specifiers": { + "jsr:@std/assert": "jsr:@std/assert@0.226.0", + "jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.1" + }, + "jsr": { + "@std/assert@0.226.0": { + "integrity": "0dfb5f7c7723c18cec118e080fec76ce15b4c31154b15ad2bd74822603ef75b3", + "dependencies": [ + "jsr:@std/internal@^1.0.0" + ] + }, + "@std/internal@1.0.1": { + "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6" + } + } + }, + "remote": {} } diff --git a/deps_test.ts b/deps_test.ts deleted file mode 100644 index b06b5fb..0000000 --- a/deps_test.ts +++ /dev/null @@ -1 +0,0 @@ -export { assertObjectMatch } from "https://deno.land/std@0.192.0/testing/asserts.ts"; diff --git a/types/request_config.ts b/types/request_config.ts index 60157f1..dc067cc 100644 --- a/types/request_config.ts +++ b/types/request_config.ts @@ -1,4 +1,4 @@ -import { MessageType } from "./message_type.ts"; +import type { MessageType } from "./message_type.ts"; export type RequestConfig

> = { id?: string;