forked from dmitrylyzo/jellyfin-tizen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tizen.js
151 lines (124 loc) · 4.4 KB
/
tizen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
(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',
'multiserver',
'subtitleappearancesettings',
'subtitleburnsettings'
];
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');
return profileBuilder({ enableMkvProgressive: false, enableSsaRender: true });
},
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');
});
})();