javascriptweboslgsmart-tv

LG WebOS 3.0 TV App - Luna connection manager subscription hanlder


I am developing a TV app for LG 4K TVs in webOS 3.0.

I am using Luna Connection Manager to subscribe network as shown in the LG developers document at http://webostv.developer.lge.com/api/webos-service-api/connection-manager/

I have sample codes as below, and I thought that my subscriptionHandle automatically detects if Network is connected or disconnected, and I can show No Connection message when disconnected.

var connected = false;
var subscriptionHandle = webOS.service.request("luna://com.palm.connectionmanager", {
    method: "getStatus",
    parameters: { "subscribe": true },
    onSuccess: function (inResponse) {
        if (typeof(inResponse.subscribed) != 'undefined') {
            if (!inResponse.subscribed) {
                console.log("Failed to subscribe network state");
                return;
            }
        }
        console.log('inResponse.isInternetConnectionAvailable -- %o ', inResponse.isInternetConnectionAvailable);
        console.log("Result: " + JSON.stringify(inResponse));
        if (inResponse.isInternetConnectionAvailable) {
            connected = true;
            Main.reConnected(); // remove disconnect message
            $('#error').append('Network Connected');
        } else {
             Main.showNoConnection(); // show disconnect message
             connected = false;
            $('#error').append('Network Disconnected'); 
        }
    },
    onFailure: function (inError) {
        console.log("Failed to get network state");
        console.log("[" + inError.errorCode + "]: " + inError.errorText);
        connected = false;
        Main.showNoConnection();
        $('#error').append('Network Disconnected');
        return;
    }
});

After the app is loaded, it doesn't go into the if condition. As a reference, I am printing out the connection status in #error element. It never gets updated. Am I missing more steps to make this work?

What I want to do is when Network is disconnected, show some kind of notification on the screen and when the connection is established, remove the message.


Solution

  • According to LG Developers, "Currently, you should use the luna://com.palm.connectionmanager for the webOS TV 1.0 and the luna://com.webos.service.connectionmanager for the webOS TV 2.0/3.0."

    My workaround is to use luna://com.webos.service.connectionmanager and also call subscriptionHandle.getStatus() every 15 seconds.