├── frontend ├── assets │ ├── icon-80.png │ ├── splash.png │ ├── icon-130.png │ ├── banner-dark.png │ ├── icon-transparent130.png │ └── icon-transparent80.png ├── submission-icon.png ├── css │ ├── webOS.css │ └── main.css ├── appinfo.json ├── .project ├── index.html ├── js │ ├── storage.js │ ├── ajax.js │ ├── webOS.js │ └── index.js └── webOSTVjs-1.2.11 │ ├── LICENSE-2.0.txt │ ├── webOSTV-dev.js │ └── webOSTV.js ├── services ├── package.json ├── services.json └── service.js ├── renovate.json ├── .editorconfig ├── tools ├── sync-version.js └── gen-manifest.js ├── CONTRIBUTORS.md ├── .gitignore ├── dev.sh ├── .github └── workflows │ ├── codeql-analysis.yml │ └── build.yml ├── package.json ├── README.md └── LICENSE /frontend/assets/icon-80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jellyfin/jellyfin-webos/HEAD/frontend/assets/icon-80.png -------------------------------------------------------------------------------- /frontend/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jellyfin/jellyfin-webos/HEAD/frontend/assets/splash.png -------------------------------------------------------------------------------- /frontend/assets/icon-130.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jellyfin/jellyfin-webos/HEAD/frontend/assets/icon-130.png -------------------------------------------------------------------------------- /frontend/submission-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jellyfin/jellyfin-webos/HEAD/frontend/submission-icon.png -------------------------------------------------------------------------------- /frontend/assets/banner-dark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jellyfin/jellyfin-webos/HEAD/frontend/assets/banner-dark.png -------------------------------------------------------------------------------- /frontend/assets/icon-transparent130.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jellyfin/jellyfin-webos/HEAD/frontend/assets/icon-transparent130.png -------------------------------------------------------------------------------- /frontend/assets/icon-transparent80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jellyfin/jellyfin-webos/HEAD/frontend/assets/icon-transparent80.png -------------------------------------------------------------------------------- /services/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "org.jellyfin.webos.service", 3 | "description": "Jellyfin Discovery Service", 4 | "main": "service.js" 5 | } -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "config:base" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | #indent_style = space 5 | indent_size = 4 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /services/services.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "org.jellyfin.webos.service", 3 | "description": "Jellyfin Discovery Service", 4 | "services": [ 5 | { 6 | "name": "org.jellyfin.webos.service" 7 | } 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /frontend/css/webOS.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | .layout-tv body::-webkit-scrollbar { 9 | display: none; 10 | } 11 | -------------------------------------------------------------------------------- /tools/sync-version.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const fs = require('fs'); 4 | 5 | const packageInfo = JSON.parse(fs.readFileSync('package.json')); 6 | const appInfo = JSON.parse(fs.readFileSync('frontend/appinfo.json')); 7 | 8 | fs.writeFileSync( 9 | 'frontend/appinfo.json', 10 | `${JSON.stringify( 11 | { 12 | ...appInfo, 13 | version: packageInfo.version, 14 | }, 15 | null, 16 | 4, 17 | )}\n`, 18 | ); -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Jellyfin Contributors 2 | 3 | - [EraYaN](https://github.com/EraYaN) 4 | - [dmitrylyzo](https://github.com/dmitrylyzo) 5 | - [TrueTechy](https://github.com/TrueTechy) 6 | - [Narfinger](https://github.com/Narfinger) 7 | - [JustAMan](https://github.com/JustAMan) 8 | - [dkanada](https://github.com/dkanada) 9 | - [Oddstr13](https://github.com/oddstr13) 10 | 11 | # PlayZ Contributors 12 | 13 | - [simonjhogan](https://github.com/simonjhogan) 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .metadata 2 | bin/ 3 | tmp/ 4 | *.tmp 5 | *.bak 6 | *.swp 7 | *~.nib 8 | local.properties 9 | .settings/ 10 | .loadpath 11 | .recommenders 12 | 13 | # External tool builders 14 | .externalToolBuilders/ 15 | 16 | # Locally stored "Eclipse launch configurations" 17 | *.launch 18 | 19 | OutputIPK/ 20 | Thumbs.db 21 | *.ipk 22 | 23 | # Artifacts from setting Docker WORKDIR the same as HOME 24 | .ssh/ 25 | .webos/ 26 | .bash_history 27 | 28 | # NodeJS 29 | node_modules/ 30 | build/ 31 | yarn.lock 32 | -------------------------------------------------------------------------------- /frontend/appinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "appDescription": "A webOS client to connect to a Jellyfin Server instance and stream media.", 3 | "icon": "assets/icon-80.png", 4 | "main": "index.html", 5 | "bgImage": "assets/splash.png", 6 | "title": "Jellyfin", 7 | "type": "web", 8 | "version": "1.2.2", 9 | "splashBackground": "assets/splash.png", 10 | "bgColor": "#000b25", 11 | "vendor": "Jellyfin Project", 12 | "largeIcon": "assets/icon-130.png", 13 | "iconColor": "#000b25", 14 | "id": "org.jellyfin.webos", 15 | "disableBackHistoryAPI": true 16 | } 17 | -------------------------------------------------------------------------------- /dev.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | CONTAINER_IMAGE="ghcr.io/oddstr13/docker-tizen-webos-sdk:webos-only" 3 | 4 | MY=$(realpath "$(dirname $0)") 5 | 6 | function ct { 7 | # The volume mount flag should be a lower case z. 8 | # NEVER upper case, as that could break permissions badly. 9 | # https://docs.docker.com/storage/bind-mounts/#configure-the-selinux-label 10 | docker container run -it --rm --user=$UID --network=host -v "${MY}":/home/developer:z $CONTAINER_IMAGE "$@" 11 | } 12 | 13 | if [ $# -lt 1 ]; then 14 | echo "Available commands:" 15 | echo "bash Enter container command line" 16 | ct ares --list 17 | else 18 | ct "$@" 19 | fi 20 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | schedule: 9 | - cron: '29 12 * * 0' 10 | 11 | jobs: 12 | analyze: 13 | name: Analyze 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | language: [ 'javascript' ] 20 | 21 | steps: 22 | - name: Checkout repository 23 | uses: actions/checkout@v5 24 | 25 | - name: Initialize CodeQL 26 | uses: github/codeql-action/init@v4 27 | with: 28 | languages: ${{ matrix.language }} 29 | queries: security-extended 30 | 31 | - name: Perform CodeQL Analysis 32 | uses: github/codeql-action/analyze@v4 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "org.jellyfin.webos", 3 | "version": "1.2.2", 4 | "description": "Jellyfin WebOS client", 5 | "scripts": { 6 | "check": "ares-package --check", 7 | "package": "ares-package --no-minify --outdir build/ services frontend", 8 | "clean": "rm -rf build/", 9 | "deploy": "ares-install build/org.jellyfin.webos_${npm_package_version}_all.ipk", 10 | "launch": "ares-launch org.jellyfin.webos", 11 | "manifest": "node tools/gen-manifest.js build/org.jellyfin.webos.manifest.json", 12 | "version": "node tools/sync-version.js && git add frontend/appinfo.json", 13 | "test": "echo \"Error: no test specified\" && exit 1" 14 | }, 15 | "author": "Jellyfin contributors", 16 | "license": "MPL-2.0", 17 | "devDependencies": { 18 | "@webosose/ares-cli": "^2.4.0" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tools/gen-manifest.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const crypto = require('crypto'); 4 | const fs = require('fs'); 5 | 6 | const outfile = process.argv[2]; 7 | const appinfo = JSON.parse(fs.readFileSync('frontend/appinfo.json')); 8 | const ipkfile = `${appinfo.id}_${appinfo.version}_all.ipk`; 9 | const ipkhash = crypto.createHash('sha256').update(fs.readFileSync(`build/${ipkfile}`)).digest('hex'); 10 | 11 | fs.writeFileSync( 12 | outfile, 13 | JSON.stringify({ 14 | id: appinfo.id, 15 | version: appinfo.version, 16 | type: appinfo.type, 17 | title: appinfo.title, 18 | appDescription: appinfo.appDescription, 19 | iconUri: 'https://github.com/jellyfin/jellyfin-webos/raw/master/org.jellyfin.webos/submission-icon.png', 20 | sourceUrl: 'https://github.com/jellyfin/jellyfin-webos', 21 | rootRequired: false, 22 | ipkUrl: ipkfile, 23 | ipkHash: { 24 | sha256: ipkhash, 25 | }, 26 | }), 27 | ); 28 | -------------------------------------------------------------------------------- /frontend/.project: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | org.jellyfin.webos 7 | 8 | 9 | 10 | 11 | 12 | org.eclipse.wst.common.project.facet.core.builder 13 | 14 | 15 | 16 | 17 | org.eclipse.wst.jsdt.core.javascriptValidator 18 | 19 | 20 | 21 | 22 | com.webos.ide.nature.WebOSBuilder 23 | 24 | 25 | 26 | 27 | org.eclipse.wst.validation.validationbuilder 28 | 29 | 30 | 31 | 32 | 33 | com.webos.ide.project.nature 34 | org.eclipse.wst.jsdt.core.jsNature 35 | org.eclipse.wst.common.project.facet.core.nature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | 38 | 39 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | release: 7 | types: 8 | - published 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v5 16 | 17 | - name: Use Node.js 14.x 18 | uses: actions/setup-node@v6 19 | with: 20 | node-version: 14.x 21 | 22 | - name: Prepare environment 23 | run: | 24 | rm -rf ./build/* 25 | mkdir ./build 26 | 27 | - name: Install ares-cli globally 28 | run: npm install -g @webosose/ares-cli 29 | 30 | - name: Check packaging 31 | run: ares-package --check 32 | 33 | - name: Build package 34 | run: ares-package --no-minify --outdir build/ services frontend 35 | 36 | - name: Create manifest for distribution 37 | run: node tools/gen-manifest.js build/org.jellyfin.webos.manifest.json 38 | 39 | - name: Upload CI artifacts 40 | uses: actions/upload-artifact@v5 41 | with: 42 | name: jellyfin_webos 43 | path: | 44 | ${{github.workspace}}/build/* 45 | 46 | - name: Upload GitHub Release Artifacts 47 | uses: shogo82148/actions-upload-release-asset@v1 48 | if: ${{ github.event_name == 'release' }} 49 | with: 50 | upload_url: ${{ github.event.release.upload_url }} 51 | asset_path: 'build/*' 52 | overwrite: true 53 | -------------------------------------------------------------------------------- /frontend/index.html: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Jellyfin for webOS 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 24 |
25 | 26 |
27 | 28 |
29 | 33 | 34 |
35 | 36 |
    37 |
    38 |
    39 | 43 |
    44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /frontend/js/storage.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * This file incorporates work covered by the following copyright and 7 | * permission notice: 8 | * 9 | * Copyright 2019 Simon J. Hogan 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | var storage = new STORAGE(); 26 | 27 | function STORAGE() {}; 28 | 29 | STORAGE.prototype.get = function(name, isJSON) { 30 | if (isJSON === undefined) { 31 | isJSON = true; 32 | } 33 | 34 | if (localStorage) { 35 | if (localStorage.getItem(name)) { 36 | if (isJSON) { 37 | return JSON.parse(localStorage.getItem(name)); 38 | } else { 39 | return localStorage.getItem(name); 40 | } 41 | } 42 | } 43 | }; 44 | 45 | STORAGE.prototype.set = function(name, data, isJSON) { 46 | if (isJSON === undefined) { 47 | isJSON = true; 48 | } 49 | 50 | if (localStorage) { 51 | if (isJSON) { 52 | localStorage.setItem(name, JSON.stringify(data)); 53 | } else { 54 | localStorage.setItem(name, data); 55 | } 56 | } 57 | 58 | return data; 59 | }; 60 | 61 | STORAGE.prototype.remove = function(name) { 62 | if (localStorage) { 63 | localStorage.removeItem(name); 64 | } 65 | }; 66 | 67 | STORAGE.prototype.exists = function(name) { 68 | if (localStorage) { 69 | if (localStorage.getItem(name)) { 70 | return true; 71 | } 72 | } 73 | return false; 74 | }; -------------------------------------------------------------------------------- /frontend/js/ajax.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * This file incorporates work covered by the following copyright and 7 | * permission notice: 8 | * 9 | * Copyright 2019 Simon J. Hogan 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); 12 | * you may not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | */ 24 | 25 | var ajax = new AJAX(); 26 | 27 | function AJAX() {}; 28 | 29 | AJAX.prototype.request = function(url, settings) { 30 | var method = (settings.method) ? settings.method : "GET"; 31 | var xhr = new XMLHttpRequest(); 32 | 33 | xhr.open(method, url); 34 | 35 | if (settings.headers) { 36 | for (var h in settings.headers) { 37 | if (settings.headers.hasOwnProperty(h)) { 38 | xhr.setRequestHeader(h, settings.headers[h]); 39 | } 40 | } 41 | } 42 | 43 | if (settings.timeout) { 44 | xhr.timeout = settings.timeout; 45 | } 46 | 47 | xhr.ontimeout = function (event) { 48 | if (settings.error) { 49 | settings.error({error: "timeout"}); 50 | } 51 | } 52 | 53 | xhr.onerror = function (event) { 54 | if (settings.error) { 55 | settings.error({error: event.target.status}); 56 | } 57 | } 58 | 59 | xhr.onabort = function (event) { 60 | if (settings.abort) { 61 | settings.abort({error: "abort"}); 62 | } 63 | } 64 | 65 | xhr.onreadystatechange = function () { 66 | if (xhr.readyState == XMLHttpRequest.DONE) { 67 | if (xhr.status == 200) { 68 | if (settings.success) { 69 | try { 70 | settings.success(JSON.parse(xhr.responseText)); 71 | } catch (error) { 72 | console.error(error); 73 | if (error instanceof SyntaxError) { 74 | if (settings.error) { 75 | settings.error({error: "The server did not return valid JSON data."}); 76 | } 77 | } else if (settings.error) { 78 | settings.error({error: 0}); 79 | } 80 | } 81 | } 82 | } else if (xhr.status == 204) { 83 | if (settings.success) { 84 | settings.success({success: true}) 85 | } 86 | } else if (settings.error) { 87 | settings.error({error: xhr.status}); 88 | } 89 | } 90 | } 91 | 92 | if (settings.data) { 93 | xhr.send(JSON.stringify(settings.data)); 94 | } else { 95 | xhr.send(); 96 | } 97 | return xhr; 98 | }; 99 | -------------------------------------------------------------------------------- /frontend/css/main.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | * { 9 | -webkit-box-sizing: border-box; 10 | box-sizing: border-box; 11 | } 12 | 13 | html, 14 | body { 15 | margin: 0; 16 | padding: 0; 17 | height: 100%; 18 | } 19 | 20 | body { 21 | width: 100%; 22 | font-size: 36px; 23 | font-family: -apple-system, "Helvetica", system-ui, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", "Open Sans", sans-serif; 24 | background-color: #101010; 25 | color: #FFF; 26 | } 27 | 28 | #contentFrame { 29 | border: none; 30 | width: 100%; 31 | height: 100%; 32 | } 33 | 34 | .container { 35 | position: absolute; 36 | height: 100%; 37 | width: 100%; 38 | vertical-align: middle; 39 | color: #FFF; 40 | display:-webkit-flex; 41 | display:flex; 42 | -webkit-flex-direction: column; 43 | flex-direction: column; 44 | -webkit-flex-wrap: flex-direction; 45 | flex-wrap: flex-direction; 46 | -webkit-justify-content: center; 47 | justify-content: center; 48 | -webkit-align-items: center; 49 | align-items: center; 50 | -webkit-align-content: center; 51 | align-content: center; 52 | } 53 | 54 | .container > div { 55 | display: inline-block; 56 | width: 60%; 57 | } 58 | 59 | #logo { 60 | width: 40%; 61 | margin-bottom: 2em; 62 | } 63 | 64 | #logo img { 65 | max-width: 100%; 66 | } 67 | 68 | input, 69 | textarea, 70 | button { 71 | font-size: 1em; 72 | -webkit-transition: all 0.30s ease-in-out; 73 | transition: all 0.30s ease-in-out; 74 | outline: none; 75 | padding: .5rem 1.25rem; 76 | margin: 0.8rem 0; 77 | border-radius: 0.2rem; 78 | } 79 | 80 | .checkbox-wrapper { 81 | margin: 0.8rem 0; 82 | } 83 | 84 | #error { 85 | color: #000; 86 | background-color: tomato; 87 | border-radius: .2rem; 88 | padding: 0.25em 0.5em; 89 | font-size: 1.5rem; 90 | } 91 | 92 | input[type=checkbox] { 93 | margin: 0; 94 | width: 1em; 95 | height: 1em; 96 | } 97 | 98 | input[type=text], 99 | input[type=url], 100 | input[type=checkbox], 101 | textarea { 102 | border: 2px solid #292929; 103 | background-color: #292929; 104 | color: #FFF; 105 | } 106 | 107 | input[type=text]:focus, 108 | input[type=url]:focus, 109 | input[type=checkbox]:focus, 110 | textarea:focus { 111 | border-color: #00A4DC; 112 | } 113 | 114 | input[type=text], 115 | input[type=url], 116 | textarea, 117 | button { 118 | width: 100%; 119 | } 120 | 121 | button { 122 | background: #292929; 123 | border: 0; 124 | color: #FFF; 125 | font-weight: bold; 126 | } 127 | 128 | button:focus { 129 | background: #00A4DC; 130 | } 131 | 132 | input[type=checkbox]:focus+label { 133 | color: #00A4DC; 134 | } 135 | 136 | input[type=checkbox]:focus { 137 | outline: 2px solid #00A4DC; 138 | } 139 | 140 | #serverlist { 141 | display: -webkit-box; 142 | display: flex; 143 | flex-direction: row; 144 | flex-wrap: wrap; 145 | padding: 0; 146 | } 147 | 148 | .server_card { 149 | display: block; 150 | flex-grow: 1; 151 | flex-basis: 0; 152 | text-align: center; 153 | width: 33%; 154 | margin: 0.3em; 155 | } 156 | server_card_url 157 | .server_card_version, .server_card_url { 158 | color: gray; 159 | font-size: 0.7em; 160 | margin: 0.3em auto; 161 | width: 90%; 162 | overflow : hidden; 163 | text-overflow: ellipsis; 164 | } 165 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Jellyfin for webOS 3 | This is a small wrapper around the web interface provided by the server (https://github.com/jellyfin/jellyfin-web) so most of the development happens there. 4 | 5 | 6 | ## Download 7 | 8 | For all versions: 9 |

    10 | Enjoy on LG Smart TV 11 |
    12 | Note: If you previously installed the app via Homebrew or Developer mode, you must uninstall that before you can use the store version. 13 |

    14 | 15 | 16 | ## License 17 | All Jellyfin webOS code is licensed under the MPL 2.0 license, some parts incorporate content licensed under the Apache 2.0 license. All images are taken from and licensed under the same license as https://github.com/jellyfin/jellyfin-ux. 18 | 19 | --- 20 | 21 | ## Development 22 | 23 | The general development workflow looks like this: 24 | 25 | - Prepare a build environment of your choice (see below) 26 | - Compile an IPK either with the IDE or with ares-package 27 | - Test the app on the emulator or ares-server or install it on your tv by following http://webostv.developer.lge.com/develop/app-test/ 28 | 29 | There are three ways to create the required build environment: 30 | 31 | - Full WebOS SDK Installation 32 | - Docker 33 | - NPM ares-cli 34 | 35 | ### Full WebOS SDK Installation 36 | 37 | - Install the WebOS SDK from http://webostv.developer.lge.com/sdk/installation/ 38 | 39 | ### Docker 40 | 41 | A prebuilt docker image is available that includes the build and deployment dependencies, see [Docker Hub](https://ghcr.io/oddstr13/docker-tizen-webos-sdk). 42 | 43 | ### Managing the ares-tools via npm 44 | 45 | This requires `npm`, the Node.js package manager. 46 | 47 | Execute the following to install the required WebOS toolkit for building & deployment: 48 | 49 | `npm install` 50 | 51 | Now you can package the app by running: 52 | 53 | `npm run package` 54 | 55 | ## Building with Docker or WebOS SDK 56 | 57 | `dev.sh` is a wrapper around the Docker commands. If you have installed the SDK directly, just omit that part. 58 | 59 | ```sh 60 | # Build the package via Docker 61 | ./dev.sh ares-package --no-minify services frontend 62 | # Build the package with natively installed WebOS SDK 63 | ares-package --no-minify services frontend 64 | ``` 65 | 66 | ## Usage 67 | Fill in your hostname, port, and schema and click connect. The app will check for a server by grabbing the manifest and the public serverinfo. 68 | Afterwards, the app hands off control to the hosted webUI. 69 | 70 | 71 | ## Testing 72 | Testing on a TV requires [registering a LG developer account](https://webostv.developer.lge.com/develop/app-test/preparing-account/) and [setting up the devmode app](https://webostv.developer.lge.com/develop/app-test/using-devmode-app/). 73 | 74 | Once you have installed the devmode app on your target TV and logged in with your LG developer account, you need to turn on the `Dev Mode Status` and `Key Server`. 75 | **Make sure** to take a note of the passphrase. 76 | 77 | ```sh 78 | # Add your TV. The defaults are fine, but I recommend naming it `tv`. 79 | ./dev.sh ares-setup-device --search 80 | 81 | # This command sets up the SSH key for the device `tv` (Key Server must be running) 82 | ./dev.sh ares-novacom --device tv --getkey 83 | 84 | # Run this command to verify that things are working. 85 | ./dev.sh ares-device-info -d tv 86 | 87 | # This command installs the app. Remember to build it first. 88 | ./dev.sh ares-install -d tv org.jellyfin.webos_*.ipk 89 | 90 | # Launch the app and the web developer console. 91 | ./dev.sh ares-inspect -d tv org.jellyfin.webos 92 | 93 | # Or just launch the app. 94 | ./dev.sh ares-launch -d tv org.jellyfin.webos 95 | ``` 96 | -------------------------------------------------------------------------------- /services/service.js: -------------------------------------------------------------------------------- 1 | // -*- coding: utf-8 -*- 2 | 3 | /* 4 | * Backend node.js service for server autodiscovery. 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | var pkgInfo = require('./package.json'); 12 | var Service = require('webos-service'); 13 | 14 | // Register com.yourdomain.@DIR@.service, on both buses 15 | var service = new Service(pkgInfo.name); 16 | 17 | var dgram = require('dgram'); 18 | var client4 = dgram.createSocket("udp4"); 19 | 20 | // var client6; 21 | // try { 22 | // client6 = dgram.createSocket("udp6"); 23 | // } catch (err) { 24 | // console.log(err); 25 | // client6 = false; 26 | // } 27 | 28 | const JELLYFIN_DISCOVERY_PORT = 7359; 29 | const JELLYFIN_DISCOVERY_MESSAGE = "who is JellyfinServer?"; 30 | 31 | const SCAN_INTERVAL = 15 * 1000; 32 | const SCAN_ON_START = true; 33 | 34 | var scanresult = {}; 35 | 36 | function sendScanResults(server_id) { 37 | console.log("Sending responses, subscription count=" + Object.keys(subscriptions).length); 38 | for (var i in subscriptions) { 39 | if (subscriptions.hasOwnProperty(i)) { 40 | var s = subscriptions[i]; 41 | if (server_id) { 42 | var res = {}; 43 | res[server_id] = scanresult[server_id]; 44 | s.respond({ 45 | results: res 46 | }); 47 | } else { 48 | s.respond({ 49 | results: scanresult, 50 | }); 51 | } 52 | } 53 | } 54 | } 55 | 56 | function handleDiscoveryResponse(message, remote) { 57 | try { 58 | var msg = JSON.parse(message.toString('utf-8')); 59 | 60 | if (typeof msg == "object" && 61 | typeof msg.Id == "string" && 62 | typeof msg.Name == "string" && 63 | typeof msg.Address == "string") { 64 | 65 | scanresult[msg.Id] = msg; 66 | scanresult[msg.Id].source = { 67 | address: remote.address, 68 | port: remote.port, 69 | }; 70 | 71 | sendScanResults(msg.Id); 72 | } 73 | } catch (err) { 74 | console.log(err); 75 | } 76 | } 77 | 78 | function sendJellyfinDiscovery() { 79 | var msg = new Buffer(JELLYFIN_DISCOVERY_MESSAGE); 80 | client4.send(msg, 0, msg.length, 7359, "255.255.255.255"); 81 | 82 | // if (client6) { 83 | // client6.send(msg, 0, msg.length, 7359, "ff08::1"); // All organization-local nodes 84 | // } 85 | 86 | } 87 | 88 | function discoverInitial() { 89 | if (SCAN_ON_START) { 90 | sendJellyfinDiscovery(); 91 | } 92 | } 93 | 94 | client4.on("listening", function () { 95 | var address = client4.address(); 96 | console.log('UDP Client listening on ' + address.address + ":" + address.port); 97 | client4.setBroadcast(true) 98 | client4.setMulticastTTL(128); 99 | //client.addMembership('230.185.192.108'); 100 | }); 101 | 102 | client4.on("message", handleDiscoveryResponse); 103 | client4.bind({ 104 | port: JELLYFIN_DISCOVERY_PORT 105 | }, discoverInitial); 106 | 107 | 108 | // if (client6) { 109 | // client6.on("listening", function () { 110 | // var address = client4.address(); 111 | // console.log('UDP Client listening on ' + address.address + ":" + address.port); 112 | // client6.setMulticastTTL(128); 113 | // //client.addMembership('230.185.192.108'); 114 | // }); 115 | 116 | // client6.on("message", handleDiscoveryResponse); 117 | 118 | // try { // client6 bind failing even in a try catch. 119 | // //client6.bind(JELLYFIN_DISCOVERY_PORT, discoverInitial); 120 | // } catch (err) { 121 | // console.log(err); 122 | // } 123 | // } 124 | 125 | 126 | var interval; 127 | var subscriptions = {}; 128 | 129 | function createInterval() { 130 | if (interval) { 131 | return; 132 | } 133 | console.log("create new interval"); 134 | interval = setInterval(function () { 135 | sendJellyfinDiscovery(); 136 | }, SCAN_INTERVAL); 137 | } 138 | 139 | var discover = service.register("discover"); 140 | discover.on("request", function (message) { 141 | sendScanResults(); 142 | var uniqueToken = message.uniqueToken; 143 | console.log("discover callback, uniqueToken: " + uniqueToken + ", token: " + message.token); 144 | 145 | sendJellyfinDiscovery(); 146 | 147 | if (message.isSubscription) { 148 | subscriptions[uniqueToken] = message; 149 | if (!interval) { 150 | createInterval(); 151 | } 152 | } 153 | }); 154 | discover.on("cancel", function (message) { 155 | var uniqueToken = message.uniqueToken; 156 | console.log("Canceled " + uniqueToken); 157 | delete subscriptions[uniqueToken]; 158 | var keys = Object.keys(subscriptions); 159 | if (keys.length === 0) { 160 | console.log("no more subscriptions, canceling interval"); 161 | clearInterval(interval); 162 | interval = undefined; 163 | } 164 | }); 165 | -------------------------------------------------------------------------------- /frontend/js/webOS.js: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | (function(AppInfo, deviceInfo) { 9 | 'use strict'; 10 | 11 | console.log('WebOS adapter'); 12 | 13 | function postMessage(type, data) { 14 | window.top.postMessage({ 15 | type: type, 16 | data: data 17 | }, '*'); 18 | } 19 | 20 | // List of supported features 21 | var SupportedFeatures = [ 22 | 'exit', 23 | 'externallinkdisplay', 24 | 'htmlaudioautoplay', 25 | 'htmlvideoautoplay', 26 | 'imageanalysis', 27 | 'physicalvolumecontrol', 28 | 'displaylanguage', 29 | 'otherapppromotions', 30 | 'targetblank', 31 | 'screensaver', 32 | 'subtitleappearancesettings', 33 | 'subtitleburnsettings', 34 | 'chromecast', 35 | 'multiserver' 36 | ]; 37 | 38 | window.NativeShell = { 39 | AppHost: { 40 | init: function () { 41 | postMessage('AppHost.init', AppInfo); 42 | return Promise.resolve(AppInfo); 43 | }, 44 | 45 | appName: function () { 46 | postMessage('AppHost.appName', AppInfo.appName); 47 | return AppInfo.appName; 48 | }, 49 | 50 | appVersion: function () { 51 | postMessage('AppHost.appVersion', AppInfo.appVersion); 52 | return AppInfo.appVersion; 53 | }, 54 | 55 | deviceId: function () { 56 | postMessage('AppHost.deviceId', AppInfo.deviceId); 57 | return AppInfo.deviceId; 58 | }, 59 | 60 | deviceName: function () { 61 | postMessage('AppHost.deviceName', AppInfo.deviceName); 62 | return AppInfo.deviceName; 63 | }, 64 | 65 | exit: function () { 66 | postMessage('AppHost.exit'); 67 | }, 68 | 69 | getDefaultLayout: function () { 70 | postMessage('AppHost.getDefaultLayout', 'tv'); 71 | return 'tv'; 72 | }, 73 | 74 | getDeviceProfile: function (profileBuilder) { 75 | postMessage('AppHost.getDeviceProfile'); 76 | return profileBuilder({ 77 | enableMkvProgressive: false, 78 | enableSsaRender: true, 79 | supportsDolbyAtmos: deviceInfo ? deviceInfo.dolbyAtmos : null, 80 | supportsDolbyVision: deviceInfo ? deviceInfo.dolbyVision : null, 81 | supportsHdr10: deviceInfo ? deviceInfo.hdr10 : null 82 | }); 83 | }, 84 | 85 | getSyncProfile: function (profileBuilder) { 86 | postMessage('AppHost.getSyncProfile'); 87 | return profileBuilder({ enableMkvProgressive: false }); 88 | }, 89 | 90 | supports: function (command) { 91 | var isSupported = command && SupportedFeatures.indexOf(command.toLowerCase()) != -1; 92 | postMessage('AppHost.supports', { 93 | command: command, 94 | isSupported: isSupported 95 | }); 96 | return isSupported; 97 | }, 98 | 99 | screen: function () { 100 | return deviceInfo ? { 101 | width: deviceInfo.screenWidth, 102 | height: deviceInfo.screenHeight 103 | } : null; 104 | } 105 | }, 106 | 107 | selectServer: function () { 108 | postMessage('selectServer'); 109 | }, 110 | 111 | downloadFile: function (url) { 112 | postMessage('downloadFile', { url: url }); 113 | }, 114 | 115 | enableFullscreen: function () { 116 | postMessage('enableFullscreen'); 117 | }, 118 | 119 | disableFullscreen: function () { 120 | postMessage('disableFullscreen'); 121 | }, 122 | 123 | getPlugins: function () { 124 | postMessage('getPlugins'); 125 | return []; 126 | }, 127 | 128 | openUrl: function (url, target) { 129 | postMessage('openUrl', { 130 | url: url, 131 | target: target 132 | }); 133 | }, 134 | 135 | updateMediaSession: function (mediaInfo) { 136 | postMessage('updateMediaSession', { mediaInfo: mediaInfo }); 137 | }, 138 | 139 | hideMediaSession: function () { 140 | postMessage('hideMediaSession'); 141 | } 142 | }; 143 | })(window.AppInfo, window.DeviceInfo); 144 | -------------------------------------------------------------------------------- /frontend/webOSTVjs-1.2.11/LICENSE-2.0.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /frontend/webOSTVjs-1.2.11/webOSTV-dev.js: -------------------------------------------------------------------------------- 1 | window.webOSDev=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var r=1;r0&&void 0!==arguments[0]?arguments[0]:function(){},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){},t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(!this.cancelled){var o={};try{o=JSON.parse(n)}catch(e){o={errorCode:-1,errorText:n,returnValue:!1}}var i=o,u=i.errorCode,c=i.returnValue;u||!1===c?(o.returnValue=!1,r(o)):(o.returnValue=!0,e(o)),t(o),this.subscribe||this.cancel()}}},{key:"cancel",value:function(){this.cancelled=!0,null!==this.bridge&&(this.bridge.cancel(),this.bridge=null),this.ts&&s[this.ts]&&delete s[this.ts]}}])&&c(r.prototype,t),n&&c(r,n),Object.defineProperty(r,"prototype",{writable:!1}),e}(),f={BROWSER:"APP_BROWSER"},d=function(e){var r=e.id,t=void 0===r?"":r,n=e.params,o=void 0===n?{}:n,i=e.onSuccess,u=void 0===i?function(){}:i,c=e.onFailure,a=void 0===c?function(){}:c,s={id:t,params:o};f.BROWSER===t&&(s.params.target=o.target||"",s.params.fullMode=!0,s.id="com.webos.app.browser"),function(e){var r=e.parameters,t=e.onSuccess,n=e.onFailure;(new l).send({service:"luna://com.webos.applicationManager",method:"launch",parameters:r,onComplete:function(e){var r=e.returnValue,o=e.errorCode,i=e.errorText;return!0===r?t():n({errorCode:o,errorText:i})}})}({parameters:s,onSuccess:u,onFailure:a})},b=function(){var e={};if(window.PalmSystem&&""!==window.PalmSystem.launchParams)try{e=JSON.parse(window.PalmSystem.launchParams)}catch(e){console.error("JSON parsing error")}return e},p=function(){return window.PalmSystem&&window.PalmSystem.identifier?window.PalmSystem.identifier.split(" ")[0]:""};function v(e){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function m(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function y(e){for(var r=1;r0&&void 0!==arguments[0]?arguments[0]:function(){},r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};setTimeout((function(){return e(r)}),0)},R=function(e){return e.state===T&&""!==e.getClientId()},C=function(e,r){var t=r.errorCode,n=void 0===t?S.UNKNOWN_ERROR:t,o=r.errorText,i={errorCode:n,errorText:void 0===o?"Unknown error.":o};return e.setError(i),i},N={errorCode:S.CLIENT_NOT_LOADED,errorText:"DRM client is not loaded."},_=function(){function e(r){!function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this,e),this.clientId="",this.drmType=r,this.errorCode=S.NOT_ERROR,this.errorText="",this.state=P}var r,t,n;return r=e,(t=[{key:"getClientId",value:function(){return this.clientId}},{key:"getDrmType",value:function(){return this.drmType}},{key:"getErrorCode",value:function(){return this.errorCode}},{key:"getErrorText",value:function(){return this.errorText}},{key:"setError",value:function(e){var r=e.errorCode,t=e.errorText;this.errorCode=r,this.errorText=t}},{key:"isLoaded",value:function(e){var r=this,t=e.onSuccess,n=void 0===t?function(){}:t,o=e.onFailure,i=void 0===o?function(){}:o;D({method:"isLoaded",parameters:{appId:p()},onComplete:function(e){if(!0===e.returnValue){if(r.clientId=e.clientId||"",r.state=e.loadStatus?T:P,!0===e.loadStatus&&e.drmType!==r.drmType)return i(C(r,{errorCode:S.UNKNOWN_ERROR,errorText:"DRM types of set and loaded are not matched."}));var t=y({},e);return delete t.returnValue,n(t)}return i(C(r,e))}})}},{key:"load",value:function(e){var r=this,t=e.onSuccess,n=void 0===t?function(){}:t,o=e.onFailure,i=void 0===o?function(){}:o;if(this.state!==j&&this.state!==T){var u={appId:p(),drmType:this.drmType};this.state=j,D({method:"load",onComplete:function(e){return!0===e.returnValue?(r.clientId=e.clientId,r.state=T,n({clientId:r.clientId})):i(C(r,e))},parameters:u})}else I(n,{isLoaded:!0,clientId:this.clientId})}},{key:"unload",value:function(e){var r=this,t=e.onSuccess,n=void 0===t?function(){}:t,o=e.onFailure,i=void 0===o?function(){}:o;if(R(this)){var u={clientId:this.clientId};this.state=E,D({method:"unload",onComplete:function(e){return!0===e.returnValue?(r.clientId="",r.state=P,n()):i(C(r,e))},parameters:u})}else I(i,C(this,N))}},{key:"getRightsError",value:function(e){var r=this,t=e.onSuccess,n=void 0===t?function(){}:t,o=e.onFailure,i=void 0===o?function(){}:o;R(this)?D({method:"getRightsError",parameters:{clientId:this.clientId,subscribe:!0},onComplete:function(e){if(!0===e.returnValue){var t=y({},e);return delete t.returnValue,n(t)}return i(C(r,e))}}):I(i,C(this,N))}},{key:"sendDrmMessage",value:function(e){var r=this,t=e.msg,n=void 0===t?"":t,o=e.onSuccess,i=void 0===o?function(){}:o,u=e.onFailure,c=void 0===u?function(){}:u;if(R(this)){var a=function(e){var r="",t="";switch(e){case w.PLAYREADY:r="application/vnd.ms-playready.initiator+xml",t="urn:dvb:casystemid:19219";break;case w.WIDEVINE:r="application/widevine+xml",t="urn:dvb:casystemid:19156"}return{msgType:r,drmSystemId:t}}(this.drmType),s=y({clientId:this.clientId,msg:n},a);D({method:"sendDrmMessage",onComplete:function(e){if(!0===e.returnValue){var t=y({},e);return delete t.returnValue,i(t)}return c(C(r,e))},parameters:s})}else I(c,C(this,N))}}])&&O(r.prototype,t),n&&O(r,n),Object.defineProperty(r,"prototype",{writable:!1}),e}(),x={Error:S,Type:w},V=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return""===e?null:new _(e)};function k(e){return(k="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function A(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function L(e,r,t){return(r=function(e){var r=function(e,r){if("object"!==k(e)||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!==k(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"===k(r)?r:String(r)}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var F=function(e){var r=e.service,t=e.subscribe,n=e.onSuccess,o=e.onFailure;(new l).send({service:r,method:"getStatus",parameters:{subscribe:t},onComplete:function(e){var r=function(e){for(var r=1;r-1&&(c="palm"),F({service:"luna://com.".concat(c,".connectionmanager"),subscribe:u,onSuccess:t,onFailure:o})}},U=function(e){var r=e.onSuccess,t=void 0===r?function(){}:r,n=e.onFailure,o=void 0===n?function(){}:n;-1!==navigator.userAgent.indexOf("Chrome")?(new l).send({service:"luna://com.webos.service.sm",method:"deviceid/getIDs",parameters:{idType:["LGUDID"]},onComplete:function(e){if(!0!==e.returnValue)o({errorCode:e.errorCode,errorText:e.errorText});else{var r=e.idList.filter((function(e){return"LGUDID"===e.idType}))[0].idValue;t({id:r})}}}):setTimeout((function(){o({errorCode:"ERROR.000",errorText:"Not supported."})}),0)}}]); -------------------------------------------------------------------------------- /frontend/webOSTVjs-1.2.11/webOSTV.js: -------------------------------------------------------------------------------- 1 | window.webOS=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e){e.exports=JSON.parse('{"name":"webostv-js","version":"1.2.11","description":"","main":"index.js","scripts":{"belazy":"npm run lint && npm run release","build":"node scripts/build.js","build:dev":"node scripts/build.js develop","clean":"git clean -xdf","lint":"eslint . --cache","format":"prettier --write \\"{src,tests,config,scripts}/**/*.{js,json}\\"","release":"node scripts/release.js","zip":"node scripts/zip.js","test":"node scripts/test.js app","test:mocha":"node scripts/test.js mocha"},"repository":{"type":"git","url":"http://mod.lge.com/hub/tvsdk/webostv-js.git"},"keywords":[],"author":"LGE TV Lab","license":"Apache-2.0","devDependencies":{"@babel/cli":"^7.10.1","@babel/core":"^7.10.2","@babel/polyfill":"^7.10.1","@babel/preset-env":"^7.10.2","address":"^1.0.3","archiver":"^4.0.1","babel-loader":"^8.1.0","chalk":"^2.4.1","command-exists":"^1.2.7","eslint":"^4.19.1","eslint-config-airbnb-base":"^12.1.0","eslint-loader":"^2.0.0","eslint-plugin-import":"^2.12.0","fs-extra":"^8.1.0","html-webpack-plugin":"^4.3.0","mocha":"^5.2.0","mocha-loader":"^1.1.3","prettier":"^3.2.5","webpack":"^4.10.1","webpack-dev-server":"^3.1.4","webpack-merge":"^4.1.2"}}')},function(e,t,n){"use strict";n.r(t),n.d(t,"deviceInfo",(function(){return I})),n.d(t,"fetchAppId",(function(){return o})),n.d(t,"fetchAppInfo",(function(){return i})),n.d(t,"fetchAppRootPath",(function(){return s})),n.d(t,"keyboard",(function(){return H})),n.d(t,"libVersion",(function(){return K})),n.d(t,"platformBack",(function(){return u})),n.d(t,"platform",(function(){return k})),n.d(t,"service",(function(){return b})),n.d(t,"systemInfo",(function(){return L}));var o=function(){return window.PalmSystem&&window.PalmSystem.identifier?window.PalmSystem.identifier.split(" ")[0]:""},r={},i=function(e,t){if(0===Object.keys(r).length){var n=function(t,n){if(!t&&n)try{r=JSON.parse(n),e&&e(r)}catch(t){console.error("Unable to parse appinfo.json file for",o()),e&&e()}else e&&e()},i=new window.XMLHttpRequest;i.onreadystatechange=function(){4===i.readyState&&(i.status>=200&&i.status<300||0===i.status?n(null,i.responseText):n({status:404}))};try{i.open("GET",t||"appinfo.json",!0),i.send(null)}catch(e){n({status:404})}}else e&&e(r)},s=function(){var e=window.location.href;if("baseURI"in window.document)e=window.document.baseURI;else{var t=window.document.getElementsByTagName("base");t.length>0&&(e=t[0].href)}var n=e.match(/.*:\/\/[^#]*\//);return n?n[0]:""},u=function(){if(window.PalmSystem&&window.PalmSystem.platformBack)return window.PalmSystem.platformBack()};function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function l(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:function(){},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(!this.cancelled){var r={};try{r=JSON.parse(o)}catch(e){r={errorCode:-1,errorText:o,returnValue:!1}}var i=r,s=i.errorCode,u=i.returnValue;s||!1===u?(r.returnValue=!1,t(r)):(r.returnValue=!0,e(r)),n(r),this.subscribe||this.cancel()}}},{key:"cancel",value:function(){this.cancelled=!0,null!==this.bridge&&(this.bridge.cancel(),this.bridge=null),this.ts&&p[this.ts]&&delete p[this.ts]}}])&&f(t.prototype,n),o&&f(t,o),Object.defineProperty(t,"prototype",{writable:!1}),e}(),b={request:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=l({service:e},t);return(new v).send(n)}};function y(e){return(y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var g={};if("object"===("undefined"==typeof window?"undefined":y(window))&&window.PalmSystem){if(window.navigator.userAgent.indexOf("SmartWatch")>-1)g.watch=!0;else if(window.navigator.userAgent.indexOf("SmartTV")>-1||window.navigator.userAgent.indexOf("Large Screen")>-1)g.tv=!0;else{try{var w=JSON.parse(window.PalmSystem.deviceInfo||"{}");if(w.platformVersionMajor&&w.platformVersionMinor){var h=Number(w.platformVersionMajor),O=Number(w.platformVersionMinor);h<3||3===h&&O<=0?g.legacy=!0:g.open=!0}}catch(e){g.open=!0}window.Mojo=window.Mojo||{relaunch:function(){}},window.PalmSystem.stageReady&&window.PalmSystem.stageReady()}if(window.navigator.userAgent.indexOf("Chr0me")>-1||window.navigator.userAgent.indexOf("Chrome")>-1){var S=window.navigator.userAgent.indexOf("Chr0me")>-1?window.navigator.userAgent.indexOf("Chr0me"):window.navigator.userAgent.indexOf("Chrome"),V=window.navigator.userAgent.slice(S).indexOf(" "),j=window.navigator.userAgent.slice(S+7,S+V).split(".");g.chrome=Number(j[0])}else g.chrome=0}else g.unknown=!0;var k=g,T={},P={},x=!1,A=!1,D=!1,C=[];function M(e){A&&D?(C.length&&(C.forEach((function(t){t!==e&&t(T)})),C=[]),e(T)):C.push(e)}function _(e){P.soundOutput&&0===P.soundOutput.indexOf("external_arc")&&"external_arc_sound_alive"!==P.soundOutput?e(!0):!P.soundOutput||0!==P.soundOutput.indexOf("tv_")&&"external_arc_sound_alive"!==P.soundOutput?e(null):e(!1)}function N(e){"auto"===P.soundOutputDigital||"passThrough"===P.soundOutputDigital?e(!0):e(!1)}function z(e,t){T.dolbyAtmos!==e&&(T.dolbyAtmos=e,A=!0,M(t))}function B(e){!function(e){T.sdkVersion&&e(T.sdkVersion.split(".")),(new v).send({service:"luna://com.webos.service.tv.systemproperty",method:"getSystemInfo",parameters:{keys:["sdkVersion"]},onSuccess:function(t){T.sdkVersion=t.sdkVersion||T.sdkVersion,e(T.sdkVersion.split("."))},onFailure:function(){e([0,0,0])}})}((function(t){parseInt(t[0],10)>=5?(new v).send({service:"luna://com.webos.service.arccontroller",method:"getARCState",subscribe:!0,onComplete:function(t){_((function(n){(n||!P.dolbyAtmosConfig&&"tv_speaker_external_arc_harmony"===P.soundOutput)&&N((function(n){z(!!n&&(t.returnValue&&("ATMOS"===t.arcProfile||!0===t.earcATMOS)),e)}))}))},onFailure:function(){console.log("[webOSTV.js] getARCState failed"),z(!1,e)}}):(new v).send({service:"luna://com.webos.service.eim",method:"getAllInputStatus",subscribe:!0,onComplete:function(t){_((function(n){!n&&(P.dolbyAtmosConfig||"tv_speaker_external_arc_harmony"!==P.soundOutput&&void 0!==P.soundOutput)||N((function(n){z(!!n&&(t.returnValue&&!0===t.atmosDevice),e)}))}))},onFailure:function(){console.log("[webOSTV.js] getAllInputStatus failed"),z(!1,e)}})}))}function R(e){void 0===P.dolbyAtmosConfig?(new v).send({service:"luna://com.webos.service.config",method:"getConfigs",parameters:{configNames:["tv.config.supportDolbyTVATMOS","tv.model.soundModeType"]},onComplete:function(t){P.dolbyAtmosConfig=t.configs?t.configs["tv.config.supportDolbyTVATMOS"]||"Dolby Atmos"===t.configs["tv.model.soundModeType"]:"failure",R(e)}}):!0===P.dolbyAtmosConfig?z(!0,e):!1===P.dolbyAtmosConfig?"tv_speaker_external_arc_harmony"===P.soundOutput?N((function(t){t?B(e):z(!1,e)})):void 0===P.soundOutput?(console.log("[webOSTV.js] soundOutput value is",P.soundOutput),B(e)):z(!1,e):(console.log("[webOSTV.js] dolbyAtmos config is",P.dolbyAtmosConfig),z(!1,e))}function E(e){(new v).send({service:"luna://com.webos.service.config",method:"getConfigs",parameters:{configNames:["com.webos.app.home.uiStyle","com.webos.service.utp.supportTunerless","profile.list","tv.config.supportDolbyHDRContents","tv.hw.ddrSize","tv.hw.displayType","tv.hw.panelResolution","tv.model.mainboardMaker","tv.model.modelname","tv.model.supportHDR","tv.model.supportTemp8K","tv.model.TVBrandName","tv.model.TVManufacturer","tv.nyx.firmwareVersion","tv.nyx.platformVersion","wee.platformBizType"]},onComplete:function(t){if(t.configs){if(T.modelName=t.configs["tv.model.modelname"]||T.modelName,t.configs["tv.nyx.firmwareVersion"]&&"0.0.0"!==t.configs["tv.nyx.firmwareVersion"]||(t.configs["tv.nyx.firmwareVersion"]=t.configs["tv.nyx.platformVersion"]),t.configs["tv.nyx.firmwareVersion"]){T.version=t.configs["tv.nyx.firmwareVersion"];for(var n=T.version.split("."),o=["versionMajor","versionMinor","versionDot"],r=0;r 0 && element.offsetHeight > 0; 40 | } 41 | 42 | function findIndex(array, currentNode) { 43 | //This just implements the following function which is not available on some LG TVs 44 | //Array.from(allElements).findIndex(function (el) { return currentNode.isEqualNode(el); }) 45 | for (var i = 0, item; item = array[i]; i++) { 46 | if (currentNode.isEqualNode(item)) 47 | return i; 48 | } 49 | } 50 | 51 | function navigate(amount) { 52 | console.log("Navigating " + amount.toString() + "...") 53 | var element = document.activeElement; 54 | if (element === null) { 55 | navigationInit(); 56 | } else if (!isVisible(element) || element.tagName == 'BODY') { 57 | navigationInit(); 58 | } else { 59 | //Isolate the node that we're after 60 | const currentNode = element; 61 | 62 | //find all tab-able elements 63 | const allElements = document.querySelectorAll('input, button, a, area, object, select, textarea, [contenteditable]'); 64 | 65 | //Find the current tab index. 66 | const currentIndex = findIndex(allElements, currentNode); 67 | 68 | //focus the following element 69 | if (allElements[currentIndex + amount]) 70 | allElements[currentIndex + amount].focus(); 71 | } 72 | } 73 | 74 | 75 | function upArrowPressed() { 76 | navigate(-1); 77 | } 78 | 79 | function downArrowPressed() { 80 | navigate(1); 81 | } 82 | function leftArrowPressed() { 83 | // Your stuff here 84 | } 85 | 86 | function rightArrowPressed() { 87 | // Your stuff here 88 | } 89 | 90 | function backPressed() { 91 | webOS.platformBack(); 92 | } 93 | 94 | document.onkeydown = function (evt) { 95 | evt = evt || window.event; 96 | switch (evt.keyCode) { 97 | case 37: 98 | leftArrowPressed(); 99 | break; 100 | case 39: 101 | rightArrowPressed(); 102 | break; 103 | case 38: 104 | upArrowPressed(); 105 | break; 106 | case 40: 107 | downArrowPressed(); 108 | break; 109 | case 461: // Back 110 | backPressed(); 111 | break; 112 | } 113 | }; 114 | 115 | function handleCheckbox(elem, evt) { 116 | console.log(elem); 117 | if (evt === true) { 118 | return true; // webos should be capable of toggling the checkbox by itself 119 | } else { 120 | evt = evt || window.event; //keydown event 121 | if (evt.keyCode == 13 || evt.keyCode == 32) { //OK button or Space 122 | elem.checked = !elem.checked; 123 | } 124 | } 125 | return false; 126 | } 127 | 128 | // Similar to jellyfin-web 129 | function generateDeviceId() { 130 | return btoa([navigator.userAgent, new Date().getTime()].join('|')).replace(/=/g, '1'); 131 | } 132 | 133 | function getDeviceId() { 134 | // Use variable '_deviceId2' to mimic jellyfin-web 135 | 136 | var deviceId = storage.get('_deviceId2'); 137 | 138 | if (!deviceId) { 139 | deviceId = generateDeviceId(); 140 | storage.set('_deviceId2', deviceId); 141 | } 142 | 143 | return deviceId; 144 | } 145 | 146 | function navigationInit() { 147 | if (isVisible(document.querySelector('#connect'))) { 148 | document.querySelector('#connect').focus() 149 | } else if (isVisible(document.querySelector('#abort'))) { 150 | document.querySelector('#abort').focus() 151 | } 152 | } 153 | 154 | function Init() { 155 | appInfo.deviceId = getDeviceId(); 156 | 157 | webOS.fetchAppInfo(function (info) { 158 | if (info) { 159 | appInfo.appVersion = info.version; 160 | } else { 161 | console.error('Error occurs while getting appinfo.json.'); 162 | } 163 | }); 164 | 165 | navigationInit(); 166 | 167 | if (storage.exists('connected_servers')) { 168 | connected_servers = storage.get('connected_servers') 169 | var first_server = connected_servers[Object.keys(connected_servers)[0]] 170 | document.querySelector('#baseurl').value = first_server.baseurl; 171 | document.querySelector('#auto_connect').checked = first_server.auto_connect; 172 | if (window.performance && window.performance.navigation.type == window.performance.navigation.TYPE_BACK_FORWARD) { 173 | console.log('Got here using the browser "Back" or "Forward" button, inhibiting auto connect.'); 174 | } else { 175 | if (first_server.auto_connect) { 176 | console.log("Auto connecting..."); 177 | handleServerSelect(); 178 | } 179 | } 180 | renderServerList(connected_servers); 181 | } 182 | } 183 | // Just ensure that the string has no spaces, and begins with either http:// or https:// (case insensitively), and isn't empty after the :// 184 | function validURL(str) { 185 | pattern = /^https?:\/\/\S+$/i; 186 | return !!pattern.test(str); 187 | } 188 | 189 | function normalizeUrl(url) { 190 | url = url.trimLeft ? url.trimLeft() : url.trimStart(); 191 | if (url.indexOf("http://") != 0 && url.indexOf("https://") != 0) { 192 | // assume http 193 | url = "http://" + url; 194 | } 195 | // normalize multiple slashes as this trips WebOS in some cases 196 | var parts = url.split("://"); 197 | for (var i = 1; i < parts.length; i++) { 198 | var part = parts[i]; 199 | while (true) { 200 | var newpart = part.replace("//", "/"); 201 | if (newpart.length == part.length) break; 202 | part = newpart; 203 | } 204 | parts[i] = part; 205 | } 206 | return parts.join("://"); 207 | } 208 | 209 | function handleServerSelect() { 210 | var baseurl = normalizeUrl(document.querySelector('#baseurl').value); 211 | var auto_connect = document.querySelector('#auto_connect').checked; 212 | 213 | if (validURL(baseurl)) { 214 | 215 | displayConnecting(); 216 | console.log(baseurl, auto_connect); 217 | 218 | if (curr_req) { 219 | console.log("There is an active request."); 220 | abort(); 221 | } 222 | hideError(); 223 | getServerInfo(baseurl, auto_connect); 224 | } else { 225 | console.log(baseurl); 226 | displayError("Please enter a valid URL, it needs a scheme (http:// or https://), a hostname or IP (ex. jellyfin.local or 192.168.0.2) and a port (ex. :8096 or :8920)."); 227 | } 228 | } 229 | 230 | function displayError(error) { 231 | var errorElem = document.querySelector('#error') 232 | errorElem.style.display = ''; 233 | errorElem.innerHTML = error; 234 | } 235 | function hideError() { 236 | var errorElem = document.querySelector('#error') 237 | errorElem.style.display = 'none'; 238 | errorElem.innerHTML = ' '; 239 | } 240 | 241 | function displayConnecting() { 242 | document.querySelector('#serverInfoForm').style.display = 'none'; 243 | document.querySelector('#busy').style.display = ''; 244 | navigationInit(); 245 | } 246 | function hideConnecting() { 247 | document.querySelector('#serverInfoForm').style.display = ''; 248 | document.querySelector('#busy').style.display = 'none'; 249 | navigationInit(); 250 | } 251 | function getServerInfo(baseurl, auto_connect) { 252 | curr_req = ajax.request(normalizeUrl(baseurl + "/System/Info/Public"), { 253 | method: "GET", 254 | success: function (data) { 255 | handleSuccessServerInfo(data, baseurl, auto_connect); 256 | }, 257 | error: handleFailure, 258 | abort: handleAbort, 259 | timeout: 5000 260 | }); 261 | } 262 | 263 | function getManifest(baseurl) { 264 | curr_req = ajax.request(normalizeUrl(baseurl + "/web/manifest.json"), { 265 | method: "GET", 266 | success: function (data) { 267 | handleSuccessManifest(data, baseurl); 268 | }, 269 | error: handleFailure, 270 | abort: handleAbort, 271 | timeout: 5000 272 | }); 273 | } 274 | 275 | function getConnectedServers() { 276 | connected_servers = storage.get('connected_servers'); 277 | if (!connected_servers) { 278 | connected_servers = {}; 279 | } 280 | return connected_servers; 281 | } 282 | 283 | 284 | function handleSuccessServerInfo(data, baseurl, auto_connect) { 285 | curr_req = false; 286 | 287 | connected_servers = getConnectedServers(); 288 | for (var server_id in connected_servers) { 289 | var server = connected_servers[server_id] 290 | if (server.baseurl == baseurl) { 291 | if (server.id != data.Id && server.id !== false) { 292 | //server has changed warn user. 293 | hideConnecting(); 294 | displayError("The server ID has changed since the last connection, please check if you are reaching your own server. To connect anyway, click connect again."); 295 | delete connected_servers[server_id] 296 | connected_servers[data.Id] = ({ 'baseurl': baseurl, 'auto_connect': false, 'id': false }) 297 | storage.set('connected_server', connected_servers) 298 | return false 299 | } 300 | } 301 | } 302 | 303 | 304 | connected_servers = lruStrategy(connected_servers,4, { 'baseurl': baseurl, 'auto_connect': auto_connect, 'id': data.Id, 'Name':data.ServerName }) 305 | 306 | storage.set('connected_servers', connected_servers); 307 | 308 | 309 | getManifest(baseurl) 310 | return true; 311 | } 312 | 313 | function lruStrategy(old_items,max_items,new_item) { 314 | var result = {} 315 | var id = new_item.id 316 | 317 | delete old_items[id] // LRU: re-insert entry (in front) each time it is used 318 | result[id] = new_item 319 | var keys = Object.keys(old_items) 320 | for (var i=0; i 0) { 386 | displayError("Got HTTP error " + data.error.toString() + " from server, are you connecting to a Jellyfin Server?") 387 | } else { 388 | displayError("Unknown error occured, are you connecting to a Jellyfin Server?") 389 | } 390 | 391 | hideConnecting(); 392 | storage.remove('connected_server'); 393 | curr_req = false; 394 | } 395 | 396 | function abort() { 397 | if (curr_req) { 398 | curr_req.abort() 399 | } else { 400 | hideConnecting(); 401 | } 402 | console.log("Aborting..."); 403 | } 404 | 405 | function loadUrl(url, success, failure) { 406 | var xhr = new XMLHttpRequest(); 407 | 408 | xhr.open('GET', url); 409 | 410 | xhr.onload = function () { 411 | success(xhr.responseText); 412 | }; 413 | 414 | xhr.onerror = function () { 415 | failure("Failed to load '" + url + "'"); 416 | } 417 | 418 | xhr.send(); 419 | } 420 | 421 | function getTextToInject(success, failure) { 422 | var bundle = {}; 423 | 424 | var urls = ['js/webOS.js', 'css/webOS.css']; 425 | 426 | // imitate promises as they're borked in at least WebOS 2 427 | var looper = function (idx) { 428 | if (idx >= urls.length) { 429 | success(bundle); 430 | } else { 431 | var url = urls[idx]; 432 | var ext = url.split('.').pop(); 433 | loadUrl(url, function (data) { 434 | bundle[ext] = (bundle[ext] || '') + data; 435 | looper(idx + 1); 436 | }, failure); 437 | } 438 | }; 439 | looper(0); 440 | } 441 | 442 | function injectScriptText(document, text) { 443 | var script = document.createElement('script'); 444 | script.type = 'text/javascript'; 445 | script.innerHTML = text; 446 | document.head.appendChild(script); 447 | } 448 | 449 | function injectStyleText(document, text) { 450 | var style = document.createElement('style'); 451 | style.innerHTML = text; 452 | document.body.appendChild(style); 453 | } 454 | 455 | function handoff(url, bundle) { 456 | console.log("Handoff called with: ", url) 457 | //hideConnecting(); 458 | 459 | stopDiscovery(); 460 | document.querySelector('.container').style.display = 'none'; 461 | 462 | var contentFrame = document.querySelector('#contentFrame'); 463 | var contentWindow = contentFrame.contentWindow; 464 | 465 | var timer; 466 | 467 | function onLoad() { 468 | clearInterval(timer); 469 | contentFrame.contentDocument.removeEventListener('DOMContentLoaded', onLoad); 470 | contentFrame.removeEventListener('load', onLoad); 471 | 472 | injectScriptText(contentFrame.contentDocument, 'window.AppInfo = ' + JSON.stringify(appInfo) + ';'); 473 | injectScriptText(contentFrame.contentDocument, 'window.DeviceInfo = ' + JSON.stringify(deviceInfo) + ';'); 474 | 475 | if (bundle.js) { 476 | injectScriptText(contentFrame.contentDocument, bundle.js); 477 | } 478 | 479 | if (bundle.css) { 480 | injectStyleText(contentFrame.contentDocument, bundle.css); 481 | } 482 | } 483 | 484 | function onUnload() { 485 | contentWindow.removeEventListener('unload', onUnload); 486 | 487 | timer = setInterval(function () { 488 | var contentDocument = contentFrame.contentDocument; 489 | 490 | switch (contentDocument.readyState) { 491 | case 'loading': 492 | clearInterval(timer); 493 | contentDocument.addEventListener('DOMContentLoaded', onLoad); 494 | break; 495 | 496 | // In the case of "loading" is not caught 497 | case 'interactive': 498 | onLoad(); 499 | break; 500 | } 501 | }, 0); 502 | } 503 | 504 | contentWindow.addEventListener('unload', onUnload); 505 | 506 | // In the case of "loading" and "interactive" are not caught 507 | contentFrame.addEventListener('load', onLoad); 508 | 509 | contentFrame.style.display = ''; 510 | contentFrame.src = url; 511 | } 512 | 513 | window.addEventListener('message', function (msg) { 514 | msg = msg.data; 515 | 516 | var contentFrame = document.querySelector('#contentFrame'); 517 | 518 | switch (msg.type) { 519 | case 'selectServer': 520 | startDiscovery(); 521 | document.querySelector('.container').style.display = ''; 522 | hideConnecting(); 523 | contentFrame.style.display = 'none'; 524 | contentFrame.src = ''; 525 | break; 526 | case 'AppHost.exit': 527 | webOS.platformBack(); 528 | break; 529 | } 530 | }); 531 | 532 | /* Server auto-discovery */ 533 | 534 | var discovered_servers = {}; 535 | var connected_servers = {}; 536 | 537 | function renderServerList(server_list) { 538 | for (var server_id in server_list) { 539 | var server = server_list[server_id]; 540 | renderSingleServer(server_id, server); 541 | } 542 | } 543 | 544 | function renderSingleServer(server_id, server) { 545 | var server_list = document.getElementById("serverlist"); 546 | var server_card = document.getElementById("server_" + server.Id); 547 | 548 | if (!server_card) { 549 | server_card = document.createElement("li"); 550 | server_card.id = "server_" + server_id; 551 | server_card.className = "server_card"; 552 | server_list.appendChild(server_card); 553 | } 554 | server_card.innerHTML = ""; 555 | 556 | // Server name 557 | var title = document.createElement("div"); 558 | title.className = "server_card_title"; 559 | title.innerText = server.Name; 560 | server_card.appendChild(title); 561 | 562 | // Server URL 563 | var server_url = document.createElement("div"); 564 | server_url.className = "server_card_url"; 565 | server_url.innerText = server.Address; 566 | server_card.appendChild(server_url); 567 | 568 | // Button 569 | var btn = document.createElement("button"); 570 | btn.innerText = "Connect"; 571 | btn.type = "button"; 572 | btn.value = server.Address; 573 | btn.onclick = function () { 574 | var urlfield = document.getElementById("baseurl"); 575 | urlfield.value = this.value; 576 | handleServerSelect(); 577 | }; 578 | server_card.appendChild(btn); 579 | } 580 | 581 | 582 | var servers_verifying = {}; 583 | 584 | function verifyThenAdd(server) { 585 | if (servers_verifying[server.Id]) { 586 | return; 587 | } 588 | servers_verifying[server.Id] = server; 589 | 590 | curr_req = ajax.request(normalizeUrl(server.Address + "/System/Info/Public"), { 591 | method: "GET", 592 | success: function (data) { 593 | console.log("success"); 594 | console.log(server); 595 | console.log(data); 596 | 597 | // TODO: Do we want to autodiscover only Jellyfin servers, or anything that responds to "who is JellyfinServer?" 598 | if (data.ProductName == "Jellyfin Server") { 599 | server.system_info_public = data; 600 | if (!discovered_servers[server.Id]) { 601 | discovered_servers[server.Id] = server; 602 | renderServerList(discovered_servers); 603 | } 604 | } 605 | servers_verifying[server.Id] = true; 606 | }, 607 | error: function (data) { 608 | console.log("error"); 609 | console.log(server); 610 | console.log(data); 611 | servers_verifying[server.Id] = false; 612 | }, 613 | abort: function () { 614 | console.log("abort"); 615 | console.log(server); 616 | servers_verifying[server.Id] = false; 617 | }, 618 | timeout: 5000 619 | }); 620 | } 621 | 622 | 623 | var discover = null; 624 | 625 | function startDiscovery() { 626 | if (discover) { 627 | return; 628 | } 629 | console.log("Starting server autodiscovery..."); 630 | discover = webOS.service.request("luna://org.jellyfin.webos.service", { 631 | method: "discover", 632 | parameters: { 633 | uniqueToken: 'fooo' 634 | }, 635 | subscribe: true, 636 | resubscribe: true, 637 | onSuccess: function (args) { 638 | console.log('OK:', JSON.stringify(args)); 639 | 640 | if (args.results) { 641 | for (var server_id in args.results) { 642 | verifyThenAdd(args.results[server_id]); 643 | } 644 | } 645 | }, 646 | onFailure: function (args) { 647 | console.log('ERR:', JSON.stringify(args)); 648 | } 649 | }); 650 | } 651 | 652 | function stopDiscovery() { 653 | if (discover) { 654 | try { 655 | discover.cancel(); 656 | } catch (err) { 657 | console.warn(err); 658 | } 659 | discover = null; 660 | } 661 | } 662 | 663 | startDiscovery(); 664 | --------------------------------------------------------------------------------