Skip to content

Commit

Permalink
Introduce network status
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Sep 17, 2024
1 parent 05d3230 commit ad65bc2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/components/status-bar/ConnectionStatus.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<template>
<div class="connection">
{{ $t("versionLabelConnection") }}: {{ networkSpeed }} Mb/s
{{ $t("versionLabelConnection") }}: {{ networkStatus }}
</div>
</template>

<script>
export default {
props: {
networkSpeed: {
type: Number,
default: 0,
networkStatus: {
type: String,
default: "",
},
},
};
Expand Down
8 changes: 4 additions & 4 deletions src/components/status-bar/StatusBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
unit="%"
/>
<ConnectionStatus
:network-speed="networkSpeed"
:network-status="networkStatus"
/>
<StatusBarVersion
:configurator-version="configuratorVersion"
Expand Down Expand Up @@ -72,9 +72,9 @@ export default {
default: 0,
},
networkSpeed: {
type: Number,
default: 0,
networkStatus: {
type: String,
default: "",
},
configuratorVersion: {
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
:cycle-time="FC.CONFIG.cycleTime"
:cpu-load="FC.CONFIG.cpuload"

:network-speed="CONFIGURATOR.networkSpeed"
:network-status="CONFIGURATOR.networkStatus"

:configurator-version="CONFIGURATOR.getDisplayVersion()"
:firmware-version="FC.CONFIG.flightControllerVersion"
Expand Down
2 changes: 1 addition & 1 deletion src/js/data_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CONFIGURATOR = {

connectionValid: false,
connectionValidCliOnly: false,
networkSpeed: 0,
networkStatus: 'UNKNOWN',
virtualMode: false,
virtualApiVersion: '0.0.1',
cliActive: false,
Expand Down
21 changes: 9 additions & 12 deletions src/js/utils/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@ export function ispConnected() {
const type = navigator.connection.effectiveType;
const downlink = navigator.connection.downlink;
const rtt = navigator.connection.rtt;
const logHead = '[ISP] ';

CONFIGURATOR.networkSpeed = downlink;

if (isMetered) {
console.log(`${logHead}Metered connection is enabled`);
if (type === 'none' || !connected) {
CONFIGURATOR.networkStatus = 'Offline';
return false;
}

if (type === 'slow-2g' || type === '2g' || downlink < 0.115 || rtt > 1000) {
console.log(`${logHead}Slow network detected`);
} else if (isMetered) {
CONFIGURATOR.networkStatus = 'Metered';
return false;
}

if (connected) {
} else if (type === 'slow-2g' || type === '2g' || downlink < 0.115 || rtt > 1000) {
CONFIGURATOR.networkStatus = 'Slow';
return false;
} else if (connected) {
CONFIGURATOR.networkStatus = 'Online';
return true;
}
}
Expand Down

0 comments on commit ad65bc2

Please sign in to comment.