Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Samsung Smart Hub Preview Integration #319

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,21 @@
<description>Jellyfin for Samsung Smart TV (Tizen).</description>
<feature name="http://tizen.org/feature/screen.size.all"/>
<icon src="icon.png"/>
<tizen:app-control>
<tizen:src name="index.html" reload="disable"/>
<tizen:operation name="http://samsung.com/appcontrol/operation/eden_resume"/>
</tizen:app-control>
<tizen:service id="AprZAARz4r.service">
<tizen:content src="service/service.js"/>
<tizen:name>jellyfin_service</tizen:name>
<tizen:description>Jellyfin Smarthub Preview Handler Service</tizen:description>
<tizen:metadata key="meta-key" value="meta-value"/>
<tizen:category name="http://tizen.org/category/service"/>
</tizen:service>
<name>Jellyfin</name>
<tizen:privilege name="http://developer.samsung.com/privilege/productinfo"/>
<tizen:privilege name="http://tizen.org/privilege/tv.inputdevice"/>
<tizen:metadata key="http://samsung.com/tv/metadata/use.preview" value="bg_service"/>
<tizen:profile name="tv"/>
<tizen:setting screen-orientation="auto-rotation" context-menu="enable" background-support="disable" encryption="disable" install-location="auto" hwkey-event="enable"/>
</widget>
7 changes: 7 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ function modifyIndex() {
appMode.text = 'window.appMode=\'cordova\';';
injectTarget.insertBefore(appMode, apploader);


// inject smarthub.js
const smarthub = this.createElement('script');
smarthub.setAttribute('src', '../smarthub.js');
smarthub.setAttribute('defer', '');
injectTarget.insertBefore(smarthub, apploader);

// inject tizen.js
const tizen = this.createElement('script');
tizen.setAttribute('src', '../tizen.js');
Expand Down
101 changes: 101 additions & 0 deletions service/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
var packageId = tizen.application.getCurrentApplication().appInfo.packageId;
var applicationId = packageId + '.Jellyfin'
var remoteMessagePort = undefined;


/**
* Sends a message to Application and write out the log.
* It is needed because logs are not visible from service
*
* @param {string} value - The value to send in the message and wite to console
*/
function logAndSend(value)
{
console.log(value);
sendMessage(value);
}

/**
* Sends a message to the remote message port.
*
* @param {string} value - The value to send in the message.
* @param {string} [key="KEY"] - The key associated with the value. Defaults to "KEY".
*/
function sendMessage(value, key) {
key = key || "KEY";
if (remoteMessagePort === undefined) {
remoteMessagePort = tizen.messageport.requestRemoteMessagePort(applicationId, packageId);
}
if (remoteMessagePort ) {
try {
remoteMessagePort.sendMessage([{ key, value }]);
} catch (e) {
console.error("Error sending message:", e.message);
}
} else {
console.log("Message port is undefined");
}

}

function handleDataInRequest()
{
try {
var reqAppControl = tizen.application.getCurrentApplication().getRequestedAppControl();

if (!!reqAppControl) {
var appControlData = reqAppControl.appControl.data;

// Iterate through all keys in appControl.data
for (var i = 0; i < appControlData.length; i++) {
var key = appControlData[i].key;
var value = appControlData[i].value;

if (key === 'Preview') {
var previewData = value;
var previewData2 = JSON.parse(previewData);
logAndSend("Preview Data received: " + previewData);

try {
webapis.preview.setPreviewData(
JSON.stringify(previewData2),
function () {
logAndSend("Preview Set!");
tizen.application.getCurrentApplication().exit();
},
function (e) {
logAndSend("PreviewData Setting failed: " + e.message);
}
);
} catch (e) {
logAndSend("PreviewData Setting exception: " + e.message);
}
} else {
logAndSend("Unhandled key: " + key + ", value: " + value);
}
}
}
}
catch (e) {
logAndSend('On error exception : ' + e.message);
}
}

module.exports.onStart = function () {
logAndSend('OnStart recieved');
};

module.exports.onRequest = function () {
logAndSend('onRequest recieved');
handleDataInRequest();
}


module.exports.onStop = function () {
logAndSend('Service stopping...');
};


module.exports.onExit = function () {
logAndSend("Service exiting...");
}
Loading