-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adapt client concurrency to network conditions
Signed-off-by: Ryan Cao <[email protected]>
- Loading branch information
Showing
10 changed files
with
65 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pLimit from "p-limit"; | ||
|
||
export const autoClientConcurrency = () => { | ||
switch (window.navigator?.connection?.effectiveType) { | ||
case "4g": { | ||
return 10; | ||
} | ||
case "3g": { | ||
return 6; | ||
} | ||
case "2g": { | ||
return 3; | ||
} | ||
case "slow-2g": { | ||
return 1; | ||
} | ||
default: { | ||
return 8; | ||
} | ||
} | ||
}; | ||
|
||
export const clientPLimit = () => pLimit(autoClientConcurrency()); |
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,28 @@ | ||
declare interface Navigator extends NavigatorNetworkInformation {} | ||
declare interface WorkerNavigator extends NavigatorNetworkInformation {} | ||
|
||
declare interface NavigatorNetworkInformation { | ||
readonly connection?: NetworkInformation; | ||
} | ||
|
||
type ConnectionType = | ||
| "bluetooth" | ||
| "cellular" | ||
| "ethernet" | ||
| "mixed" | ||
| "none" | ||
| "wifi" | ||
| "wimax" | ||
| "other" | ||
| "unknown"; | ||
|
||
type EffectiveConnectionType = "2g" | "3g" | "4g" | "slow-2g"; | ||
|
||
interface NetworkInformation extends EventTarget { | ||
readonly type?: ConnectionType; | ||
readonly effectiveType?: EffectiveConnectionType; | ||
readonly downlink?: number; | ||
readonly downlinkMax?: number; | ||
readonly rtt?: number; | ||
readonly saveData?: boolean; | ||
} |
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