I build application for the Samsung TV in JavaScript using webapis.js
, now I have an issue to determine when LAN cable is attached/detached. My TV is connected to the internet via switch. When I detach internet cable from the switch I can determine that via webapis.network.isConnectedToGateway();
but when I detach LAN cable from the switch my application on the TV is stuck, developer tools throws an error: "Debugging connection was closed Reason: Websocket disconnected", so I can't even debug this case. I've already tried to save logs in cookies
/LocalStorage
but they are removed as soon as developer tools is disconnected.
So, how can I determine that LAN cable is not connected to the TV. Note: I don’t need to know when GATEWAY_DISCONNECTED but rather when LAN_CABLE_DETACHED.
Here is what I've tried so far:
function getIsConnected () {
try {
/// This will throw an exception when LAN is disconnected
var isConnectedToGateway = webapis.network.isConnectedToGateway();
console.log("isCableConnected value :: " + isConnectedToGateway);
return isConnectedToGateway;
/// won't help me here as when LAN is detached that doesn't work
//return Device.getNetworkConnectionType() === "LAN";
} catch (e) {
log.info("isCableConnected error :: " + e.message);
return 0;
}
}
/// I've also tried this, without any succes
webapis.network.getActiveConnectionType();
/// It only determines 2 states: GATEWAY_CONNECTED = 4; & GATEWAY_DISCONNECTED = 5;
/// which is not what I need
webapis.network.addNetworkStateChangeListener(function (data) {
if (data === 2) { // LAN_CABLE_DETACHED
// never gets here
} else if (data === 1) { // LAN_CABLE_ATTACHED
// never gets here either
}
}