Setup SDK
LG WebOS SDK Integration Guide
Overview
This guide is for developers who want to monetize LG WebOS applications with PacketSDK.
Integrating the PacketSDK into an application is the first step toward earning revenue. Once you've integrated the SDK, you will start seeing devices data and revenue in PacketSDK Dashboard in 24 hours.
This document will walk you through the steps needed to be taken in order to properly integrate PacketSDK into your application.
Prerequisites
Step 1: Apply for appkey.
Register and log in to the PacketSDK, go to Dashboard to create your app and get your appkey.
appkey is an important way to track your earnings, please ensure it is set correctly in the subsequent integration steps.
Step 2: Download WebOS integration package.
Download the PacketSDK WebOS integration package packet_sdk_webos-1.0.*.zip and unzip it.
Once you unzip the package, you can see the following contents:
packet_sdk_webos-1.0.*.zip
├───sample_app - Integration example of general architecture of WebOS applications.
├───sdk - The main engine for the WebOS SDK, the controlling interface is based on Luna Service 2 API.
└───README.html
Step 3: Prepare the files.
Open sdk/service/package.json and set a correct name attribute, preserve .packet_sdk_service postfix at the end.
Open sdk/service/services.json and set a correct id, services[0].id and services[0].name attributes, preserve .packet_sdk_service postfix at the end.
ID in configuration files must comply with LG naming guidelines. When you add JS services into your app, do not include minus signs (-) or .(period)+ (for example, abc-1.0) in your app ID, because Luna Service does not allow them in a JS service name and the service name must begin with the app ID.
WebOS Platform Integration
Step 1: Copy the service directory next to other services that you already use.
Step 2: Refer to the example in the compressed file packet_sdk_webos-1.0.*.zip, integrate PacketSDK in your code.
packet_sdk_webos-1.0.*.zip, integrate PacketSDK in your code.After each start of the JS backend service, subscribe to the status of the SDK through the subscribe_sdk_status API for future checks on successful integration.
Set the application key through the set_appkey API.
Start the SDK through the start_packet_sdk API.
<script src="lib/webOSTV.js" charset="utf-8"></script>
// Replace "luna://com.company.app.packetsdk_service" with your actual URI based on the "name" you set in "Prerequisites-Step 3: Prepare the files".
function subscribeSdkStatus(){
webOS.service.request("luna://com.company.app.packetsdk_service", {
method: "subscribe_sdk_status",
parameters: { subscribe: true },
onSuccess: function (response) {
if(response.code == 0){
let appkey = response.data.appkey;
let sdk_version = response.data.sdk_version;
let sdk_started_status = response.data.sdk_started_status;
let sdk_detailed_status_message = response.data.sdk_detailed_status_message;
}
},
onFailure: function (response) {
console.log("LS2 API 'get_sdk_status' call failed.");
},
});
}
const app_key = "test"; // Replace the "test" with your actual appkey.
function setAppKey(){
webOS.service.request("luna://com.company.app.packetsdk_service", {
method: "set_appkey",
parameters: {
appkey: app_key
},
onSuccess: function (response) {
if(response.code == 0){
console.log("Set appkey successfully, message: " + response.message);
}else{
console.log("Set appkey failed, error code: " + response.code + " error message:" + response.message);
}
},
onFailure: function (response) {
console.log("LS2 API 'set_appkey' call failed.");
}
});
}
function startPacketSDK(){
webOS.service.request("luna://com.company.app.packetsdk_service", {
method: "start_packet_sdk",
parameters: {},
onSuccess: function (response) {
if(response.code == 0){
console.log("Start PacketSDK successfully, message: " + response.message);
}else{
console.log("Start PacketSDK failed, error code: " + response.code + " error message: " + response.message);
}
},
onFailure: function (response) {
console.log("LS2 API 'start_packet_sdk' call failed.");
}
});
}
function stopPacketSDK(){
webOS.service.request("luna://com.company.app.packetsdk_service", {
method: "stop_packet_sdk",
parameters: {},
onSuccess: function (response) {
if(response.code == 0){
console.log("Stop PacketSDK successfully, message: " + response.message);
}else{
console.log("Stop PacketSDK failed, error code: " + response.code + " error message: " + response.message);
}
},
onFailure: function (response) {
console.log("LS2 API 'stop_packet_sdk' call failed.");
}
});
}Step 3: Verify if integration is successful.
Start JS backend service and your WebOS application.
After call set_appkey and start_packet_sdk API, if you receive sdk_detailed_status: certification successful in the subscription SDK status callback function, it indicates that you have successfully integrated Packet SDK into your application.
Once you've received certification successful in the callback function, you will start seeing devices data and revenue in Packet SDK Dashboard in 24 hours.
Step 4: Build your app
In order to build your app you must use ares-package CLI command, which is a part of the WebOS CLI. You must use "-n" option to disable the process of minifying the source code.
Example: ares-package -n app_folder service_folder
Make sure you have removed all the dynamic files from the app and service folders before the build, such as logs.
How to update SDK:
Delete the service directory and replace it with a newer version.
Update package.json and services.json files.
Step 5: App performance
We care about the user experience at a high level, so it is important to pay attention to the performance of your app. Make sure that your app doesn't experience input lag, and that the CPU load is not high. We recommend not exceeding the average CPU load over 50% and not exceeding the RAM load over 90%.
If the system load is significant, we will not be able to use the free resources of the device. Such a device will not be counted as active and will not be paid.
To check the load on webOS, you can use the Beanviser from LG.
API documentation
Inter-process communication protocol: Luna Service 2 API
Please use the actual URI based on the
nameyou set inPrerequisites-Step3:Prepare the files. Service URI format example: luna://com.company.app.packetsdk_serviceAPI Description
subscribe_sdk_status - Subscribe to the status of packtsdk, and the callback function will automatically notify you when the sdk status changes.
Request parameters:
subscribe: true
Return example: {"code": 0, "data": {"appkey": "test", "sdk_version": "1.0.0", "sdk_started_status": true, "sdk_detailed_status_message": "certification successful"}, "message": "success"}
set_appkey - (Required)
Request parameters: {"appkey": "abcdefg"}
Return example: {"code": 0, "data": null, "message": "success"}
start_packet_sdk - (Required)
Request parameters: null
Return example: {"code": 0, "data": null, "message": "success"}
stop_packet_sdk
Request parameters: null
Return example: {"code": 0, "data": null, "message": "success"}
Return code and corresponding meaning
0 - success
20001 - invalid appkey
20010 - the appkey cannot be modified while the PacketSDK is running
30001 - packet sdk is already in a started state
30002 - packet sdk is already in a stopped state
Last updated