Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement network information utilities #101

Closed
myty opened this issue Mar 17, 2021 · 0 comments
Closed

Implement network information utilities #101

myty opened this issue Mar 17, 2021 · 0 comments
Assignees

Comments

@myty
Copy link
Contributor

myty commented Mar 17, 2021

All modern browsers offer the Navigator.onLine property, and most modern browsers offer some form of NetworkInformation, Safari and Firefox being the exception. Having a common way of getting this information enables online/offline scenarios in the browser.

This is a proposal to merge the two into a common utility as well as offer up a much needed interface for typescript.

The key interfaces for this:

enum NetworkType {
    Bluetooth = "bluetooth",
    Cellular = "cellular",
    Ethernet = "ethernet",
    None = "none",
    Wifi = "wifi",
    Wimax = "wimax",
    Other = "other",
    Uknown = "unknown",
}

enum NetworkEffectiveType {
    Slow2g = "slow-2g",
    Cellular2g = "2g",
    Cellular3g = "3g",
    Cellular4g = "4g",
}

interface NetworkInformation {
    downlink?: number;
    downlinkMax?: number;
    effectiveType?: NetworkEffectiveType;
    saveData?: boolean;
    type?: NetworkType;
}

interface NetworkState extends NetworkInformation {
    isOnline: boolean;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants