Typescript: how to get access to the navigator.connection property

Discussão em 'Angular' iniciado por sentenza, Novembro 26, 2024.

  1. sentenza

    sentenza Guest

    I would like to get access to the NetworkInformation interface using a simple TypeScript function like the following one:

    private checkNetworkConnection(): void {
    const connection = Navigator.connection
    || navigator.mozConnection
    || navigator.webkitConnection;
    const type = connection.type;
    console.log('CONNECTION TYPE: %o', type);
    console.log('DOWNLINK: %o', connection.downlink);
    }


    The fact is that I keep getting back the connection is undefined error. Looking around on SO I found that the people that use Cordova extend the type definitions of Typescript importing @types/cordova-plugin-network-information but that doesn't solve my issue.

    A working StackBlitz example can be found here.

    1. https://wicg.github.io/netinfo/#-dfn-connection-dfn-attribute
    2. https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API

    Continue reading...

Compartilhe esta Página