Skip to main content

Integrating with WebOS

This guide provides instructions on how to integrate the Honeygain SDK into your WebOS application using the provided hgsdk.js and associated service.

info

Don't forget to generate your Honeygain SDK API Key and download SDK from Developers dashboard first.

Prerequisites

  • WebOS development environment set up
  • Basic knowledge of WebOS app development
  • Honeygain SDK files (hgsdk.js and service files)

Integration Steps

1. Add SDK Files

  1. Copy hgsdk.js to your app's directory.
  2. Add the service files to your project's service directory.

2. Include the SDK in your app

In your main HTML file (e.g., index.html), include the SDK:

<script src="path/to/hgsdk.js"></script>

3. Initialize the SDK

To initialize the Honeygain SDK, you need to create an instance of the HgSdk class with your API key. Here's an example of how to do this in your main JavaScript file:

var sdk = new HgSdk({
apiKey: 'your-api-key-here',
appId: 'your-app-id' // Example: com.honeygain.app
});

4. Use methods of SDK

Once you have initialized the SDK, you can use its methods to interact with the Honeygain service. Below are the methods provided by the class:

sdk.start() // Starts SDK if opted in or consented
sdk.stop() // Stops SDK
sdk.optIn() // Opts in without showing consent screen
sdk.optOut() // Opts out and stops SDK
sdk.requestConsent() // Shows consent screen
sdk.isOptedIn() // Returns a boolean
sdk.isRunning(function (isRunning) {}) // Returns a callback with boolean

5. Update service configuration files

To ensure that the SDK can find and use the service, you need to update two configuration files: package.json and services.json.

Update package.json

Update the service package.json file according to your application. Change the name value to have a suffix of .hg_sdk.

For example, if the app id is com.honeygain.app, package.json should be updated as such:

{
"name": "com.honeygain.app.hg_sdk",
// ...
}

Update services.json

Similarly, update the services.json file to match your application's identifier. The id and name fields should be updated to include the .hg_sdk suffix, matching the package.json file.

For example, if your app id is com.honeygain.app, the services.json file should be updated as follows:

{
"id": "com.honeygain.app.hg_sdk",
"description": "Honeygain SDK",
"services": [
{
"id": "com.honeygain.app.hg_sdk",
"name": "com.honeygain.app.hg_sdk",
// ...
}
]
}

6. Package the app with service

To package your WebOS app with the Honeygain SDK service, follow these steps:

  1. If you do not have a service besides Honeygain SDK, ensure your app directory structure looks like this:
your-app/
├── app/
│ ├── index.html
│ ├── hgsdk.js
│ └── ... (other app files)
├── service/
│ ├── package.json
│ ├── services.json
│ └── service.js
└── appinfo.json

If you have more, it should look like this:

your-app/
├── app/
│ ├── index.html
│ ├── hgsdk.js
│ └── ... (other app files)
├── service/
│ ├── service1/
│ │ ├── package.json
│ │ ├── services.json
│ │ └── service.js
│ ├── service2/
│ │ ├── package.json
│ │ ├── services.json
│ │ └── service.js
│ └── ... (other service folders)
└── appinfo.json
  1. Package your app using the ares-package command:

    ares-package ./app ./service

    This command will create a .ipk file in your current directory.

  2. Install the packaged app on your WebOS device or emulator:

    ares-install --device <your-device-name> <your-app-name>.ipk
  3. Launch the app:

    ares-launch --device <your-device-name> <your-app-id>

Logging

To enable logging to console by default, you can set the enableLogging option to true when creating the SDK instance:

var sdk = new HgSdk({
apiKey: 'your-api-key-here',
enableLogging: true,
});

This will log all SDK events to the console, including session start, stop, and heartbeat events. You can also customize the logging by providing a custom logger function that takes a message as an argument. This allows you to log messages to a file or any other logging service of your choice.

var sdk = new HgSdk({
apiKey: 'your-api-key-here',
enableLogging: true,
loggerCallback: function (message) {
// Custom logging logic
// For example, log to a file or send to a logging service
console.log(message);
}
});

Example log messages include:

info: Session started <session-id>
info: Heartbeat received
info: Heartbeat sent
info: Session stopped

error: Unable to resolve host
error: Unable to connect to server

Conclusion

By following these steps, you'll successfully package your WebOS app with the Honeygain SDK service. The service will run in the background, allowing your app to interact with it using the SDK methods described earlier.

Remember to replace com.honeygain.app with your actual app ID, and adjust other fields in the appinfo.json file as necessary for your specific application.

If you have any questions or encounter issues during integration, please reach out to us at [email protected] for support. Happy coding!