Hosted server and device access
The hosted server is a self-hosted gateway for an IPTVnator library. It keeps the library on the user's computer while making the same service available to trusted companion devices and browser clients over a home network, a configured HTTPS address, or a Cloudflare Access route.
Access model
Hosted server
The hosted server joins the desktop app, the shared library, and remote clients into one access boundary. The desktop app starts or stops the server and reports the active endpoint; the server then serves the web client and the library API from the host computer.
The server has a local-only path for the host app and a shared path for devices. Each running instance has an instance identity, so a client can detect that its saved connection points to an old server session instead of silently using the wrong host.
References: apps/…/hosted-server.service.ts• L60-79 apps/…/hosted-server-session.ts• L8-41 apps/…/hosted-web-app.ts• L12-45
Access modes
The settings screen presents three access modes. They differ in how a client reaches the host and how much trust the route provides.
| Mode | Client reach | Main trust boundary |
|---|---|---|
| Home network | HTTP on a selected private LAN address | Requests must come from the host or the selected private subnet. Devices still pair before library access. |
| Custom HTTPS | An HTTPS origin backed by the host or a trusted proxy | TLS protects the route. A browser pairing password can protect browser approval. |
| Cloudflare | An HTTPS origin reached through Cloudflare Access | Cloudflare Access proves the request identity. The host then checks the Access token before it permits device actions. |
The application treats a Cloudflare connector as a transport aid rather than as proof that the public route works. It checks the public route separately and enables pairing only after it sees the expected Access protection.
References: libs/…/hosted-server.interface.ts• L42-62 apps/…/settings-hosted-server.component.ts• L32-177 apps/…/hosted-mode-config.ts• L35-134
Request paths
All access modes use the same application routes. The host can send a request to the server through a private in-process transport, while remote clients use the LAN or HTTPS endpoint. This keeps the library behavior consistent without exposing the local transport as a network listener.
The web client receives /api as its backend address. Special pages handle device pairing and TV approval before the normal web app opens. Cloudflare discovery and authorization paths are not treated as normal player pages when they reach the origin.
The main paths are:
/api: library and device service requests./pair-device: invitation-based browser or companion-device pairing on LAN or custom HTTPS.- /connect-device.html: browser registration through a Cloudflare route.
/approve-device: approval of a TV request from a paired phone or an HTTPS browser.
References: apps/…/hosted-web-app.ts• L23-45 apps/…/hosted-worker-transport.ts• L11-20 apps/…/hosted-device-page.ts• L32-100 apps/…/hosted-cloudflare-device-page.ts• L18-58
Device trust
Invitation and approval
Pairing turns a short-lived invitation into a lasting device credential only after the host owner approves the request. The invitation and pending claim expire, while the approved device record remains available to the hosted server.
The normal flow is:
- The host creates an invitation and shares its link.
- The device opens the link and submits its name.
- The host shows the pending device and a confirmation code.
- The owner compares the code and approves the device.
- The device polls with its claim secret and receives its access token after approval.
The host can list devices, grant or remove device approval rights, and revoke a device. Revocation removes access from future requests without requiring a new library or server setup.
References: apps/…/hosted-device-control.ts• L54-169 apps/…/device-pairing-router.ts• L260-363 apps/…/device-pairing-store.ts• L71-122 apps/…/device-pairing-store.ts• L237-253
Browser access
Browser access uses a device credential saved by the browser after pairing. The browser sends the credential with later library requests, and the hosted server can reject an unknown or revoked device before it reaches the library.
Custom HTTPS also supports a separate browser approval password. This password lets an HTTPS browser approve a TV request without giving that browser general device-management rights. The password creates a short-lived browser session and is cleared from active sessions when the owner changes it.
References: apps/…/hosted-device-page.ts• L54-99 apps/…/device-pairing-router.ts• L136-218 apps/…/device-pairing-store.ts• L124-199
Cloudflare device access
Cloudflare device access adds two checks to the public route. Cloudflare Access must authenticate the request, and the host must find an active device credential associated with that route. A browser receives a secure device cookie, then registers that browser only through a fresh host invitation.
The host validates the Access issuer, audience, time claims, and signature before it accepts device operations. A revoked device cannot register again unless the host creates a new valid invitation and restores its access.
References: apps/…/cloudflare-access.ts• L13-20 apps/…/cloudflare-access.ts• L64-109 apps/…/cloudflare-device-access.ts• L18-105 apps/…/hosted-cloudflare-device-page.ts• L25-55
Companion flows
Television pairing
The television client uses a short-lived pairing session to ask a phone or another approved client to supply library setup data. The TV keeps a TV token for the session, while the companion keeps a separate phone token; both sides use the hosted backend until the request is saved, rejected, cancelled, or expires.
This flow shares the hosted access boundary but has a different purpose from device registration. Device registration grants a client access to the hosted library. Television pairing transfers setup or settings to the TV.
References: libs/…/pairing.ts• L8-59 apps/…/hosted-tv-approval-page.ts• L40-163
Source synchronization
Once a companion client connects to the hosted server, it can use the server as the shared source for the library. The saved endpoint includes the server API address and the current instance identity, which lets the client stop and ask for reconnection when the host replaces the running instance.
See self-hosted source synchronization for the library data flow. See hosted server pairing and sessions for the claim, approval, and session lifecycles.
References: apps/…/hosted-server-session.ts• L20-41 apps/…/hosted-device-page.ts• L82-95 apps/…/hosted-cloudflare-device-page.ts• L37-47
Related client surfaces
The hosted endpoint is used by more than one client surface. The browser client opens the hosted web app. The browser backend supplies its API behavior. The television client and TV shell runtime use companion flows when a TV needs a source or approval.
Hosted server setup and the detailed pairing session rules belong in the child pages hosted server pairing and sessions and the hosted server configuration page when it is available.
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the endpoint and instance identity contract aligned between hosted-server status, browser storage, and source-server reconnect checks.
- Keep the invitation type aligned with the route: normal invitations use
/pair-device, while Cloudflare invitations use /connect-device.html and require an Access-protected public route. - Keep device revocation and approval rights consistent across the desktop controls, pairing store, and Cloudflare device checks.
- Keep the browser approval password rules aligned between the settings control, browser session route, and approval page.
- Keep the Cloudflare team, audience, issuer, and route checks aligned with the Access policy that fronts the public origin.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The configured LAN address is no longer assigned | The server cannot expose the LAN endpoint | Accept only current private LAN addresses and report startup failure. |
| TLS certificate or key is missing or invalid | HTTPS mode cannot start | Validate the origin and TLS material before the listener starts. |
| A Cloudflare connector starts before the public route is Access-protected | Pairing remains unavailable even if the connector process runs | Check the public route and require access-protected before creating Cloudflare invitations. |
| An invitation or pending claim expires | The device must use a fresh invitation | Keep invitations and claims short-lived and reject stale identifiers. |
| A device is revoked | Its saved credential cannot access or register the device | Check the device state on each protected Cloudflare operation and remove revoked normal-device records. |
| The browser cannot save its connection or credential | Pairing completes but the client cannot open the shared library | Report storage failure and require a fresh pairing attempt. |
Key files
| File | Why to read it |
|---|---|
| apps/…/hosted-server.service.ts | Shows how the desktop app owns hosted server lifecycle and endpoint state. |
| libs/…/hosted-server.interface.ts | Defines the shared access modes, status, and control contracts. |
| apps/…/hosted-mode-config.ts | Explains the accepted LAN, HTTPS, and Cloudflare route rules. |
| apps/…/hosted-web-app.ts | Shows how the web app, API, and pairing pages share one hosted surface. |
| apps/…/device-pairing-store.ts | Defines invitation, claim, device, revocation, and browser-session state. |
| apps/…/device-pairing-router.ts | Maps pairing and device-management actions to access checks. |
| apps/…/cloudflare-access.ts | Shows how Cloudflare Access requests are accepted or rejected. |
| apps/…/cloudflare-device-access.ts | Shows how Cloudflare browser identity maps to a paired device. |
| apps/…/hosted-device-control.ts | Connects desktop device controls to hosted pairing actions. |
| apps/…/hosted-device-page.ts | Illustrates normal browser pairing from invitation to saved connection. |
| apps/…/hosted-cloudflare-device-page.ts | Illustrates browser registration through Cloudflare Access. |