@krx3d/tizentube2 1.31.580 → 1.31.600

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@krx3d/tizentube2",
3
3
  "appName": "TizenTube",
4
- "version": "1.31.580",
4
+ "version": "1.31.600",
5
5
  "description": "TizenTube is an ad-free and sponsor-free solution for your favourite streaming website on your Tizen (Samsung) TVs.",
6
6
  "packageType": "mods",
7
7
  "websiteURL": "https://youtube.com/tv?additionalDataUrl=http%3A%2F%2Flocalhost%3A8085%2Fdial%2Fapps%2FYouTube",
@@ -253,16 +253,22 @@
253
253
  .then(r => r.json())
254
254
  .then(res => {
255
255
  sendLog('INFO', 'getState resolved: ' + JSON.stringify(res));
256
- previewTest();
256
+ startPreviewService();
257
257
  if (res.canConnectToDaemon && !res.isConnecting) {
258
258
  sendLog('INFO', 'Taking CDP-injection path, launching debugger and exiting');
259
259
  breadcrumb('cdp-handoff');
260
- fetch(`http://localhost:8099/tizentube/debugger${args ? `?${args}` : ''}`);
260
+ // A home bar tile's request rides along as ttLaunch; the
261
+ // service takes it out before anything reaches YouTube.
262
+ var tile = tileLaunchAction();
263
+ var query = [args, tile ? 'ttLaunch=' + encodeURIComponent(tile) : ''].filter(Boolean).join('&');
264
+ fetch(`http://localhost:8099/tizentube/debugger${query ? `?${query}` : ''}`);
261
265
  tizen.application.getCurrentApplication().exit();
262
266
  } else if (!res.canConnectToDaemon) {
263
267
  sendLog('INFO', 'Taking proxy path, navigating to localhost:8099/tv');
264
268
  breadcrumb('proxy-nav');
265
- location.href = `http://localhost:8099/tv?additionalDataUrl=http%3A%2F%2Flocalhost%3A8095%2Fdial%2Fapps%2FYouTube${args ? `&${args}` : ''}`
269
+ handOverTileLaunch(function () {
270
+ location.href = `http://localhost:8099/tv?additionalDataUrl=http%3A%2F%2Flocalhost%3A8095%2Fdial%2Fapps%2FYouTube${args ? `&${args}` : ''}`
271
+ });
266
272
  } else if (connectingPolls < MAX_CONNECTING_POLLS) {
267
273
  // canConnectToDaemon && isConnecting: a connection attempt is
268
274
  // (or was) already in progress. Neither branch above matched,
@@ -281,7 +287,9 @@
281
287
  // screen indefinitely, which is what this state used to do.
282
288
  sendLog('ERROR', 'isConnecting still true after ' + MAX_CONNECTING_POLLS + ' polls, falling back to proxy path');
283
289
  breadcrumb('proxy-nav', 'after isConnecting gave up');
284
- location.href = `http://localhost:8099/tv?additionalDataUrl=http%3A%2F%2Flocalhost%3A8095%2Fdial%2Fapps%2FYouTube${args ? `&${args}` : ''}`
290
+ handOverTileLaunch(function () {
291
+ location.href = `http://localhost:8099/tv?additionalDataUrl=http%3A%2F%2Flocalhost%3A8095%2Fdial%2Fapps%2FYouTube${args ? `&${args}` : ''}`
292
+ });
285
293
  }
286
294
  }).catch((err) => {
287
295
  // The service takes a couple of seconds to come up, and every
@@ -511,46 +519,59 @@
511
519
  attempt();
512
520
  }
513
521
 
514
- // Smart Hub Preview test build (see preview/preview.js). Called once
515
- // the service answers, so the report has somewhere to go.
516
- var previewTestDone = false;
517
- function previewTest() {
518
- if (previewTestDone) return;
519
- previewTestDone = true;
520
- function report(level, message) {
521
- try {
522
- fetch('http://localhost:8099/tizentube/previewEvent', {
523
- method: 'POST',
524
- headers: { 'Content-Type': 'application/json' },
525
- body: JSON.stringify({ level: level, message: '[index.html] ' + message })
526
- }).catch(function () {});
527
- } catch (e) {}
528
- }
529
- // A tile on the home bar starts the app with its action_data under
530
- // the key PAYLOAD. Only reported for now; opening the video comes
531
- // once the row is known to work.
532
- try {
533
- var data = tizen.application.getCurrentApplication().getRequestedAppControl().appControl.data || [];
534
- var keys = [];
535
- for (var i = 0; i < data.length; i++) {
536
- keys.push(data[i].key);
537
- if (data[i].key === 'PAYLOAD') report('INFO', 'started from a preview tile, PAYLOAD=' + String(data[i].value && data[i].value[0]).slice(0, 300));
538
- }
539
- report('INFO', 'launch app-control keys: ' + JSON.stringify(keys));
540
- } catch (e) {
541
- report('ERROR', 'reading app-control failed: ' + (e && e.message || e));
542
- }
522
+ // TizenTube's row on the TV home bar (see preview/preview.js and
523
+ // mods/features/homeBarPreview.js). Started on every app start so the
524
+ // stored row is published without waiting for the system's ten-minute
525
+ // round.
526
+ var previewServiceStarted = false;
527
+ function startPreviewService() {
528
+ if (previewServiceStarted) return;
529
+ previewServiceStarted = true;
543
530
  try {
544
531
  tizen.application.launchAppControl(
545
532
  new tizen.ApplicationControl('http://tizen.org/appcontrol/operation/pick', null, 'image/jpeg', null,
546
533
  [new tizen.ApplicationControlData('caller', ['ForegroundApp'])]),
547
534
  pkgId + '.PreviewService',
548
- function () { report('INFO', 'PreviewService launched'); },
549
- function (e) { report('ERROR', 'PreviewService launch failed: ' + (e && e.message || e)); }
535
+ function () { },
536
+ function (e) { sendLog('WARN', 'PreviewService launch failed: ' + (e && e.message || e)); }
550
537
  );
551
538
  } catch (e) {
552
- report('ERROR', 'PreviewService launch threw: ' + (e && e.message || e));
539
+ sendLog('WARN', 'PreviewService launch threw: ' + (e && e.message || e));
540
+ }
541
+ }
542
+
543
+ // A tile on the home bar starts the app with its action_data under the
544
+ // key PAYLOAD, as {"values":"<action_data>"}; ours is {"v":id} or
545
+ // {"p":playlistId}. Returned as a string for the service, or ''.
546
+ function tileLaunchAction() {
547
+ try {
548
+ var data = tizen.application.getCurrentApplication().getRequestedAppControl().appControl.data || [];
549
+ for (var i = 0; i < data.length; i++) {
550
+ if (data[i].key !== 'PAYLOAD' || !data[i].value) continue;
551
+ var outer = JSON.parse(data[i].value[0]);
552
+ var values = outer && outer.values;
553
+ var action = typeof values === 'string' ? JSON.parse(values) : values;
554
+ if (action && (typeof action.v === 'string' || typeof action.p === 'string')) {
555
+ return JSON.stringify(action.v ? { v: action.v } : { p: action.p });
556
+ }
557
+ }
558
+ } catch (e) {
559
+ sendLog('WARN', 'reading the home bar tile failed: ' + (e && e.message || e));
553
560
  }
561
+ return '';
562
+ }
563
+
564
+ // Proxy path: the page asks the service for it, so it is handed over
565
+ // first and the navigation waits (a second at most).
566
+ function handOverTileLaunch(then) {
567
+ var action = tileLaunchAction();
568
+ if (!action) return then();
569
+ var done = false;
570
+ var finish = function () { if (!done) { done = true; then(); } };
571
+ setTimeout(finish, 1000);
572
+ fetch('http://localhost:8099/tizentube/launchAction', {
573
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: action
574
+ }).then(finish, finish);
554
575
  }
555
576
 
556
577
  function launchService() {
@@ -1,25 +1,32 @@
1
- // Smart Hub Preview: TEST BUILD.
1
+ // Smart Hub Preview: TizenTube's row on the TV home bar.
2
2
  //
3
- // Asked for: a row of TizenTube content on the TV's home bar when the app
4
- // is highlighted, the way Emby shows one. That is Samsung's Smart Hub
5
- // Preview: a background service hands a JSON description of the row to
6
- // webapis.preview.setPreviewData(). This first version only answers whether
7
- // the row appears on these TVs at all, so it publishes three fixed tiles.
8
- // Real rows (Continue Watching, new from subscriptions) come after.
3
+ // The row is built in the page by mods/features/homeBarPreview.js (latest
4
+ // unfinished history entry, latest playlists, subscriptions) and stored by
5
+ // StandaloneService in tt-home-bar-preview.json. This service only publishes
6
+ // that file with webapis.preview.setPreviewData() and exits, as Samsung's
7
+ // sample does; a preview service that does not exit is ended after five
8
+ // minutes, which is also why this is not part of StandaloneService.
9
9
  //
10
- // A service of its own rather than part of StandaloneService: Samsung's
11
- // sample calls exit() right after setPreviewData, and a preview service that
12
- // does not exit is terminated after five minutes. StandaloneService has to
13
- // keep running for the proxy and the injector.
10
+ // Started by the system about every ten minutes, by index.html on every app
11
+ // start, and by StandaloneService right after the row changes.
14
12
  //
15
- // Plain ES5 on purpose. The 5.0 TV runs services on Node 4.4.3, and this
16
- // file is copied as-is (nothing bundles or transpiles it).
13
+ // Samsung shows these rows on TVs up to 2021. Confirmed on the 5.0 TV; the
14
+ // 6.5 TV accepts the data and shows nothing, as it does for every app.
17
15
  //
18
- // The system launches this service by itself roughly every ten minutes;
19
- // index.html also launches it on every start (the operation and caller data
20
- // match Samsung's BackgroundServiceLocal sample).
16
+ // Plain ES5 on purpose: the 5.0 TV runs services on Node 4.4.3, and this file
17
+ // is copied as-is (nothing bundles or transpiles it).
21
18
 
22
19
  var http = require('http');
20
+ var fs = require('fs');
21
+ var path = require('path');
22
+
23
+ var PREVIEW_FILE = 'tt-home-bar-preview.json';
24
+ // When this last published and what. Samsung takes one setPreviewData every
25
+ // ten minutes and drops the rest without an error, so a repeat of the same row
26
+ // is skipped and a changed one waits; StandaloneService starts this service
27
+ // again once the ten minutes are up.
28
+ var STATE_FILE = 'tt-home-bar-preview-published.json';
29
+ var MIN_GAP_MS = 10 * 60 * 1000;
23
30
 
24
31
  // Lines land in the syslog through StandaloneService, when it is running.
25
32
  function report(level, message) {
@@ -38,31 +45,32 @@ function report(level, message) {
38
45
  } catch (e) {}
39
46
  }
40
47
 
41
- function tile(videoId, title, subtitle) {
42
- return {
43
- title: title,
44
- subtitle: subtitle,
45
- // hqdefault is 480x360, inside Samsung's 4:3 limits (333x250 to
46
- // 480x360) and well under the 360 KB cap.
47
- image_url: 'https://i.ytimg.com/vi/' + videoId + '/hqdefault.jpg',
48
- image_ratio: '4by3',
49
- action_data: JSON.stringify({ videoId: videoId }),
50
- is_playable: true
51
- };
48
+ // The same places StandaloneService tries (storeCandidates in
49
+ // service/index.js), derived the same way: /opt/usr/apps/<pkgId>/res/wgt/...
50
+ function candidates() {
51
+ var parts = String(__dirname).split(String.fromCharCode(92)).join('/').split('/');
52
+ var i = parts.indexOf('apps');
53
+ var pkg = (i !== -1 && parts[i + 1]) ? parts[i + 1] : '';
54
+ if (!pkg) return [];
55
+ var out = [];
56
+ if (process.env.HOME) out.push(path.join(process.env.HOME, 'apps_rw', pkg, 'data', PREVIEW_FILE));
57
+ out.push(path.join('/opt/usr/home/owner/apps_rw', pkg, 'data', PREVIEW_FILE));
58
+ out.push(path.join('/home/owner/apps_rw', pkg, 'data', PREVIEW_FILE));
59
+ out.push(path.join('/opt/usr/apps', pkg, 'data', PREVIEW_FILE));
60
+ return out;
52
61
  }
53
62
 
54
- var PREVIEW = {
55
- sections: [{
56
- title: 'TizenTube (Test)',
57
- tiles: [
58
- tile('aqz-KE-bpKQ', 'Big Buck Bunny', 'Test tile 1'),
59
- tile('eRsGyueVLvQ', 'Sintel', 'Test tile 2'),
60
- tile('R6MlUcmOul8', 'Tears of Steel', 'Test tile 3')
61
- ]
62
- }]
63
- };
64
-
65
- var started = Date.now();
63
+ function readPreview() {
64
+ var list = candidates();
65
+ for (var i = 0; i < list.length; i++) {
66
+ try {
67
+ var raw = fs.readFileSync(list[i], 'utf8');
68
+ var data = JSON.parse(raw);
69
+ if (data && data.sections && data.sections.length !== undefined) return { data: data, raw: raw, file: list[i] };
70
+ } catch (e) {}
71
+ }
72
+ return null;
73
+ }
66
74
 
67
75
  function exitSoon() {
68
76
  // Give the report a moment to leave before the process goes.
@@ -71,36 +79,71 @@ function exitSoon() {
71
79
  }, 1500);
72
80
  }
73
81
 
82
+ function readState(dir) {
83
+ try { return JSON.parse(fs.readFileSync(path.join(dir, STATE_FILE), 'utf8')) || {}; } catch (e) { return {}; }
84
+ }
85
+
86
+ function writeState(dir, raw) {
87
+ try { fs.writeFileSync(path.join(dir, STATE_FILE), JSON.stringify({ at: Date.now(), raw: raw })); } catch (e) {}
88
+ }
89
+
90
+ // The 4:3 thumbnail form the test build proved, for a TV that refuses the
91
+ // 16:9 mqdefault images (smaller than Samsung's documented minimum).
92
+ function fallbackRaw(raw) {
93
+ return raw.split('/mqdefault.jpg').join('/hqdefault.jpg').split('"16by9"').join('"4by3"');
94
+ }
95
+
74
96
  function publish(trigger) {
75
97
  var hasPreview = typeof webapis !== 'undefined' && webapis && webapis.preview
76
98
  && typeof webapis.preview.setPreviewData === 'function';
77
99
  if (!hasPreview) {
78
- report('ERROR', 'webapis.preview is not available in this service (trigger ' + trigger
79
- + ', webapis ' + (typeof webapis) + ')');
100
+ report('ERROR', 'webapis.preview is not available (trigger ' + trigger + ')');
80
101
  exitSoon();
81
102
  return;
82
103
  }
83
- var version = '';
84
- try { version = webapis.preview.getVersion(); } catch (e) { version = 'n/a'; }
85
- try {
86
- webapis.preview.setPreviewData(JSON.stringify(PREVIEW), function () {
87
- report('INFO', 'setPreviewData succeeded (trigger ' + trigger + ', preview API ' + version
88
- + ', ' + (Date.now() - started) + ' ms after start)');
89
- exitSoon();
90
- }, function (err) {
91
- report('ERROR', 'setPreviewData failed (trigger ' + trigger + '): '
92
- + (err && (err.name + ': ' + err.message) || err));
93
- exitSoon();
94
- });
95
- } catch (e) {
96
- report('ERROR', 'setPreviewData threw (trigger ' + trigger + '): ' + (e && e.message || e));
104
+ var stored = readPreview();
105
+ if (!stored) {
106
+ // Nothing built yet: TizenTube has not run long enough since install.
107
+ report('INFO', 'no home bar row stored yet (trigger ' + trigger + ')');
108
+ exitSoon();
109
+ return;
110
+ }
111
+ var tiles = 0;
112
+ for (var i = 0; i < stored.data.sections.length; i++) tiles += (stored.data.sections[i].tiles || []).length;
113
+ var dir = path.dirname(stored.file);
114
+ var state = readState(dir);
115
+ var sinceMs = Date.now() - Number(state.at || 0);
116
+ if (state.raw === stored.raw && trigger === 'app') {
117
+ // Already showing this row; publishing it again would only use up the
118
+ // one update Samsung allows per ten minutes.
119
+ exitSoon();
120
+ return;
121
+ }
122
+ if (sinceMs >= 0 && sinceMs < MIN_GAP_MS) {
123
+ report('INFO', 'row changed, waiting ' + Math.round((MIN_GAP_MS - sinceMs) / 1000) + ' s: Samsung allows one update per 10 min (trigger ' + trigger + ')');
97
124
  exitSoon();
125
+ return;
98
126
  }
127
+ var attempt = function (raw, label, onFail) {
128
+ try {
129
+ webapis.preview.setPreviewData(raw, function () {
130
+ writeState(dir, stored.raw);
131
+ report('INFO', 'published ' + stored.data.sections.length + ' sections, ' + tiles + ' tiles' + label + ' (trigger ' + trigger + ')');
132
+ exitSoon();
133
+ }, function (err) {
134
+ report('ERROR', 'setPreviewData failed' + label + ' (trigger ' + trigger + '): ' + (err && (err.name + ': ' + err.message) || err));
135
+ if (onFail) onFail(); else exitSoon();
136
+ });
137
+ } catch (e) {
138
+ report('ERROR', 'setPreviewData threw' + label + ' (trigger ' + trigger + '): ' + (e && e.message || e));
139
+ if (onFail) onFail(); else exitSoon();
140
+ }
141
+ };
142
+ var fallback = fallbackRaw(stored.raw);
143
+ attempt(stored.raw, '', fallback !== stored.raw ? function () { attempt(fallback, ' with 4:3 thumbnails', null); } : null);
99
144
  }
100
145
 
101
- module.exports.onStart = function () {
102
- report('INFO', 'onStart');
103
- };
146
+ module.exports.onStart = function () {};
104
147
 
105
148
  module.exports.onRequest = function () {
106
149
  var trigger = 'system';