-
-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Metered connection and usability check
- Loading branch information
1 parent
643b484
commit 539650e
Showing
10 changed files
with
74 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { get as getConfig } from "../ConfigStorage"; | ||
|
||
export function ispConnected() { | ||
|
||
const isMetered = getConfig('meteredConnection').meteredConnection; | ||
const connected = navigator.onLine; | ||
const type = navigator.connection.effectiveType; | ||
const downlink = navigator.connection.downlink; | ||
const rtt = navigator.connection.rtt; | ||
const logHead = '[ISP] '; | ||
|
||
if (navigator.connection) { | ||
console.log(`${logHead}Effective network type: ${navigator.connection.effectiveType}`); | ||
console.log(`${logHead}Downlink Speed: ${navigator.connection.downlink}Mb/s`); | ||
console.log(`${logHead}Round Trip Time: ${navigator.connection.rtt}ms`); | ||
} else { | ||
console.log(`${logHead}Navigator Connection API not supported`); | ||
} | ||
|
||
if (isMetered) { | ||
console.log(`${logHead}Metered connection is enabled`); | ||
return false; | ||
} | ||
|
||
if (type === 'slow-2g' || type === '2g' || downlink < 0.115 || rtt > 1000) { | ||
console.log(`${logHead}Slow network detected`); | ||
return false; | ||
} | ||
|
||
if (connected) { | ||
console.log(`${logHead}Connected to the internet`); | ||
return true; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters