Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open Jellyfin in iframe to fix scrolling in webOS 3 #14

Merged
merged 6 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion org.jellyfin.webos/appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"vendor": "Jellyfin Project",
"largeIcon": "assets/icon-transparent130.png",
"iconColor": "#000b25",
"id": "org.jellyfin.webos"
"id": "org.jellyfin.webos",
"disableBackHistoryAPI": true
}
14 changes: 13 additions & 1 deletion org.jellyfin.webos/css/main.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
html,
body {
width: 100%;
margin: 0;
padding: 0;
height: 100%;
}

body {
width: 100%;
font-size: 36px;
font-family: -apple-system, "Helvetica", system-ui, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", "Open Sans", sans-serif;
background-color: #000b25;
color: white;
}

#contentFrame {
border: none;
width: 100%;
height: 100%;
}

.container {
position: absolute;
height: 100%;
Expand Down
1 change: 1 addition & 0 deletions org.jellyfin.webos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ <h1>Connecting...</h1>
<button id="abort" onclick="abort();">Abort</button>
</div>
</div>
<iframe id="contentFrame" style="display: none;"></iframe>
</body>

</html>
84 changes: 82 additions & 2 deletions org.jellyfin.webos/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ function rightArrowPressed() {
// Your stuff here
}

function backPressed() {
webOS.platformBack();
}

document.onkeydown = function (evt) {
evt = evt || window.event;
switch (evt.keyCode) {
Expand All @@ -83,6 +87,9 @@ document.onkeydown = function (evt) {
case 40:
downArrowPressed();
break;
case 461: // Back
backPressed();
break;
}
};

Expand Down Expand Up @@ -265,8 +272,81 @@ function abort() {
console.log("Aborting...");
}

function injectScript(document, url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we at least alert() a user if xhr failed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alert is not displayed. I can probably try to preload the injected script before actually connecting to the server, and then displayError in case of xhr failure.

injectScriptText(document, xhr.responseText);
};
xhr.send();
}

function injectScriptText(document, text) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML = text;
document.head.appendChild(script);
}

function handoff(url) {
console.log("Handoff called with: ", url)
//hideConnecting();
location.href = url;
}

document.querySelector('.container').style.display = 'none';

var contentFrame = document.querySelector('#contentFrame');
var contentWindow = contentFrame.contentWindow;

var timer;

function onLoad() {
clearInterval(timer);
contentFrame.contentDocument.removeEventListener('DOMContentLoaded', onLoad);
contentFrame.removeEventListener('load', onLoad);

injectScript(contentFrame.contentDocument, 'js/webOS.js');
}

function onUnload() {
contentWindow.removeEventListener('unload', onUnload);

timer = setInterval(function () {
var contentDocument = contentFrame.contentDocument;

switch (contentDocument.readyState) {
case 'loading':
clearInterval(timer);
contentDocument.addEventListener('DOMContentLoaded', onLoad);
break;

// In the case of "loading" is not caught
case 'interactive':
onLoad();
break;
}
}, 0);
}

contentWindow.addEventListener('unload', onUnload);

// In the case of "loading" and "interactive" are not caught
contentFrame.addEventListener('load', onLoad);

contentFrame.style.display = '';
contentFrame.src = url;
}

window.addEventListener('message', function (msg) {
msg = msg.data;

var contentFrame = document.querySelector('#contentFrame');

switch (msg.type) {
case 'AppHost.exit':
document.querySelector('.container').style.display = '';
hideConnecting();
contentFrame.style.display = 'none';
contentFrame.src = '';
break;
}
});
18 changes: 18 additions & 0 deletions org.jellyfin.webos/js/webOS.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function() {
'use strict';

console.log('WebOS adapter');

function postMessage(type, data) {
window.top.postMessage({
type: type,
data: data
}, '*');
}

window.webOS = {
platformBack: function () {
postMessage('AppHost.exit');
}
};
})();