diff --git a/src/components/App.vue b/src/components/App.vue index dd8c2ae..2b86fb1 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -9,7 +9,20 @@ diff --git a/src/components/pages/NodeRunTraceRoutePage.vue b/src/components/pages/NodeRunTraceRoutePage.vue index 31505df..5729ce1 100644 --- a/src/components/pages/NodeRunTraceRoutePage.vue +++ b/src/components/pages/NodeRunTraceRoutePage.vue @@ -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){ @@ -105,6 +106,7 @@ export default { // stop listening for trace routes Connection.removeTraceRouteListener(this.onTraceRoutePacket); + Connection.removeClientNotificationListener(this.onClientNotification); }, beforeRouteLeave(to, from) { @@ -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() { diff --git a/src/js/Connection.js b/src/js/Connection.js index 7ef6df4..14bbdfa 100644 --- a/src/js/Connection.js +++ b/src/js/Connection.js @@ -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); } @@ -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"){ @@ -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 @@ -218,9 +243,7 @@ class Connection { for(const traceRouteListener of this.traceRouteListeners){ try { traceRouteListener(data); - } catch(e) { - // ignore error calling listener - } + } catch(e){} } });