diff --git a/packages/core/src/utils/eventSystem.ts b/packages/core/src/utils/eventSystem.ts index f50ca035..81b24d34 100644 --- a/packages/core/src/utils/eventSystem.ts +++ b/packages/core/src/utils/eventSystem.ts @@ -1,7 +1,7 @@ import type * as Protobuf from "@meshtastic/protobufs"; import { SimpleEventDispatcher } from "ste-simple-events"; -import type { PacketMetadata } from "../types.ts"; import type * as Types from "../types.ts"; +import type { PacketMetadata } from "../types.ts"; export class EventSystem { /** @@ -330,6 +330,15 @@ export class EventSystem { PacketMetadata > = new SimpleEventDispatcher>(); + /** + * Fires when a new MeshPacket message containing a ClientNotification packet has been + * received from device + * + * @event onClientNotificationPacket + */ + public readonly onClientNotificationPacket: SimpleEventDispatcher = + new SimpleEventDispatcher(); + /** * Fires when the devices connection or configuration status changes * diff --git a/packages/core/src/utils/transform/decodePacket.ts b/packages/core/src/utils/transform/decodePacket.ts index 00daf25e..94f0e54d 100644 --- a/packages/core/src/utils/transform/decodePacket.ts +++ b/packages/core/src/utils/transform/decodePacket.ts @@ -1,6 +1,6 @@ import { fromBinary } from "@bufbuild/protobuf"; -import { Constants, Protobuf, Types } from "../../../mod.ts"; import type { MeshDevice } from "../../../mod.ts"; +import { Constants, Protobuf, Types } from "../../../mod.ts"; import type { DeviceOutput } from "../../types.ts"; export const decodePacket = (device: MeshDevice) => @@ -209,6 +209,18 @@ export const decodePacket = (device: MeshDevice) => break; } + case "clientNotification": { + device.log.trace( + Types.Emitter[Types.Emitter.HandleFromRadio], + `📣 Received ClientNotification: ${decodedMessage.payloadVariant.value.message}`, + ); + + device.events.onClientNotificationPacket.dispatch( + decodedMessage.payloadVariant.value, + ); + break; + } + default: { device.log.warn( Types.Emitter[Types.Emitter.HandleFromRadio], diff --git a/packages/web/src/core/subscriptions.ts b/packages/web/src/core/subscriptions.ts index 338512c9..e9725688 100644 --- a/packages/web/src/core/subscriptions.ts +++ b/packages/web/src/core/subscriptions.ts @@ -114,6 +114,12 @@ export const subscribeAll = ( }); }); + connection.events.onClientNotificationPacket.subscribe( + (clientNotificationPacket) => { + console.debug(clientNotificationPacket.message); + }, + ); + connection.events.onRoutingPacket.subscribe((routingPacket) => { if (routingPacket.data.variant.case === "errorReason") { switch (routingPacket.data.variant.value) {