Skip to main content

Tedshd's Dev note

Samsung Samrt TV - Network Error Handle

Table of Contents

# Samsung Samrt TV - Network Error Handle

## Example

Watch network connect status

  1. Add web api in HTML
<script type="text/javascript" language="javascript" src="$MANAGER_WIDGET/Common/webapi/1.0/webapis.js"></script>
  1. Add JavaScript code
var watchCB = {
    onconnect : function (type) {
        // (1) connected
        alert(type + " is connected successfully");
    },

    ondisconnect : function(type) {
        // (0) disconnected
        alert(type + " is disconnected");
    }
};

function successCB(networks) {
    for (var i = 0; networks.length; i++) {
        if (networks[i].isActive()) {
            networks[i].setWatchListener(watchCB, errorCB);
        }
    }
};

function errorCB(error) {
    alert(error.message);
};

try {
    webapis.network.getAvailableNetworks(successCB, errorCB);
} catch (error) {
    document.querySelector('h4').innerHTML = error.name;
    alert(error.name);
}

This sample code can detect network connect status

Refer - Web Device API Refer - Network