Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
clement-berard committed Nov 3, 2024
1 parent 6470512 commit 0707bb7
Show file tree
Hide file tree
Showing 12 changed files with 780 additions and 172 deletions.
9 changes: 7 additions & 2 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ export default defineConfig({
base: process.env.CI ? '/philtv-js/' : '/',
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [{ text: 'Home', link: '../main.md' }],
sidebar: [{ text: 'Get Started', link: '/main.md' }, ...SideBarMenuAutoGen],
nav: [{ text: 'Home', link: '../get-started.md' }],
sidebar: [
{ text: 'Get Started', link: '/get-started.md' },
{ text: 'Pairing TV', link: '/pairing.md' },
{ text: 'API usage', link: '/api-usage.md' },
...SideBarMenuAutoGen,
],
socialLinks: [{ icon: 'github', link: 'https://github.com/clement-berard/philtv-js' }],
},
});
25 changes: 25 additions & 0 deletions docs/api-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# API Usage - JointSpace API

::: warning
You must have the `user` and `password` from the pairing process to use the JointSpace API. See the Pairing section for more information.
:::

To create an instance of the `PhilTVApi` class, you need to provide an object of type [`PhilTVApiParams`](./lib/type-aliases/PhilTVApiParams.md) as a parameter to the constructor.

If `cacheStructure` is set to `true`, the class will store the retrieved menu structure locally in a file using the [unstorage](https://unstorage.unjs.io/) library.
On subsequent requests for the menu structure, it will check for an existing cached version before making a network call, which can greatly enhance performance by reducing unnecessary API requests.
If caching is not required, you can simply omit the `options` parameter or set `cacheStructure` to `false`.


```typescript
const apiClient = new PhilTVApi({
apiUrl: 'https://192.168.0.22:1926/6',
password: '5bewertrewref6968be556667552a49da5bf5fce3b379127cf74af2a3951026c2b',
user: 'd1443b9fdeecd187277as5464564565e6315',
options: {
cacheStructure: true,
},
});
```

Please see the all available methods in the [API documentation](./lib/classes/PhilTVApi.md)
21 changes: 21 additions & 0 deletions docs/get-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# philtv-js

**philtv-js** is a TypeScript library for pairing a Philips Android TV with the latest versions (6) using the **JointSpace** protocol.

This library simplifies the pairing process, allowing you to interact with your Philips television securely and efficiently.

With full TypeScript support, `philtv-js` provides type safety, helping to prevent runtime errors and improve code quality.

This library leverages the lightweight [ky](https://github.com/sindresorhus/ky) HTTP client, which is built on top of Fetch API, for making secure and intuitive HTTP requests.

::: warning
**Works only in secure environments (HTTPS) and with versions 6 of the JointSpace protocol.**
:::

## Installation

To install `philtv-js`, you can use npm:

```bash
npm install philtv-js
```
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ hero:
actions:
- theme: brand
text: Get Started
link: /main.md
link: /get-started.md

features:
- title: Modern stack
Expand Down
80 changes: 0 additions & 80 deletions docs/main.md

This file was deleted.

43 changes: 43 additions & 0 deletions docs/pairing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Pairing TV

To use `philtv-js`, you need to import the PhilTVPairing class from the library:

```typescript
import { PhilTVPairing } from 'philtv-js';

// @ts-ignore
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0; // Disable TLS certificate verification

const pjs = new PhilTVPairing({ tvIp: '192.168.0.22', apiPort: 1926 });

// `startPairing` returns a function to prompt for the pin, can be useful
const { promptForPin } = await pjs.startPairing();
const pin = await promptForPin();

// `completePairing` returns the configuration object, or an error
const [error, config] = await pjs.completePairing(pin);

if (!error) {
console.log('Pairing successful:', config);
} else {
console.error('Error:', error.message);
}
```
Result example of `config`:
```json
{
"user": "d1443b9fdeecd187277as5464564565e6315",
"password": "5bewertrewref6968be556667552a49da5bf5fce3b379127cf74af2a3951026c2b",
"apiUrl": "https://192.168.0.22:1926",
"apiVersion": 6,
"fullApiUrl": "https://192.168.0.22:1926/6"
}
```
You can store the `user` and `password` in a secure location and use them to interact with your TV.

::: info
Usage of `NODE_TLS_REJECT_UNAUTHORIZED`:
Setting `NODE_TLS_REJECT_UNAUTHORIZED = 0` disables TLS certificate verification, which can expose your application to "man-in-the-middle" attacks. Use it with caution and only in development environments.

For more information on managing TLS certificates, refer to the Node.js documentation.
:::
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"scripts": {
"build": "pnpm tsup --dts --clean --minify --format esm src/index.ts",
"watch": "pnpm build --watch",
"docs:build": "vitepress build docs",
"docs:dev": "vitepress dev docs",
"docs:generate": "pnpm typedoc:generate && pnpm docs:build",
Expand All @@ -28,7 +29,8 @@
"digest-fetch": "3.1.1",
"ky": "1.7.2",
"node-fetch": "3.3.2",
"radash": "12.1.0"
"radash": "12.1.0",
"unstorage": "1.13.1"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
Expand Down Expand Up @@ -74,7 +76,10 @@
"@semantic-release/commit-analyzer",
{
"releaseRules": [
{ "type": "chore", "release": "patch" }
{
"type": "chore",
"release": "patch"
}
]
}
],
Expand Down
Loading

0 comments on commit 0707bb7

Please sign in to comment.