Browse Source

ClientNotification WIP

pull/771/head
philon- 12 months ago
parent
commit
6e51530db2
  1. 11
      packages/core/src/utils/eventSystem.ts
  2. 14
      packages/core/src/utils/transform/decodePacket.ts
  3. 6
      packages/web/src/core/subscriptions.ts

11
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<Uint8Array>
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
/**
* Fires when a new MeshPacket message containing a ClientNotification packet has been
* received from device
*
* @event onClientNotificationPacket
*/
public readonly onClientNotificationPacket: SimpleEventDispatcher<Protobuf.Mesh.ClientNotification> =
new SimpleEventDispatcher<Protobuf.Mesh.ClientNotification>();
/**
* Fires when the devices connection or configuration status changes
*

14
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],

6
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) {

Loading…
Cancel
Save