const myappsmodule = {};
(function () {
- var xhr;
function emptyElement(elm) {
while (elm.firstChild) {
elm.removeChild(elm.firstChild);
}, NEW_WINDOW_TIMEOUT);
};
+ function request(method, json, api, body) {
+ return new Promise(
+ (resolve, reject) => {
+ const xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = function () {
+ if (xhr.readyState === xhr.DONE) {
+ if (xhr.status === 200 || xhr.status === 201) {
+ resolve(xhr.responseText);
+ } else {
+ reject(xhr.responseText);
+ }
+ }
+ };
+ xhr.open(method, `${serverURL}:${serverPort}/${api}`);
+ if (json)
+ xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
+ body ? xhr.send(body) : xhr.send();
+ });
+ }
+
function showListView(dataArray) {
var formResult = document.getElementById("d2dApps"),
imgResult = document.getElementById("d2dAppList"),
d2dApp = dataArray[i]['d2dApp'];
if (d2dApp.hasOwnProperty("appName")) {
if (d2dApp.iconPath) {
- icon = d2dApp.iconPath.substring(d2dApp.iconPath.indexOf('/',10)+1);
+ icon = d2dApp.iconPath.substring(d2dApp.iconPath.indexOf('/', 10) + 1);
imgObj.src = `/d2dIcon/${icon}`;
} else {
imgObj.src = `./images/icon.png`;
}
imgObj.className = "app-icon-img";
imgObj.alt = d2dApp.appName;
+ imgObj.setAttribute('pkgId', d2dApp.pkgId);
+ imgObj.setAttribute('appId', d2dApp.appId);
textObj.style.display = "block";
textObj.style.margin = "0 auto";
textObj.style.fontSize = "14px";
textObj.innerHTML = d2dApp.appName;
}
- imgObj.addEventListener("click", actions.launchAppOnTV(
- d2dApp.pkgId,
- d2dApp.appId,
- function (response) {
- openAppWindow(response);
- }));
+ imgObj.addEventListener("click", function () {
+ var pkgId = this.getAttribute('pkgId');
+ var appId = this.getAttribute('appId');
+ showPreview(pkgId, appId);
+ }, false);
+ imgObj.addEventListener("dblclick", function () {
+ var pkgId = this.getAttribute('pkgId');
+ var appId = this.getAttribute('appId');
+ actions.launchAppOnTV(
+ pkgId,
+ appId,
+ '',
+ function (response) {
+ // TODO: should check if the app provides client page or not
+ openAppWindow(response);
+ })
+ }, false);
formObj.appendChild(imgObj);
formObj.appendChild(textObj);
}
}
+ function showPreview(pkgId, appId) {
+ const reqBody = JSON.stringify({ pkgId, appId });
+ request('POST', true, 'previewData', reqBody).then((body) => {
+ const preview = JSON.parse(body);
+ if (!preview.result.sections || !preview.result.sections.length)
+ return;
+ const previewSection = document.getElementById('preview-section');
+ previewSection.style.display = 'block';
+ previewSection.innerHTML = 'Preview';
+ const previewList = document.getElementById('preview-list');
+ previewList.style.display = 'grid';
+ previewList.innerHTML = '';
+ preview.result.sections.forEach(section => {
+ if (!section.tiles)
+ return;
+ section.tiles.forEach(tile => {
+ if (!tile.image_url)
+ return;
+ const img = document.createElement('img');
+ img.src = tile.image_url;
+ img.border = 0;
+ img.className = 'app-preview-img';
+ img.onclick = function () {
+ actions.launchAppOnTV(
+ pkgId,
+ appId,
+ tile.action_play_url,
+ function () { console.log('preview resumed') });
+ }
+ previewList.appendChild(img);
+ });
+ });
+ });
+ }
+
function showList() {
- xhr = new XMLHttpRequest();
- xhr.onreadystatechange = function () {
- if (xhr.readyState === xhr.DONE) {
- if (xhr.status === 200 || xhr.status === 201) {
- showListView(JSON.parse(xhr.responseText));
- } else {
- console.error(xhr.responseText);
- }
- }
- };
- xhr.open('GET', serverURL + ':' + serverPort + '/appList');
- xhr.send();
+ request('GET', false, 'appList').then((body) => {
+ showListView(JSON.parse(body));
+ })
}
function init() {