@foxreis/tizentube 1.2.7 → 1.3.0

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.
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "service",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "service.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "dependencies": {
14
+ "@patrickkfkan/peer-dial": "^0.1.2",
15
+ "express": "^4.19.2"
16
+ },
17
+ "devDependencies": {
18
+ "@babel/core": "^7.24.7",
19
+ "@babel/preset-env": "^7.24.7",
20
+ "@rollup/plugin-babel": "^6.0.4",
21
+ "@rollup/plugin-commonjs": "^26.0.1",
22
+ "@rollup/plugin-json": "^6.1.0",
23
+ "@rollup/plugin-node-resolve": "^15.2.3",
24
+ "@rollup/plugin-replace": "^5.0.7",
25
+ "rollup": "^4.18.1"
26
+ }
27
+ }
@@ -0,0 +1,47 @@
1
+ import resolve from '@rollup/plugin-node-resolve';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import babel from '@rollup/plugin-babel';
4
+ import replace from '@rollup/plugin-replace';
5
+ import json from '@rollup/plugin-json';
6
+ import fs from 'fs';
7
+
8
+ // Custom Rollup plugin to inject XML content
9
+ function injectXmlContent() {
10
+ return {
11
+ name: 'inject-xml-content',
12
+ renderChunk(code) {
13
+
14
+ const pattern = /var\s+(\w+)_TEMPLATE\s+=\s+fs\$3\.readFileSync\(__dirname\s+\+\s+'\/\.\.\/xml\/([^']+)'\s*,\s*'utf8'\);/g;
15
+
16
+ const modifiedCode = code.replace(pattern, (match, varName, fileName) => {
17
+ const xmlContent = fs.readFileSync(`node_modules/@patrickkfkan/peer-dial/xml/${fileName}`, 'utf8');
18
+ return `var ${varName}_TEMPLATE = ${JSON.stringify(xmlContent)};`;
19
+ });
20
+
21
+ return { code: modifiedCode, map: null };
22
+ }
23
+ };
24
+ }
25
+
26
+ export default {
27
+ input: 'service.js',
28
+ output: {
29
+ file: '../dist/service.js',
30
+ format: 'cjs'
31
+ },
32
+ plugins: [
33
+ injectXmlContent(),
34
+ replace({
35
+ 'Gate.prototype.await = function await(callback)': 'Gate.prototype.await = function(callback)',
36
+ 'Async.prototype.await = function await(callback)': 'Async.prototype.await = function (callback)',
37
+ delimiters: ['', ''],
38
+ }),
39
+ resolve(),
40
+ json(),
41
+ commonjs(),
42
+ babel({
43
+ babelHelpers: 'bundled',
44
+ presets: ['@babel/preset-env']
45
+ })
46
+ ]
47
+ };
@@ -0,0 +1,68 @@
1
+ const dial = require("@patrickkfkan/peer-dial");
2
+ const express = require('express');
3
+ const app = express();
4
+ const PORT = 8085;
5
+ const apps = {
6
+ "YouTube": {
7
+ name: "YouTube",
8
+ state: "stopped",
9
+ allowStop: true,
10
+ pid: null,
11
+ launch(launchData) {
12
+ tizen.application.launchAppControl(
13
+ new tizen.ApplicationControl(
14
+ "http://tizen.org/appcontrol/operation/view",
15
+ null,
16
+ null,
17
+ null,
18
+ [
19
+ new tizen.ApplicationControlData("module", {
20
+ moduleName: '@foxreis/tizentube',
21
+ moduleType: 'npm',
22
+ args: launchData
23
+ })
24
+ ]
25
+ ), 'xvvl3S1bvH.TizenBrewStandalone');
26
+ }
27
+ }
28
+ };
29
+
30
+ const dialServer = new dial.Server({
31
+ expressApp: app,
32
+ port: PORT,
33
+ prefix: "/dial",
34
+ manufacturer: 'Reis Can',
35
+ modelName: 'TizenBrew',
36
+ friendlyName: 'TizenTube',
37
+ delegate: {
38
+ getApp(appName) {
39
+ return apps[appName];
40
+ },
41
+ launchApp(appName, launchData, callback) {
42
+ console.log(`Got request to launch ${appName} with launch data: ${launchData}`);
43
+ const app = apps[appName];
44
+ if (app) {
45
+ app.pid = "run";
46
+ app.state = "starting";
47
+ app.launch(launchData);
48
+ app.state = "running";
49
+ }
50
+ callback(app.pid);
51
+ },
52
+ stopApp(appName, pid, callback) {
53
+ console.log(`Got request to stop ${appName} with pid: ${pid}`);
54
+ const app = apps[appName];
55
+ if (app && app.pid === pid) {
56
+ app.pid = null;
57
+ app.state = "stopped";
58
+ callback(true);
59
+ } else {
60
+ callback(false);
61
+ }
62
+ }
63
+ }
64
+ });
65
+
66
+ app.listen(PORT, () => {
67
+ dialServer.start();
68
+ });