Skip to content

Commit

Permalink
check if trace route has been rate limited
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcottle committed Nov 18, 2024
1 parent dc02d10 commit 4516f4f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@
</template>

<script>
import Connection from "../js/Connection.js";
export default {
name: 'App',
mounted() {
Connection.addClientNotificationListener(this.onClientNotification);
},
beforeUnmount() {
Connection.removeClientNotificationListener(this.onClientNotification);
},
methods: {
onClientNotification(clientNotification) {
alert(clientNotification.message);
},
},
}
</script>
10 changes: 10 additions & 0 deletions src/components/pages/NodeRunTraceRoutePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default {
// listen for trace routes
Connection.addTraceRouteListener(this.onTraceRoutePacket);
Connection.addClientNotificationListener(this.onClientNotification);
// redirect to main page if node not found
if(!this.node){
Expand All @@ -105,6 +106,7 @@ export default {
// stop listening for trace routes
Connection.removeTraceRouteListener(this.onTraceRoutePacket);
Connection.removeClientNotificationListener(this.onClientNotification);
},
beforeRouteLeave(to, from) {
Expand Down Expand Up @@ -153,6 +155,14 @@ export default {
},
});
},
onClientNotification(clientNotification) {
// check if meshtastic device rate limited trace route
if(clientNotification.message === "TraceRoute can only be sent once every 30 seconds"){
this.isRunningTraceRoute = false;
}
},
},
computed: {
node() {
Expand Down
31 changes: 27 additions & 4 deletions src/js/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ import {BleConnection, Constants, HttpConnection, Protobuf, SerialConnection, Ty

class Connection {

static clientNotificationListeners = [];
static traceRouteListeners = [];

static addClientNotificationListener(listener) {
this.clientNotificationListeners.push(listener);
}

static removeClientNotificationListener(listenerToRemove) {
this.clientNotificationListeners = this.clientNotificationListeners.filter((listener) => {
return listener !== listenerToRemove;
});
}

static addTraceRouteListener(listener) {
this.traceRouteListeners.push(listener);
}
Expand Down Expand Up @@ -99,8 +110,11 @@ class Connection {
});

// listen for packets from radio
// we are doing this to get error info for a request id as it's not provided in the onRoutingPacket event
// we use this for some packets that don't have their own event listener
connection.events.onFromRadio.subscribe((data) => {

// handle packets
// we are doing this to get error info for a request id as it's not provided in the onRoutingPacket event
if(data.payloadVariant.case.toString() === "packet") {
const meshPacket = data.payloadVariant.value;
if(meshPacket.payloadVariant.case === "decoded"){
Expand All @@ -113,6 +127,17 @@ class Connection {
}
}
}

// handle clientNotification
if(data.payloadVariant.case.toString() === "clientNotification") {
const clientNotification = data.payloadVariant.value;
for(const clientNotificationListener of this.clientNotificationListeners){
try {
clientNotificationListener(clientNotification);
} catch(e){}
}
}

});

// listen for our node number
Expand Down Expand Up @@ -218,9 +243,7 @@ class Connection {
for(const traceRouteListener of this.traceRouteListeners){
try {
traceRouteListener(data);
} catch(e) {
// ignore error calling listener
}
} catch(e){}
}
});

Expand Down

0 comments on commit 4516f4f

Please sign in to comment.