1

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
     }
}

Krusader
  • 116
  • 6

1 Answers1

1

I can suggest you using Systeminfo Public Web API for your purpose.

You can use:

tizen.systeminfo.getPropertyValue("ETHERNET_NETWORK", (s) => {console.log(s)}, (e) => {console.log(e)})

to determine if network cable is connected.

You can add a listener for notifications about this status changes with:

tizen.systeminfo.addPropertyValueChangeListener("ETHERNET_NETWORK", (s) => {console.log(s)})

and you will then receive events when cable connected/disconnnected.

EDIT: You can use public Web API to determine if network is in one of two states:

  • network cable is connected to TV, but network switch has no internet access (cable value is "ATTACHED"):
> tizen.systeminfo.getPropertyValue("ETHERNET_NETWORK", (s) => {console.log(s)}, (e) => {console.log(e)})
SystemInfoEthernetNetwork {cable: "ATTACHED", status: "DISCONNECTED", ipAddress: "", ipv6Address: "", macAddress: "ab:cd:ef:ab:cd:ef", …}
  • network cable is not connected to TV (cable value is "DETACHED"):
> tizen.systeminfo.getPropertyValue("ETHERNET_NETWORK", (s) => {console.log(s)}, (e) => {console.log(e)})

SystemInfoEthernetNetwork {cable: "DETACHED", status: "DEACTIVATED", ipAddress: "", ipv6Address: "", macAddress: "ab:cd:ef:ab:cd:ef", …}

It is not supported in Web API to register listener on physical layer, as mentioned in docs: "Change listener registered on ETHERNET_NETWORK property is triggered on ipAddress and ipv6Address properties change (the network layer)."

15kokos
  • 575
  • 2
  • 8
  • By saying **cable** do you mean `LAN` or just Internet cable from the switch to the wall? I intentionally mentioned, in my question, that I'm able to determine when `GATEWAY_DISCONNECTED` is fired, that is when cable from the wall is disconnected. What I can't determine is when `LAN` cable is detached from the TV. – Krusader Jan 25 '20 at 10:11
  • @Krusader I edited my answer to explain how Web API partially supports your scenario. – 15kokos Jan 27 '20 at 08:04
  • Unfortunately this doesn't work. When I detach Internet cable from the switch `getPropertyValue("ETHERNET_NETWORK"` fires with the following values: `cable: "ATTACHED"` & `status: "CONNECTED"` – Krusader Feb 02 '20 at 06:17