jellyfin-tizen/tizen.js

152 lines
4.4 KiB
JavaScript
Raw Normal View History

2020-02-02 14:51:13 +00:00
(function () {
'use strict';
console.log('Tizen adapter');
// Similar to jellyfin-web
function generateDeviceId() {
return btoa([navigator.userAgent, new Date().getTime()].join('|')).replace(/=/g, '1');
}
function getDeviceId() {
// Use variable '_deviceId2' to mimic jellyfin-web
var deviceId = localStorage.getItem('_deviceId2');
if (!deviceId) {
deviceId = generateDeviceId();
localStorage.setItem('_deviceId2', deviceId);
}
return deviceId;
}
var AppInfo = {
deviceId: getDeviceId(),
deviceName: 'Samsung Smart TV',
appName: 'Jellyfin for Tizen',
appVersion: tizen.application.getCurrentApplication().appInfo.version
};
// List of supported features
var SupportedFeatures = [
'exit',
'exitmenu',
'externallinkdisplay',
'htmlaudioautoplay',
'htmlvideoautoplay',
'physicalvolumecontrol',
'displaylanguage',
'otherapppromotions',
'targetblank',
'screensaver',
2020-03-27 18:33:29 +00:00
'multiserver',
'subtitleappearancesettings',
'subtitleburnsettings'
2020-02-02 14:51:13 +00:00
];
function postMessage() {
console.log.apply(console, arguments);
}
window.NativeShell = {
AppHost: {
init: function () {
postMessage('AppHost.init', AppInfo);
return Promise.resolve(AppInfo);
},
appName: function () {
postMessage('AppHost.appName', AppInfo.appName);
return AppInfo.appName;
},
appVersion: function () {
postMessage('AppHost.appVersion', AppInfo.appVersion);
return AppInfo.appVersion;
},
deviceId: function () {
postMessage('AppHost.deviceId', AppInfo.deviceId);
return AppInfo.deviceId;
},
deviceName: function () {
postMessage('AppHost.deviceName', AppInfo.deviceName);
return AppInfo.deviceName;
},
exit: function () {
postMessage('AppHost.exit');
tizen.application.getCurrentApplication().exit();
},
getDefaultLayout: function () {
postMessage('AppHost.getDefaultLayout', 'tv');
return 'tv';
},
getDeviceProfile: function (profileBuilder) {
postMessage('AppHost.getDeviceProfile');
2020-06-13 19:54:23 +00:00
return profileBuilder({ enableMkvProgressive: false, enableSsaRender: true });
2020-02-02 14:51:13 +00:00
},
getSyncProfile: function (profileBuilder) {
postMessage('AppHost.getSyncProfile');
return profileBuilder({ enableMkvProgressive: false });
},
supports: function (command) {
var isSupported = command && SupportedFeatures.indexOf(command.toLowerCase()) != -1;
postMessage('AppHost.supports', {
command: command,
isSupported: isSupported
});
return isSupported;
}
},
downloadFile: function (url) {
postMessage('downloadFile', { url: url });
},
enableFullscreen: function () {
postMessage('enableFullscreen');
},
disableFullscreen: function () {
postMessage('disableFullscreen');
},
getPlugins: function () {
postMessage('getPlugins');
return [];
},
openUrl: function (url, target) {
postMessage('openUrl', {
url: url,
target: target
});
},
updateMediaSession: function (mediaInfo) {
postMessage('updateMediaSession', { mediaInfo: mediaInfo });
},
hideMediaSession: function () {
postMessage('hideMediaSession');
}
};
window.addEventListener('load', function () {
tizen.tvinputdevice.registerKey('MediaPlay');
tizen.tvinputdevice.registerKey('MediaPause');
tizen.tvinputdevice.registerKey('MediaStop');
tizen.tvinputdevice.registerKey('MediaTrackPrevious');
tizen.tvinputdevice.registerKey('MediaTrackNext');
tizen.tvinputdevice.registerKey('MediaRewind');
tizen.tvinputdevice.registerKey('MediaFastForward');
});
})();