Fix/add npm jsr building (#722)
* fixed github workflows to improve handling of mutl runtimes * updating readme * Update packages/core/src/meshDevice.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/core/package.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/transport-http/package.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "@meshtastic/core",
|
||||
"version": "2.6.4",
|
||||
"description": "Core functionalities for Meshtastic web applications.",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
},
|
||||
"imports": {
|
||||
"crc": "npm:crc@^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "@meshtastic/core",
|
||||
"version": "2.6.5",
|
||||
"description": "Core functionalities for Meshtastic web applications.",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"crc": "npm:crc@^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,6 @@ const broadcastNum = 0xffffffff;
|
||||
const minFwVer = 2.2;
|
||||
|
||||
export const Constants = {
|
||||
broadcastNum,
|
||||
minFwVer,
|
||||
broadcastNum,
|
||||
minFwVer,
|
||||
};
|
||||
|
||||
+1148
-1148
File diff suppressed because it is too large
Load Diff
+84
-84
@@ -1,45 +1,45 @@
|
||||
import type * as Protobuf from "@meshtastic/protobufs";
|
||||
|
||||
interface Packet {
|
||||
type: "packet";
|
||||
data: Uint8Array;
|
||||
type: "packet";
|
||||
data: Uint8Array;
|
||||
}
|
||||
|
||||
interface DebugLog {
|
||||
type: "debug";
|
||||
data: string;
|
||||
type: "debug";
|
||||
data: string;
|
||||
}
|
||||
|
||||
export type DeviceOutput = Packet | DebugLog;
|
||||
|
||||
export interface Transport {
|
||||
toDevice: WritableStream<Uint8Array>;
|
||||
fromDevice: ReadableStream<DeviceOutput>;
|
||||
toDevice: WritableStream<Uint8Array>;
|
||||
fromDevice: ReadableStream<DeviceOutput>;
|
||||
}
|
||||
|
||||
export interface QueueItem {
|
||||
id: number;
|
||||
data: Uint8Array;
|
||||
sent: boolean;
|
||||
added: Date;
|
||||
promise: Promise<number>;
|
||||
id: number;
|
||||
data: Uint8Array;
|
||||
sent: boolean;
|
||||
added: Date;
|
||||
promise: Promise<number>;
|
||||
}
|
||||
|
||||
export interface HttpRetryConfig {
|
||||
maxRetries: number;
|
||||
initialDelayMs: number;
|
||||
maxDelayMs: number;
|
||||
backoffFactor: number;
|
||||
maxRetries: number;
|
||||
initialDelayMs: number;
|
||||
maxDelayMs: number;
|
||||
backoffFactor: number;
|
||||
}
|
||||
|
||||
export enum DeviceStatusEnum {
|
||||
DeviceRestarting = 1,
|
||||
DeviceDisconnected = 2,
|
||||
DeviceConnecting = 3,
|
||||
DeviceReconnecting = 4,
|
||||
DeviceConnected = 5,
|
||||
DeviceConfiguring = 6,
|
||||
DeviceConfigured = 7,
|
||||
DeviceRestarting = 1,
|
||||
DeviceDisconnected = 2,
|
||||
DeviceConnecting = 3,
|
||||
DeviceReconnecting = 4,
|
||||
DeviceConnected = 5,
|
||||
DeviceConfiguring = 6,
|
||||
DeviceConfigured = 7,
|
||||
}
|
||||
|
||||
export type LogEventPacket = LogEvent & { date: Date };
|
||||
@@ -47,83 +47,83 @@ export type LogEventPacket = LogEvent & { date: Date };
|
||||
export type PacketDestination = "broadcast" | "direct";
|
||||
|
||||
export interface PacketMetadata<T> {
|
||||
id: number;
|
||||
rxTime: Date;
|
||||
type: PacketDestination;
|
||||
from: number;
|
||||
to: number;
|
||||
channel: ChannelNumber;
|
||||
data: T;
|
||||
id: number;
|
||||
rxTime: Date;
|
||||
type: PacketDestination;
|
||||
from: number;
|
||||
to: number;
|
||||
channel: ChannelNumber;
|
||||
data: T;
|
||||
}
|
||||
|
||||
export enum EmitterScope {
|
||||
MeshDevice = 1,
|
||||
SerialConnection = 2,
|
||||
NodeSerialConnection = 3,
|
||||
BleConnection = 4,
|
||||
HttpConnection = 5,
|
||||
MeshDevice = 1,
|
||||
SerialConnection = 2,
|
||||
NodeSerialConnection = 3,
|
||||
BleConnection = 4,
|
||||
HttpConnection = 5,
|
||||
}
|
||||
|
||||
export enum Emitter {
|
||||
Constructor = 0,
|
||||
SendText = 1,
|
||||
SendWaypoint = 2,
|
||||
SendPacket = 3,
|
||||
SendRaw = 4,
|
||||
SetConfig = 5,
|
||||
SetModuleConfig = 6,
|
||||
ConfirmSetConfig = 7,
|
||||
SetOwner = 8,
|
||||
SetChannel = 9,
|
||||
ConfirmSetChannel = 10,
|
||||
ClearChannel = 11,
|
||||
GetChannel = 12,
|
||||
GetAllChannels = 13,
|
||||
GetConfig = 14,
|
||||
GetModuleConfig = 15,
|
||||
GetOwner = 16,
|
||||
Configure = 17,
|
||||
HandleFromRadio = 18,
|
||||
HandleMeshPacket = 19,
|
||||
Connect = 20,
|
||||
Ping = 21,
|
||||
ReadFromRadio = 22,
|
||||
WriteToRadio = 23,
|
||||
SetDebugMode = 24,
|
||||
GetMetadata = 25,
|
||||
ResetNodes = 26,
|
||||
Shutdown = 27,
|
||||
Reboot = 28,
|
||||
RebootOta = 29,
|
||||
FactoryReset = 30,
|
||||
EnterDfuMode = 31,
|
||||
RemoveNodeByNum = 32,
|
||||
SetCannedMessages = 33,
|
||||
Disconnect = 34,
|
||||
Constructor = 0,
|
||||
SendText = 1,
|
||||
SendWaypoint = 2,
|
||||
SendPacket = 3,
|
||||
SendRaw = 4,
|
||||
SetConfig = 5,
|
||||
SetModuleConfig = 6,
|
||||
ConfirmSetConfig = 7,
|
||||
SetOwner = 8,
|
||||
SetChannel = 9,
|
||||
ConfirmSetChannel = 10,
|
||||
ClearChannel = 11,
|
||||
GetChannel = 12,
|
||||
GetAllChannels = 13,
|
||||
GetConfig = 14,
|
||||
GetModuleConfig = 15,
|
||||
GetOwner = 16,
|
||||
Configure = 17,
|
||||
HandleFromRadio = 18,
|
||||
HandleMeshPacket = 19,
|
||||
Connect = 20,
|
||||
Ping = 21,
|
||||
ReadFromRadio = 22,
|
||||
WriteToRadio = 23,
|
||||
SetDebugMode = 24,
|
||||
GetMetadata = 25,
|
||||
ResetNodes = 26,
|
||||
Shutdown = 27,
|
||||
Reboot = 28,
|
||||
RebootOta = 29,
|
||||
FactoryReset = 30,
|
||||
EnterDfuMode = 31,
|
||||
RemoveNodeByNum = 32,
|
||||
SetCannedMessages = 33,
|
||||
Disconnect = 34,
|
||||
}
|
||||
|
||||
export interface LogEvent {
|
||||
scope: EmitterScope;
|
||||
emitter: Emitter;
|
||||
message: string;
|
||||
level: Protobuf.Mesh.LogRecord_Level;
|
||||
packet?: Uint8Array;
|
||||
scope: EmitterScope;
|
||||
emitter: Emitter;
|
||||
message: string;
|
||||
level: Protobuf.Mesh.LogRecord_Level;
|
||||
packet?: Uint8Array;
|
||||
}
|
||||
|
||||
export enum ChannelNumber {
|
||||
Primary = 0,
|
||||
Channel1 = 1,
|
||||
Channel2 = 2,
|
||||
Channel3 = 3,
|
||||
Channel4 = 4,
|
||||
Channel5 = 5,
|
||||
Channel6 = 6,
|
||||
Admin = 7,
|
||||
Primary = 0,
|
||||
Channel1 = 1,
|
||||
Channel2 = 2,
|
||||
Channel3 = 3,
|
||||
Channel4 = 4,
|
||||
Channel5 = 5,
|
||||
Channel6 = 6,
|
||||
Admin = 7,
|
||||
}
|
||||
|
||||
export type Destination = number | "self" | "broadcast";
|
||||
|
||||
export interface PacketError {
|
||||
id: number;
|
||||
error: Protobuf.Mesh.Routing_Error;
|
||||
id: number;
|
||||
error: Protobuf.Mesh.Routing_Error;
|
||||
}
|
||||
|
||||
@@ -4,378 +4,378 @@ import type { PacketMetadata } from "../types.ts";
|
||||
import type * as Types from "../types.ts";
|
||||
|
||||
export class EventSystem {
|
||||
/**
|
||||
* Fires when a new FromRadio message has been received from the device
|
||||
*
|
||||
* @event onLogEvent
|
||||
*/
|
||||
public readonly onLogEvent: SimpleEventDispatcher<Types.LogEventPacket> =
|
||||
new SimpleEventDispatcher<Types.LogEventPacket>();
|
||||
/**
|
||||
* Fires when a new FromRadio message has been received from the device
|
||||
*
|
||||
* @event onLogEvent
|
||||
*/
|
||||
public readonly onLogEvent: SimpleEventDispatcher<Types.LogEventPacket> =
|
||||
new SimpleEventDispatcher<Types.LogEventPacket>();
|
||||
|
||||
/**
|
||||
* Fires when a new FromRadio message has been received from the device
|
||||
*
|
||||
* @event onFromRadio
|
||||
*/
|
||||
public readonly onFromRadio: SimpleEventDispatcher<Protobuf.Mesh.FromRadio> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.FromRadio>();
|
||||
/**
|
||||
* Fires when a new FromRadio message has been received from the device
|
||||
*
|
||||
* @event onFromRadio
|
||||
*/
|
||||
public readonly onFromRadio: SimpleEventDispatcher<Protobuf.Mesh.FromRadio> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.FromRadio>();
|
||||
|
||||
/**
|
||||
* Fires when a new FromRadio message containing a Data packet has been
|
||||
* received from the device
|
||||
*
|
||||
* @event onMeshPacket
|
||||
*/
|
||||
public readonly onMeshPacket: SimpleEventDispatcher<Protobuf.Mesh.MeshPacket> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.MeshPacket>();
|
||||
/**
|
||||
* Fires when a new FromRadio message containing a Data packet has been
|
||||
* received from the device
|
||||
*
|
||||
* @event onMeshPacket
|
||||
*/
|
||||
public readonly onMeshPacket: SimpleEventDispatcher<Protobuf.Mesh.MeshPacket> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.MeshPacket>();
|
||||
|
||||
/**
|
||||
* Fires when a new MyNodeInfo message has been received from the device
|
||||
*
|
||||
* @event onMyNodeInfo
|
||||
*/
|
||||
public readonly onMyNodeInfo: SimpleEventDispatcher<Protobuf.Mesh.MyNodeInfo> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.MyNodeInfo>();
|
||||
/**
|
||||
* Fires when a new MyNodeInfo message has been received from the device
|
||||
*
|
||||
* @event onMyNodeInfo
|
||||
*/
|
||||
public readonly onMyNodeInfo: SimpleEventDispatcher<Protobuf.Mesh.MyNodeInfo> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.MyNodeInfo>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a NodeInfo packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onNodeInfoPacket
|
||||
*/
|
||||
public readonly onNodeInfoPacket: SimpleEventDispatcher<Protobuf.Mesh.NodeInfo> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.NodeInfo>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a NodeInfo packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onNodeInfoPacket
|
||||
*/
|
||||
public readonly onNodeInfoPacket: SimpleEventDispatcher<Protobuf.Mesh.NodeInfo> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.NodeInfo>();
|
||||
|
||||
/**
|
||||
* Fires when a new Channel message is received
|
||||
*
|
||||
* @event onChannelPacket
|
||||
*/
|
||||
public readonly onChannelPacket: SimpleEventDispatcher<Protobuf.Channel.Channel> =
|
||||
new SimpleEventDispatcher<Protobuf.Channel.Channel>();
|
||||
/**
|
||||
* Fires when a new Channel message is received
|
||||
*
|
||||
* @event onChannelPacket
|
||||
*/
|
||||
public readonly onChannelPacket: SimpleEventDispatcher<Protobuf.Channel.Channel> =
|
||||
new SimpleEventDispatcher<Protobuf.Channel.Channel>();
|
||||
|
||||
/**
|
||||
* Fires when a new Config message is received
|
||||
*
|
||||
* @event onConfigPacket
|
||||
*/
|
||||
public readonly onConfigPacket: SimpleEventDispatcher<Protobuf.Config.Config> =
|
||||
new SimpleEventDispatcher<Protobuf.Config.Config>();
|
||||
/**
|
||||
* Fires when a new Config message is received
|
||||
*
|
||||
* @event onConfigPacket
|
||||
*/
|
||||
public readonly onConfigPacket: SimpleEventDispatcher<Protobuf.Config.Config> =
|
||||
new SimpleEventDispatcher<Protobuf.Config.Config>();
|
||||
|
||||
/**
|
||||
* Fires when a new ModuleConfig message is received
|
||||
*
|
||||
* @event onModuleConfigPacket
|
||||
*/
|
||||
public readonly onModuleConfigPacket: SimpleEventDispatcher<Protobuf.ModuleConfig.ModuleConfig> =
|
||||
new SimpleEventDispatcher<Protobuf.ModuleConfig.ModuleConfig>();
|
||||
/**
|
||||
* Fires when a new ModuleConfig message is received
|
||||
*
|
||||
* @event onModuleConfigPacket
|
||||
*/
|
||||
public readonly onModuleConfigPacket: SimpleEventDispatcher<Protobuf.ModuleConfig.ModuleConfig> =
|
||||
new SimpleEventDispatcher<Protobuf.ModuleConfig.ModuleConfig>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a ATAK packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onAtakPacket
|
||||
*/
|
||||
public readonly onAtakPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a ATAK packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onAtakPacket
|
||||
*/
|
||||
public readonly onAtakPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Text packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onMessagePacket
|
||||
*/
|
||||
public readonly onMessagePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<string>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<string>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Text packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onMessagePacket
|
||||
*/
|
||||
public readonly onMessagePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<string>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<string>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Remote Hardware packet has
|
||||
* been received from device
|
||||
*
|
||||
* @event onRemoteHardwarePacket
|
||||
*/
|
||||
public readonly onRemoteHardwarePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.RemoteHardware.HardwareMessage>
|
||||
> = new SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.RemoteHardware.HardwareMessage>
|
||||
>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Remote Hardware packet has
|
||||
* been received from device
|
||||
*
|
||||
* @event onRemoteHardwarePacket
|
||||
*/
|
||||
public readonly onRemoteHardwarePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.RemoteHardware.HardwareMessage>
|
||||
> = new SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.RemoteHardware.HardwareMessage>
|
||||
>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Position packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onPositionPacket
|
||||
*/
|
||||
public readonly onPositionPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.Position>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.Position>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Position packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onPositionPacket
|
||||
*/
|
||||
public readonly onPositionPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.Position>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.Position>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a User packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onUserPacket
|
||||
*/
|
||||
public readonly onUserPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.User>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.User>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a User packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onUserPacket
|
||||
*/
|
||||
public readonly onUserPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.User>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.User>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Routing packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onRoutingPacket
|
||||
*/
|
||||
public readonly onRoutingPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.Routing>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.Routing>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Routing packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onRoutingPacket
|
||||
*/
|
||||
public readonly onRoutingPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.Routing>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.Routing>>();
|
||||
|
||||
/**
|
||||
* Fires when the device receives a Metadata packet
|
||||
*
|
||||
* @event onDeviceMetadataPacket
|
||||
*/
|
||||
public readonly onDeviceMetadataPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.DeviceMetadata>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.DeviceMetadata>>();
|
||||
/**
|
||||
* Fires when the device receives a Metadata packet
|
||||
*
|
||||
* @event onDeviceMetadataPacket
|
||||
*/
|
||||
public readonly onDeviceMetadataPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.DeviceMetadata>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.DeviceMetadata>>();
|
||||
|
||||
/**
|
||||
* Fires when the device receives a Canned Message Module message packet
|
||||
*
|
||||
* @event onCannedMessageModulePacket
|
||||
*/
|
||||
public readonly onCannedMessageModulePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<string>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<string>>();
|
||||
/**
|
||||
* Fires when the device receives a Canned Message Module message packet
|
||||
*
|
||||
* @event onCannedMessageModulePacket
|
||||
*/
|
||||
public readonly onCannedMessageModulePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<string>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<string>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Waypoint packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onWaypointPacket
|
||||
*/
|
||||
public readonly onWaypointPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.Waypoint>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.Waypoint>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Waypoint packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onWaypointPacket
|
||||
*/
|
||||
public readonly onWaypointPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.Waypoint>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.Waypoint>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing an Audio packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onAudioPacket
|
||||
*/
|
||||
public readonly onAudioPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing an Audio packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onAudioPacket
|
||||
*/
|
||||
public readonly onAudioPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Detection Sensor packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onDetectionSensorPacket
|
||||
*/
|
||||
public readonly onDetectionSensorPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Detection Sensor packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onDetectionSensorPacket
|
||||
*/
|
||||
public readonly onDetectionSensorPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Ping packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onPingPacket
|
||||
*/
|
||||
public readonly onPingPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Ping packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onPingPacket
|
||||
*/
|
||||
public readonly onPingPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a IP Tunnel packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onIpTunnelPacket
|
||||
*/
|
||||
public readonly onIpTunnelPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a IP Tunnel packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onIpTunnelPacket
|
||||
*/
|
||||
public readonly onIpTunnelPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Paxcounter packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onPaxcounterPacket
|
||||
*/
|
||||
public readonly onPaxcounterPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.PaxCount.Paxcount>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.PaxCount.Paxcount>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Paxcounter packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onPaxcounterPacket
|
||||
*/
|
||||
public readonly onPaxcounterPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.PaxCount.Paxcount>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.PaxCount.Paxcount>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Serial packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onSerialPacket
|
||||
*/
|
||||
public readonly onSerialPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Serial packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onSerialPacket
|
||||
*/
|
||||
public readonly onSerialPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Store and Forward packet
|
||||
* has been received from device
|
||||
*
|
||||
* @event onStoreForwardPacket
|
||||
*/
|
||||
public readonly onStoreForwardPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Store and Forward packet
|
||||
* has been received from device
|
||||
*
|
||||
* @event onStoreForwardPacket
|
||||
*/
|
||||
public readonly onStoreForwardPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Store and Forward packet
|
||||
* has been received from device
|
||||
*
|
||||
* @event onRangeTestPacket
|
||||
*/
|
||||
public readonly onRangeTestPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Store and Forward packet
|
||||
* has been received from device
|
||||
*
|
||||
* @event onRangeTestPacket
|
||||
*/
|
||||
public readonly onRangeTestPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Telemetry packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onTelemetryPacket
|
||||
*/
|
||||
public readonly onTelemetryPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Telemetry.Telemetry>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Telemetry.Telemetry>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Telemetry packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onTelemetryPacket
|
||||
*/
|
||||
public readonly onTelemetryPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Telemetry.Telemetry>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Telemetry.Telemetry>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a ZPS packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onZPSPacket
|
||||
*/
|
||||
public readonly onZpsPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a ZPS packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onZPSPacket
|
||||
*/
|
||||
public readonly onZpsPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Simulator packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onSimulatorPacket
|
||||
*/
|
||||
public readonly onSimulatorPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Simulator packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onSimulatorPacket
|
||||
*/
|
||||
public readonly onSimulatorPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Trace Route packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onTraceRoutePacket
|
||||
*/
|
||||
public readonly onTraceRoutePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.RouteDiscovery>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.RouteDiscovery>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Trace Route packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onTraceRoutePacket
|
||||
*/
|
||||
public readonly onTraceRoutePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.RouteDiscovery>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.RouteDiscovery>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Neighbor Info packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onNeighborInfoPacket
|
||||
*/
|
||||
public readonly onNeighborInfoPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.NeighborInfo>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.NeighborInfo>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Neighbor Info packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onNeighborInfoPacket
|
||||
*/
|
||||
public readonly onNeighborInfoPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Protobuf.Mesh.NeighborInfo>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Protobuf.Mesh.NeighborInfo>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing an ATAK packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onAtakPluginPacket
|
||||
*/
|
||||
public readonly onAtakPluginPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing an ATAK packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onAtakPluginPacket
|
||||
*/
|
||||
public readonly onAtakPluginPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Map Report packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onMapReportPacket
|
||||
*/
|
||||
public readonly onMapReportPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Map Report packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onMapReportPacket
|
||||
*/
|
||||
public readonly onMapReportPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Private packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onPrivatePacket
|
||||
*/
|
||||
public readonly onPrivatePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing a Private packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onPrivatePacket
|
||||
*/
|
||||
public readonly onPrivatePacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing an ATAK Forwarder packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onAtakForwarderPacket
|
||||
*/
|
||||
public readonly onAtakForwarderPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
/**
|
||||
* Fires when a new MeshPacket message containing an ATAK Forwarder packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onAtakForwarderPacket
|
||||
*/
|
||||
public readonly onAtakForwarderPacket: SimpleEventDispatcher<
|
||||
PacketMetadata<Uint8Array>
|
||||
> = new SimpleEventDispatcher<PacketMetadata<Uint8Array>>();
|
||||
|
||||
/**
|
||||
* Fires when the devices connection or configuration status changes
|
||||
*
|
||||
* @event onDeviceStatus
|
||||
*/
|
||||
public readonly onDeviceStatus: SimpleEventDispatcher<Types.DeviceStatusEnum> =
|
||||
new SimpleEventDispatcher<Types.DeviceStatusEnum>();
|
||||
/**
|
||||
* Fires when the devices connection or configuration status changes
|
||||
*
|
||||
* @event onDeviceStatus
|
||||
*/
|
||||
public readonly onDeviceStatus: SimpleEventDispatcher<Types.DeviceStatusEnum> =
|
||||
new SimpleEventDispatcher<Types.DeviceStatusEnum>();
|
||||
|
||||
/**
|
||||
* Fires when a new FromRadio message containing a LogRecord packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onLogRecord
|
||||
*/
|
||||
public readonly onLogRecord: SimpleEventDispatcher<Protobuf.Mesh.LogRecord> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.LogRecord>();
|
||||
/**
|
||||
* Fires when a new FromRadio message containing a LogRecord packet has been
|
||||
* received from device
|
||||
*
|
||||
* @event onLogRecord
|
||||
*/
|
||||
public readonly onLogRecord: SimpleEventDispatcher<Protobuf.Mesh.LogRecord> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.LogRecord>();
|
||||
|
||||
/**
|
||||
* Fires when the device receives a meshPacket, returns a timestamp
|
||||
*
|
||||
* @event onMeshHeartbeat
|
||||
*/
|
||||
public readonly onMeshHeartbeat: SimpleEventDispatcher<Date> =
|
||||
new SimpleEventDispatcher<Date>();
|
||||
/**
|
||||
* Fires when the device receives a meshPacket, returns a timestamp
|
||||
*
|
||||
* @event onMeshHeartbeat
|
||||
*/
|
||||
public readonly onMeshHeartbeat: SimpleEventDispatcher<Date> =
|
||||
new SimpleEventDispatcher<Date>();
|
||||
|
||||
/**
|
||||
* Outputs any debug log data (currently serial connections only)
|
||||
*
|
||||
* @event onDeviceDebugLog
|
||||
*/
|
||||
public readonly onDeviceDebugLog: SimpleEventDispatcher<Uint8Array> =
|
||||
new SimpleEventDispatcher<Uint8Array>();
|
||||
/**
|
||||
* Outputs any debug log data (currently serial connections only)
|
||||
*
|
||||
* @event onDeviceDebugLog
|
||||
*/
|
||||
public readonly onDeviceDebugLog: SimpleEventDispatcher<Uint8Array> =
|
||||
new SimpleEventDispatcher<Uint8Array>();
|
||||
|
||||
/**
|
||||
* Outputs status of pending settings changes
|
||||
*
|
||||
* @event onpendingSettingsChange
|
||||
*/
|
||||
public readonly onPendingSettingsChange: SimpleEventDispatcher<boolean> =
|
||||
new SimpleEventDispatcher<boolean>();
|
||||
/**
|
||||
* Outputs status of pending settings changes
|
||||
*
|
||||
* @event onpendingSettingsChange
|
||||
*/
|
||||
public readonly onPendingSettingsChange: SimpleEventDispatcher<boolean> =
|
||||
new SimpleEventDispatcher<boolean>();
|
||||
|
||||
/**
|
||||
* Fires when a QueueStatus message is generated
|
||||
*
|
||||
* @event onQueueStatus
|
||||
*/
|
||||
public readonly onQueueStatus: SimpleEventDispatcher<Protobuf.Mesh.QueueStatus> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.QueueStatus>();
|
||||
/**
|
||||
* Fires when a QueueStatus message is generated
|
||||
*
|
||||
* @event onQueueStatus
|
||||
*/
|
||||
public readonly onQueueStatus: SimpleEventDispatcher<Protobuf.Mesh.QueueStatus> =
|
||||
new SimpleEventDispatcher<Protobuf.Mesh.QueueStatus>();
|
||||
}
|
||||
|
||||
+100
-100
@@ -4,116 +4,116 @@ import { SimpleEventDispatcher } from "ste-simple-events";
|
||||
import type { PacketError, QueueItem } from "../types.ts";
|
||||
|
||||
export class Queue {
|
||||
private queue: QueueItem[] = [];
|
||||
private lock = false;
|
||||
private ackNotifier = new SimpleEventDispatcher<number>();
|
||||
private errorNotifier = new SimpleEventDispatcher<PacketError>();
|
||||
private timeout: number;
|
||||
private queue: QueueItem[] = [];
|
||||
private lock = false;
|
||||
private ackNotifier = new SimpleEventDispatcher<number>();
|
||||
private errorNotifier = new SimpleEventDispatcher<PacketError>();
|
||||
private timeout: number;
|
||||
|
||||
constructor() {
|
||||
this.timeout = 60000;
|
||||
}
|
||||
constructor() {
|
||||
this.timeout = 60000;
|
||||
}
|
||||
|
||||
public getState(): QueueItem[] {
|
||||
return this.queue;
|
||||
}
|
||||
public getState(): QueueItem[] {
|
||||
return this.queue;
|
||||
}
|
||||
|
||||
public clear(): void {
|
||||
this.queue = [];
|
||||
}
|
||||
public clear(): void {
|
||||
this.queue = [];
|
||||
}
|
||||
|
||||
public push(item: Omit<QueueItem, "promise" | "sent" | "added">): void {
|
||||
const queueItem: QueueItem = {
|
||||
...item,
|
||||
sent: false,
|
||||
added: new Date(),
|
||||
promise: new Promise<number>((resolve, reject) => {
|
||||
this.ackNotifier.subscribe((id) => {
|
||||
if (item.id === id) {
|
||||
this.remove(item.id);
|
||||
resolve(id);
|
||||
}
|
||||
});
|
||||
this.errorNotifier.subscribe((e) => {
|
||||
if (item.id === e.id) {
|
||||
this.remove(item.id);
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
if (this.queue.findIndex((qi) => qi.id === item.id) !== -1) {
|
||||
this.remove(item.id);
|
||||
const decoded = fromBinary(Protobuf.Mesh.ToRadioSchema, item.data);
|
||||
console.warn(
|
||||
`Packet ${item.id} of type ${decoded.payloadVariant.case} timed out`,
|
||||
);
|
||||
public push(item: Omit<QueueItem, "promise" | "sent" | "added">): void {
|
||||
const queueItem: QueueItem = {
|
||||
...item,
|
||||
sent: false,
|
||||
added: new Date(),
|
||||
promise: new Promise<number>((resolve, reject) => {
|
||||
this.ackNotifier.subscribe((id) => {
|
||||
if (item.id === id) {
|
||||
this.remove(item.id);
|
||||
resolve(id);
|
||||
}
|
||||
});
|
||||
this.errorNotifier.subscribe((e) => {
|
||||
if (item.id === e.id) {
|
||||
this.remove(item.id);
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
if (this.queue.findIndex((qi) => qi.id === item.id) !== -1) {
|
||||
this.remove(item.id);
|
||||
const decoded = fromBinary(Protobuf.Mesh.ToRadioSchema, item.data);
|
||||
console.warn(
|
||||
`Packet ${item.id} of type ${decoded.payloadVariant.case} timed out`,
|
||||
);
|
||||
|
||||
reject({
|
||||
id: item.id,
|
||||
error: Protobuf.Mesh.Routing_Error.TIMEOUT,
|
||||
});
|
||||
}
|
||||
}, this.timeout);
|
||||
}),
|
||||
};
|
||||
this.queue.push(queueItem);
|
||||
}
|
||||
reject({
|
||||
id: item.id,
|
||||
error: Protobuf.Mesh.Routing_Error.TIMEOUT,
|
||||
});
|
||||
}
|
||||
}, this.timeout);
|
||||
}),
|
||||
};
|
||||
this.queue.push(queueItem);
|
||||
}
|
||||
|
||||
public remove(id: number): void {
|
||||
if (this.lock) {
|
||||
setTimeout(() => this.remove(id), 100);
|
||||
return;
|
||||
}
|
||||
this.queue = this.queue.filter((item) => item.id !== id);
|
||||
}
|
||||
public remove(id: number): void {
|
||||
if (this.lock) {
|
||||
setTimeout(() => this.remove(id), 100);
|
||||
return;
|
||||
}
|
||||
this.queue = this.queue.filter((item) => item.id !== id);
|
||||
}
|
||||
|
||||
public processAck(id: number): void {
|
||||
this.ackNotifier.dispatch(id);
|
||||
}
|
||||
public processAck(id: number): void {
|
||||
this.ackNotifier.dispatch(id);
|
||||
}
|
||||
|
||||
public processError(e: PacketError): void {
|
||||
console.error(
|
||||
`Error received for packet ${e.id}: ${
|
||||
Protobuf.Mesh.Routing_Error[e.error]
|
||||
}`,
|
||||
);
|
||||
this.errorNotifier.dispatch(e);
|
||||
}
|
||||
public processError(e: PacketError): void {
|
||||
console.error(
|
||||
`Error received for packet ${e.id}: ${
|
||||
Protobuf.Mesh.Routing_Error[e.error]
|
||||
}`,
|
||||
);
|
||||
this.errorNotifier.dispatch(e);
|
||||
}
|
||||
|
||||
public wait(id: number): Promise<number> {
|
||||
const queueItem = this.queue.find((qi) => qi.id === id);
|
||||
if (!queueItem) {
|
||||
throw new Error("Packet does not exist");
|
||||
}
|
||||
return queueItem.promise;
|
||||
}
|
||||
public wait(id: number): Promise<number> {
|
||||
const queueItem = this.queue.find((qi) => qi.id === id);
|
||||
if (!queueItem) {
|
||||
throw new Error("Packet does not exist");
|
||||
}
|
||||
return queueItem.promise;
|
||||
}
|
||||
|
||||
public async processQueue(
|
||||
outputStream: WritableStream<Uint8Array>,
|
||||
): Promise<void> {
|
||||
if (this.lock) {
|
||||
return;
|
||||
}
|
||||
public async processQueue(
|
||||
outputStream: WritableStream<Uint8Array>,
|
||||
): Promise<void> {
|
||||
if (this.lock) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.lock = true;
|
||||
const writer = outputStream.getWriter();
|
||||
this.lock = true;
|
||||
const writer = outputStream.getWriter();
|
||||
|
||||
try {
|
||||
while (this.queue.filter((p) => !p.sent).length > 0) {
|
||||
const item = this.queue.filter((p) => !p.sent)[0];
|
||||
if (item) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
try {
|
||||
await writer.write(item.data);
|
||||
item.sent = true;
|
||||
} catch (error) {
|
||||
console.error(`Error sending packet ${item.id}`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
writer.releaseLock();
|
||||
this.lock = false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
while (this.queue.filter((p) => !p.sent).length > 0) {
|
||||
const item = this.queue.filter((p) => !p.sent)[0];
|
||||
if (item) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
try {
|
||||
await writer.write(item.data);
|
||||
item.sent = true;
|
||||
} catch (error) {
|
||||
console.error(`Error sending packet ${item.id}`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
writer.releaseLock();
|
||||
this.lock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,219 +4,219 @@ import type { MeshDevice } from "../../../mod.ts";
|
||||
import type { DeviceOutput } from "../../types.ts";
|
||||
|
||||
export const decodePacket = (device: MeshDevice) =>
|
||||
new WritableStream<DeviceOutput>({
|
||||
write(chunk) {
|
||||
switch (chunk.type) {
|
||||
case "debug": {
|
||||
break;
|
||||
}
|
||||
case "packet": {
|
||||
const decodedMessage = fromBinary(
|
||||
Protobuf.Mesh.FromRadioSchema,
|
||||
chunk.data,
|
||||
);
|
||||
device.events.onFromRadio.dispatch(decodedMessage);
|
||||
new WritableStream<DeviceOutput>({
|
||||
write(chunk) {
|
||||
switch (chunk.type) {
|
||||
case "debug": {
|
||||
break;
|
||||
}
|
||||
case "packet": {
|
||||
const decodedMessage = fromBinary(
|
||||
Protobuf.Mesh.FromRadioSchema,
|
||||
chunk.data,
|
||||
);
|
||||
device.events.onFromRadio.dispatch(decodedMessage);
|
||||
|
||||
/** @todo Add map here when `all=true` gets fixed. */
|
||||
switch (decodedMessage.payloadVariant.case) {
|
||||
case "packet": {
|
||||
device.handleMeshPacket(decodedMessage.payloadVariant.value);
|
||||
break;
|
||||
}
|
||||
/** @todo Add map here when `all=true` gets fixed. */
|
||||
switch (decodedMessage.payloadVariant.case) {
|
||||
case "packet": {
|
||||
device.handleMeshPacket(decodedMessage.payloadVariant.value);
|
||||
break;
|
||||
}
|
||||
|
||||
case "myInfo": {
|
||||
device.events.onMyNodeInfo.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
device.log.info(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
"📱 Received Node info for this device",
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "myInfo": {
|
||||
device.events.onMyNodeInfo.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
device.log.info(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
"📱 Received Node info for this device",
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "nodeInfo": {
|
||||
device.log.info(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`📱 Received Node Info packet for node: ${decodedMessage.payloadVariant.value.num}`,
|
||||
);
|
||||
case "nodeInfo": {
|
||||
device.log.info(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`📱 Received Node Info packet for node: ${decodedMessage.payloadVariant.value.num}`,
|
||||
);
|
||||
|
||||
device.events.onNodeInfoPacket.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
device.events.onNodeInfoPacket.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
|
||||
//TODO: HERE
|
||||
if (decodedMessage.payloadVariant.value.position) {
|
||||
device.events.onPositionPacket.dispatch({
|
||||
id: decodedMessage.id,
|
||||
rxTime: new Date(),
|
||||
from: decodedMessage.payloadVariant.value.num,
|
||||
to: decodedMessage.payloadVariant.value.num,
|
||||
type: "direct",
|
||||
channel: Types.ChannelNumber.Primary,
|
||||
data: decodedMessage.payloadVariant.value.position,
|
||||
});
|
||||
}
|
||||
//TODO: HERE
|
||||
if (decodedMessage.payloadVariant.value.position) {
|
||||
device.events.onPositionPacket.dispatch({
|
||||
id: decodedMessage.id,
|
||||
rxTime: new Date(),
|
||||
from: decodedMessage.payloadVariant.value.num,
|
||||
to: decodedMessage.payloadVariant.value.num,
|
||||
type: "direct",
|
||||
channel: Types.ChannelNumber.Primary,
|
||||
data: decodedMessage.payloadVariant.value.position,
|
||||
});
|
||||
}
|
||||
|
||||
//TODO: HERE
|
||||
if (decodedMessage.payloadVariant.value.user) {
|
||||
device.events.onUserPacket.dispatch({
|
||||
id: decodedMessage.id,
|
||||
rxTime: new Date(),
|
||||
from: decodedMessage.payloadVariant.value.num,
|
||||
to: decodedMessage.payloadVariant.value.num,
|
||||
type: "direct",
|
||||
channel: Types.ChannelNumber.Primary,
|
||||
data: decodedMessage.payloadVariant.value.user,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
//TODO: HERE
|
||||
if (decodedMessage.payloadVariant.value.user) {
|
||||
device.events.onUserPacket.dispatch({
|
||||
id: decodedMessage.id,
|
||||
rxTime: new Date(),
|
||||
from: decodedMessage.payloadVariant.value.num,
|
||||
to: decodedMessage.payloadVariant.value.num,
|
||||
type: "direct",
|
||||
channel: Types.ChannelNumber.Primary,
|
||||
data: decodedMessage.payloadVariant.value.user,
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case "config": {
|
||||
if (decodedMessage.payloadVariant.value.payloadVariant.case) {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`💾 Received Config packet of variant: ${decodedMessage.payloadVariant.value.payloadVariant.case}`,
|
||||
);
|
||||
} else {
|
||||
device.log.warn(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`⚠️ Received Config packet of variant: ${"UNK"}`,
|
||||
);
|
||||
}
|
||||
case "config": {
|
||||
if (decodedMessage.payloadVariant.value.payloadVariant.case) {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`💾 Received Config packet of variant: ${decodedMessage.payloadVariant.value.payloadVariant.case}`,
|
||||
);
|
||||
} else {
|
||||
device.log.warn(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`⚠️ Received Config packet of variant: ${"UNK"}`,
|
||||
);
|
||||
}
|
||||
|
||||
device.events.onConfigPacket.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
device.events.onConfigPacket.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "logRecord": {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
"Received onLogRecord",
|
||||
);
|
||||
device.events.onLogRecord.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "logRecord": {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
"Received onLogRecord",
|
||||
);
|
||||
device.events.onLogRecord.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "configCompleteId": {
|
||||
if (decodedMessage.payloadVariant.value !== device.configId) {
|
||||
device.log.error(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`❌ Invalid config id received from device, expected ${device.configId} but received ${decodedMessage.payloadVariant.value}`,
|
||||
);
|
||||
}
|
||||
case "configCompleteId": {
|
||||
if (decodedMessage.payloadVariant.value !== device.configId) {
|
||||
device.log.error(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`❌ Invalid config id received from device, expected ${device.configId} but received ${decodedMessage.payloadVariant.value}`,
|
||||
);
|
||||
}
|
||||
|
||||
device.log.info(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`⚙️ Valid config id received from device: ${device.configId}`,
|
||||
);
|
||||
device.log.info(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`⚙️ Valid config id received from device: ${device.configId}`,
|
||||
);
|
||||
|
||||
device.updateDeviceStatus(
|
||||
Types.DeviceStatusEnum.DeviceConfigured,
|
||||
);
|
||||
break;
|
||||
}
|
||||
device.updateDeviceStatus(
|
||||
Types.DeviceStatusEnum.DeviceConfigured,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "rebooted": {
|
||||
device.configure().catch(() => {
|
||||
// TODO: FIX, workaround for `wantConfigId` not getting acks.
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "rebooted": {
|
||||
device.configure().catch(() => {
|
||||
// TODO: FIX, workaround for `wantConfigId` not getting acks.
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "moduleConfig": {
|
||||
if (decodedMessage.payloadVariant.value.payloadVariant.case) {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`💾 Received Module Config packet of variant: ${decodedMessage.payloadVariant.value.payloadVariant.case}`,
|
||||
);
|
||||
} else {
|
||||
device.log.warn(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
"⚠️ Received Module Config packet of variant: UNK",
|
||||
);
|
||||
}
|
||||
case "moduleConfig": {
|
||||
if (decodedMessage.payloadVariant.value.payloadVariant.case) {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`💾 Received Module Config packet of variant: ${decodedMessage.payloadVariant.value.payloadVariant.case}`,
|
||||
);
|
||||
} else {
|
||||
device.log.warn(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
"⚠️ Received Module Config packet of variant: UNK",
|
||||
);
|
||||
}
|
||||
|
||||
device.events.onModuleConfigPacket.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
device.events.onModuleConfigPacket.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "channel": {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`🔐 Received Channel: ${decodedMessage.payloadVariant.value.index}`,
|
||||
);
|
||||
case "channel": {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`🔐 Received Channel: ${decodedMessage.payloadVariant.value.index}`,
|
||||
);
|
||||
|
||||
device.events.onChannelPacket.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
device.events.onChannelPacket.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "queueStatus": {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`🚧 Received Queue Status: ${decodedMessage.payloadVariant.value}`,
|
||||
);
|
||||
case "queueStatus": {
|
||||
device.log.trace(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`🚧 Received Queue Status: ${decodedMessage.payloadVariant.value}`,
|
||||
);
|
||||
|
||||
device.events.onQueueStatus.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
device.events.onQueueStatus.dispatch(
|
||||
decodedMessage.payloadVariant.value,
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
case "xmodemPacket": {
|
||||
device.xModem.handlePacket(decodedMessage.payloadVariant.value);
|
||||
break;
|
||||
}
|
||||
case "xmodemPacket": {
|
||||
device.xModem.handlePacket(decodedMessage.payloadVariant.value);
|
||||
break;
|
||||
}
|
||||
|
||||
case "metadata": {
|
||||
if (
|
||||
Number.parseFloat(
|
||||
decodedMessage.payloadVariant.value.firmwareVersion,
|
||||
) < Constants.minFwVer
|
||||
) {
|
||||
device.log.fatal(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`Device firmware outdated. Min supported: ${Constants.minFwVer} got : ${decodedMessage.payloadVariant.value.firmwareVersion}`,
|
||||
);
|
||||
}
|
||||
device.log.debug(
|
||||
Types.Emitter[Types.Emitter.GetMetadata],
|
||||
"🏷️ Received metadata packet",
|
||||
);
|
||||
case "metadata": {
|
||||
if (
|
||||
Number.parseFloat(
|
||||
decodedMessage.payloadVariant.value.firmwareVersion,
|
||||
) < Constants.minFwVer
|
||||
) {
|
||||
device.log.fatal(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`Device firmware outdated. Min supported: ${Constants.minFwVer} got : ${decodedMessage.payloadVariant.value.firmwareVersion}`,
|
||||
);
|
||||
}
|
||||
device.log.debug(
|
||||
Types.Emitter[Types.Emitter.GetMetadata],
|
||||
"🏷️ Received metadata packet",
|
||||
);
|
||||
|
||||
device.events.onDeviceMetadataPacket.dispatch({
|
||||
id: decodedMessage.id,
|
||||
rxTime: new Date(),
|
||||
from: 0,
|
||||
to: 0,
|
||||
type: "direct",
|
||||
channel: Types.ChannelNumber.Primary,
|
||||
data: decodedMessage.payloadVariant.value,
|
||||
});
|
||||
break;
|
||||
}
|
||||
device.events.onDeviceMetadataPacket.dispatch({
|
||||
id: decodedMessage.id,
|
||||
rxTime: new Date(),
|
||||
from: 0,
|
||||
to: 0,
|
||||
type: "direct",
|
||||
channel: Types.ChannelNumber.Primary,
|
||||
data: decodedMessage.payloadVariant.value,
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "mqttClientProxyMessage": {
|
||||
break;
|
||||
}
|
||||
case "mqttClientProxyMessage": {
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
device.log.warn(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`⚠️ Unhandled payload variant: ${decodedMessage.payloadVariant.case}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
default: {
|
||||
device.log.warn(
|
||||
Types.Emitter[Types.Emitter.HandleFromRadio],
|
||||
`⚠️ Unhandled payload variant: ${decodedMessage.payloadVariant.case}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
import type { DeviceOutput } from "../../types.ts";
|
||||
|
||||
export const fromDeviceStream: () => TransformStream<Uint8Array, DeviceOutput> =
|
||||
(
|
||||
// onReleaseEvent: SimpleEventDispatcher<boolean>,
|
||||
) => {
|
||||
let byteBuffer = new Uint8Array([]);
|
||||
const textDecoder = new TextDecoder();
|
||||
return new TransformStream<Uint8Array, DeviceOutput>({
|
||||
transform(chunk: Uint8Array, controller): void {
|
||||
// onReleaseEvent.subscribe(() => {
|
||||
// controller.terminate();
|
||||
// });
|
||||
byteBuffer = new Uint8Array([...byteBuffer, ...chunk]);
|
||||
let processingExhausted = false;
|
||||
while (byteBuffer.length !== 0 && !processingExhausted) {
|
||||
const framingIndex = byteBuffer.findIndex((byte) => byte === 0x94);
|
||||
const framingByte2 = byteBuffer[framingIndex + 1];
|
||||
if (framingByte2 === 0xc3) {
|
||||
if (byteBuffer.subarray(0, framingIndex).length) {
|
||||
controller.enqueue({
|
||||
type: "debug",
|
||||
data: textDecoder.decode(byteBuffer.subarray(0, framingIndex)),
|
||||
});
|
||||
byteBuffer = byteBuffer.subarray(framingIndex);
|
||||
}
|
||||
(
|
||||
// onReleaseEvent: SimpleEventDispatcher<boolean>,
|
||||
) => {
|
||||
let byteBuffer = new Uint8Array([]);
|
||||
const textDecoder = new TextDecoder();
|
||||
return new TransformStream<Uint8Array, DeviceOutput>({
|
||||
transform(chunk: Uint8Array, controller): void {
|
||||
// onReleaseEvent.subscribe(() => {
|
||||
// controller.terminate();
|
||||
// });
|
||||
byteBuffer = new Uint8Array([...byteBuffer, ...chunk]);
|
||||
let processingExhausted = false;
|
||||
while (byteBuffer.length !== 0 && !processingExhausted) {
|
||||
const framingIndex = byteBuffer.findIndex((byte) => byte === 0x94);
|
||||
const framingByte2 = byteBuffer[framingIndex + 1];
|
||||
if (framingByte2 === 0xc3) {
|
||||
if (byteBuffer.subarray(0, framingIndex).length) {
|
||||
controller.enqueue({
|
||||
type: "debug",
|
||||
data: textDecoder.decode(byteBuffer.subarray(0, framingIndex)),
|
||||
});
|
||||
byteBuffer = byteBuffer.subarray(framingIndex);
|
||||
}
|
||||
|
||||
const msb = byteBuffer[2];
|
||||
const lsb = byteBuffer[3];
|
||||
const msb = byteBuffer[2];
|
||||
const lsb = byteBuffer[3];
|
||||
|
||||
if (
|
||||
msb !== undefined &&
|
||||
lsb !== undefined &&
|
||||
byteBuffer.length >= 4 + (msb << 8) + lsb
|
||||
) {
|
||||
const packet = byteBuffer.subarray(4, 4 + (msb << 8) + lsb);
|
||||
if (
|
||||
msb !== undefined &&
|
||||
lsb !== undefined &&
|
||||
byteBuffer.length >= 4 + (msb << 8) + lsb
|
||||
) {
|
||||
const packet = byteBuffer.subarray(4, 4 + (msb << 8) + lsb);
|
||||
|
||||
const malformedDetectorIndex = packet.findIndex(
|
||||
(byte) => byte === 0x94,
|
||||
);
|
||||
if (
|
||||
malformedDetectorIndex !== -1 &&
|
||||
packet[malformedDetectorIndex + 1] === 0xc3
|
||||
) {
|
||||
console.warn(
|
||||
`⚠️ Malformed packet found, discarding: ${byteBuffer
|
||||
.subarray(0, malformedDetectorIndex - 1)
|
||||
.toString()}`,
|
||||
);
|
||||
const malformedDetectorIndex = packet.findIndex(
|
||||
(byte) => byte === 0x94,
|
||||
);
|
||||
if (
|
||||
malformedDetectorIndex !== -1 &&
|
||||
packet[malformedDetectorIndex + 1] === 0xc3
|
||||
) {
|
||||
console.warn(
|
||||
`⚠️ Malformed packet found, discarding: ${byteBuffer
|
||||
.subarray(0, malformedDetectorIndex - 1)
|
||||
.toString()}`,
|
||||
);
|
||||
|
||||
byteBuffer = byteBuffer.subarray(malformedDetectorIndex);
|
||||
} else {
|
||||
byteBuffer = byteBuffer.subarray(3 + (msb << 8) + lsb + 1);
|
||||
byteBuffer = byteBuffer.subarray(malformedDetectorIndex);
|
||||
} else {
|
||||
byteBuffer = byteBuffer.subarray(3 + (msb << 8) + lsb + 1);
|
||||
|
||||
controller.enqueue({
|
||||
type: "packet",
|
||||
data: packet,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
/** Only partioal message in buffer, wait for the rest */
|
||||
processingExhausted = true;
|
||||
}
|
||||
} else {
|
||||
/** Message not complete, only 1 byte in buffer */
|
||||
processingExhausted = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
controller.enqueue({
|
||||
type: "packet",
|
||||
data: packet,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
/** Only partioal message in buffer, wait for the rest */
|
||||
processingExhausted = true;
|
||||
}
|
||||
} else {
|
||||
/** Message not complete, only 1 byte in buffer */
|
||||
processingExhausted = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
* Pads packets with appropriate framing information before writing to the output stream.
|
||||
*/
|
||||
export const toDeviceStream: TransformStream<Uint8Array, Uint8Array> =
|
||||
new TransformStream<Uint8Array, Uint8Array>({
|
||||
transform(chunk: Uint8Array, controller): void {
|
||||
const bufLen = chunk.length;
|
||||
const header = new Uint8Array([
|
||||
0x94,
|
||||
0xc3,
|
||||
(bufLen >> 8) & 0xff,
|
||||
bufLen & 0xff,
|
||||
]);
|
||||
controller.enqueue(new Uint8Array([...header, ...chunk]));
|
||||
},
|
||||
});
|
||||
new TransformStream<Uint8Array, Uint8Array>({
|
||||
transform(chunk: Uint8Array, controller): void {
|
||||
const bufLen = chunk.length;
|
||||
const header = new Uint8Array([
|
||||
0x94,
|
||||
0xc3,
|
||||
(bufLen >> 8) & 0xff,
|
||||
bufLen & 0xff,
|
||||
]);
|
||||
controller.enqueue(new Uint8Array([...header, ...chunk]));
|
||||
},
|
||||
});
|
||||
|
||||
+116
-116
@@ -6,130 +6,130 @@ import crc16ccitt from "crc/calculators/crc16ccitt";
|
||||
type XmodemProps = (toRadio: Uint8Array, id?: number) => Promise<number>;
|
||||
|
||||
export class Xmodem {
|
||||
private sendRaw: XmodemProps;
|
||||
private rxBuffer: Uint8Array[];
|
||||
private txBuffer: Uint8Array[];
|
||||
private textEncoder: TextEncoder;
|
||||
private counter: number;
|
||||
private sendRaw: XmodemProps;
|
||||
private rxBuffer: Uint8Array[];
|
||||
private txBuffer: Uint8Array[];
|
||||
private textEncoder: TextEncoder;
|
||||
private counter: number;
|
||||
|
||||
constructor(sendRaw: XmodemProps) {
|
||||
this.sendRaw = sendRaw;
|
||||
this.rxBuffer = [];
|
||||
this.txBuffer = [];
|
||||
this.textEncoder = new TextEncoder();
|
||||
this.counter = 0;
|
||||
}
|
||||
constructor(sendRaw: XmodemProps) {
|
||||
this.sendRaw = sendRaw;
|
||||
this.rxBuffer = [];
|
||||
this.txBuffer = [];
|
||||
this.textEncoder = new TextEncoder();
|
||||
this.counter = 0;
|
||||
}
|
||||
|
||||
async downloadFile(filename: string): Promise<number> {
|
||||
return await this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.STX,
|
||||
this.textEncoder.encode(filename),
|
||||
0,
|
||||
);
|
||||
}
|
||||
async downloadFile(filename: string): Promise<number> {
|
||||
return await this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.STX,
|
||||
this.textEncoder.encode(filename),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
async uploadFile(filename: string, data: Uint8Array): Promise<number> {
|
||||
for (let i = 0; i < data.length; i += 128) {
|
||||
this.txBuffer.push(data.slice(i, i + 128));
|
||||
}
|
||||
async uploadFile(filename: string, data: Uint8Array): Promise<number> {
|
||||
for (let i = 0; i < data.length; i += 128) {
|
||||
this.txBuffer.push(data.slice(i, i + 128));
|
||||
}
|
||||
|
||||
return await this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.SOH,
|
||||
this.textEncoder.encode(filename),
|
||||
0,
|
||||
);
|
||||
}
|
||||
return await this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.SOH,
|
||||
this.textEncoder.encode(filename),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
async sendCommand(
|
||||
command: Protobuf.Xmodem.XModem_Control,
|
||||
buffer?: Uint8Array,
|
||||
sequence?: number,
|
||||
crc16?: number,
|
||||
): Promise<number> {
|
||||
const toRadio = create(Protobuf.Mesh.ToRadioSchema, {
|
||||
payloadVariant: {
|
||||
case: "xmodemPacket",
|
||||
value: {
|
||||
buffer,
|
||||
control: command,
|
||||
seq: sequence,
|
||||
crc16: crc16,
|
||||
},
|
||||
},
|
||||
});
|
||||
return await this.sendRaw(toBinary(Protobuf.Mesh.ToRadioSchema, toRadio));
|
||||
}
|
||||
async sendCommand(
|
||||
command: Protobuf.Xmodem.XModem_Control,
|
||||
buffer?: Uint8Array,
|
||||
sequence?: number,
|
||||
crc16?: number,
|
||||
): Promise<number> {
|
||||
const toRadio = create(Protobuf.Mesh.ToRadioSchema, {
|
||||
payloadVariant: {
|
||||
case: "xmodemPacket",
|
||||
value: {
|
||||
buffer,
|
||||
control: command,
|
||||
seq: sequence,
|
||||
crc16: crc16,
|
||||
},
|
||||
},
|
||||
});
|
||||
return await this.sendRaw(toBinary(Protobuf.Mesh.ToRadioSchema, toRadio));
|
||||
}
|
||||
|
||||
async handlePacket(packet: Protobuf.Xmodem.XModem): Promise<number> {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
async handlePacket(packet: Protobuf.Xmodem.XModem): Promise<number> {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
switch (packet.control) {
|
||||
case Protobuf.Xmodem.XModem_Control.NUL: {
|
||||
// nothing
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.SOH: {
|
||||
this.counter = packet.seq;
|
||||
if (this.validateCrc16(packet)) {
|
||||
this.rxBuffer[this.counter] = packet.buffer;
|
||||
return this.sendCommand(Protobuf.Xmodem.XModem_Control.ACK);
|
||||
}
|
||||
return await this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.NAK,
|
||||
undefined,
|
||||
packet.seq,
|
||||
);
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.STX: {
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.EOT: {
|
||||
// end of transmission
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.ACK: {
|
||||
this.counter++;
|
||||
if (this.txBuffer[this.counter - 1]) {
|
||||
return this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.SOH,
|
||||
this.txBuffer[this.counter - 1],
|
||||
this.counter,
|
||||
crc16ccitt(this.txBuffer[this.counter - 1] ?? new Uint8Array()),
|
||||
);
|
||||
}
|
||||
if (this.counter === this.txBuffer.length + 1) {
|
||||
return this.sendCommand(Protobuf.Xmodem.XModem_Control.EOT);
|
||||
}
|
||||
this.clear();
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.NAK: {
|
||||
return this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.SOH,
|
||||
this.txBuffer[this.counter],
|
||||
this.counter,
|
||||
crc16ccitt(this.txBuffer[this.counter - 1] ?? new Uint8Array()),
|
||||
);
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.CAN: {
|
||||
this.clear();
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.CTRLZ: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
switch (packet.control) {
|
||||
case Protobuf.Xmodem.XModem_Control.NUL: {
|
||||
// nothing
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.SOH: {
|
||||
this.counter = packet.seq;
|
||||
if (this.validateCrc16(packet)) {
|
||||
this.rxBuffer[this.counter] = packet.buffer;
|
||||
return this.sendCommand(Protobuf.Xmodem.XModem_Control.ACK);
|
||||
}
|
||||
return await this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.NAK,
|
||||
undefined,
|
||||
packet.seq,
|
||||
);
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.STX: {
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.EOT: {
|
||||
// end of transmission
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.ACK: {
|
||||
this.counter++;
|
||||
if (this.txBuffer[this.counter - 1]) {
|
||||
return this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.SOH,
|
||||
this.txBuffer[this.counter - 1],
|
||||
this.counter,
|
||||
crc16ccitt(this.txBuffer[this.counter - 1] ?? new Uint8Array()),
|
||||
);
|
||||
}
|
||||
if (this.counter === this.txBuffer.length + 1) {
|
||||
return this.sendCommand(Protobuf.Xmodem.XModem_Control.EOT);
|
||||
}
|
||||
this.clear();
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.NAK: {
|
||||
return this.sendCommand(
|
||||
Protobuf.Xmodem.XModem_Control.SOH,
|
||||
this.txBuffer[this.counter],
|
||||
this.counter,
|
||||
crc16ccitt(this.txBuffer[this.counter - 1] ?? new Uint8Array()),
|
||||
);
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.CAN: {
|
||||
this.clear();
|
||||
break;
|
||||
}
|
||||
case Protobuf.Xmodem.XModem_Control.CTRLZ: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
|
||||
validateCrc16(packet: Protobuf.Xmodem.XModem): boolean {
|
||||
return crc16ccitt(packet.buffer) === packet.crc16;
|
||||
}
|
||||
validateCrc16(packet: Protobuf.Xmodem.XModem): boolean {
|
||||
return crc16ccitt(packet.buffer) === packet.crc16;
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.counter = 0;
|
||||
this.rxBuffer = [];
|
||||
this.txBuffer = [];
|
||||
}
|
||||
clear() {
|
||||
this.counter = 0;
|
||||
this.rxBuffer = [];
|
||||
this.txBuffer = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,31 +2,31 @@ import { Utils } from "@meshtastic/core";
|
||||
import type { Types } from "@meshtastic/core";
|
||||
|
||||
export class TransportDeno implements Types.Transport {
|
||||
private _toDevice: WritableStream<Uint8Array>;
|
||||
private _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
private _toDevice: WritableStream<Uint8Array>;
|
||||
private _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
|
||||
public static async create(hostname: string): Promise<TransportDeno> {
|
||||
const connection = await Deno.connect({
|
||||
hostname,
|
||||
port: 4403,
|
||||
});
|
||||
return new TransportDeno(connection);
|
||||
}
|
||||
public static async create(hostname: string): Promise<TransportDeno> {
|
||||
const connection = await Deno.connect({
|
||||
hostname,
|
||||
port: 4403,
|
||||
});
|
||||
return new TransportDeno(connection);
|
||||
}
|
||||
|
||||
constructor(connection: Deno.Conn) {
|
||||
Utils.toDeviceStream.readable.pipeTo(connection.writable);
|
||||
constructor(connection: Deno.Conn) {
|
||||
Utils.toDeviceStream.readable.pipeTo(connection.writable);
|
||||
|
||||
this._toDevice = Utils.toDeviceStream.writable;
|
||||
this._fromDevice = connection.readable.pipeThrough(
|
||||
Utils.fromDeviceStream(),
|
||||
);
|
||||
}
|
||||
this._toDevice = Utils.toDeviceStream.writable;
|
||||
this._fromDevice = connection.readable.pipeThrough(
|
||||
Utils.fromDeviceStream(),
|
||||
);
|
||||
}
|
||||
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "@meshtastic/transport-http",
|
||||
"version": "0.2.2",
|
||||
"exports": "./mod.ts"
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "@meshtastic/transport-http",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"description": "A transport layer for Meshtastic applications using HTTP.",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
"exports": {".": "./mod.ts"},
|
||||
"tasks": {
|
||||
"build": "deno build"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +1,89 @@
|
||||
import type { Types } from "@meshtastic/core";
|
||||
|
||||
export class TransportHTTP implements Types.Transport {
|
||||
private _toDevice: WritableStream<Uint8Array>;
|
||||
private _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
private url: string;
|
||||
private receiveBatchRequests: boolean;
|
||||
private fetchInterval: number;
|
||||
private _toDevice: WritableStream<Uint8Array>;
|
||||
private _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
private url: string;
|
||||
private receiveBatchRequests: boolean;
|
||||
private fetchInterval: number;
|
||||
|
||||
public static async create(
|
||||
address: string,
|
||||
tls?: boolean,
|
||||
): Promise<TransportHTTP> {
|
||||
const connectionUrl = `${tls ? "https" : "http"}://${address}`;
|
||||
await fetch(`${connectionUrl}/json/report`);
|
||||
await Promise.resolve();
|
||||
return new TransportHTTP(connectionUrl);
|
||||
}
|
||||
public static async create(
|
||||
address: string,
|
||||
tls?: boolean,
|
||||
): Promise<TransportHTTP> {
|
||||
const connectionUrl = `${tls ? "https" : "http"}://${address}`;
|
||||
await fetch(`${connectionUrl}/json/report`);
|
||||
await Promise.resolve();
|
||||
return new TransportHTTP(connectionUrl);
|
||||
}
|
||||
|
||||
constructor(url: string) {
|
||||
this.url = url;
|
||||
this.receiveBatchRequests = false;
|
||||
this.fetchInterval = 3000;
|
||||
constructor(url: string) {
|
||||
this.url = url;
|
||||
this.receiveBatchRequests = false;
|
||||
this.fetchInterval = 3000;
|
||||
|
||||
this._toDevice = new WritableStream<Uint8Array>({
|
||||
write: async (chunk) => {
|
||||
await this.writeToRadio(chunk);
|
||||
},
|
||||
});
|
||||
this._toDevice = new WritableStream<Uint8Array>({
|
||||
write: async (chunk) => {
|
||||
await this.writeToRadio(chunk);
|
||||
},
|
||||
});
|
||||
|
||||
let controller: ReadableStreamDefaultController<Types.DeviceOutput>;
|
||||
let controller: ReadableStreamDefaultController<Types.DeviceOutput>;
|
||||
|
||||
this._fromDevice = new ReadableStream<Types.DeviceOutput>({
|
||||
start: (ctrl) => {
|
||||
controller = ctrl;
|
||||
},
|
||||
});
|
||||
this._fromDevice = new ReadableStream<Types.DeviceOutput>({
|
||||
start: (ctrl) => {
|
||||
controller = ctrl;
|
||||
},
|
||||
});
|
||||
|
||||
setInterval(async () => {
|
||||
await this.readFromRadio(controller);
|
||||
}, this.fetchInterval);
|
||||
}
|
||||
setInterval(async () => {
|
||||
await this.readFromRadio(controller);
|
||||
}, this.fetchInterval);
|
||||
}
|
||||
|
||||
private async readFromRadio(
|
||||
controller: ReadableStreamDefaultController<Types.DeviceOutput>,
|
||||
): Promise<void> {
|
||||
let readBuffer = new ArrayBuffer(1);
|
||||
while (readBuffer.byteLength > 0) {
|
||||
const response = await fetch(
|
||||
`${this.url}/api/v1/fromradio?all=${
|
||||
this.receiveBatchRequests ? "true" : "false"
|
||||
}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/x-protobuf",
|
||||
},
|
||||
},
|
||||
);
|
||||
private async readFromRadio(
|
||||
controller: ReadableStreamDefaultController<Types.DeviceOutput>,
|
||||
): Promise<void> {
|
||||
let readBuffer = new ArrayBuffer(1);
|
||||
while (readBuffer.byteLength > 0) {
|
||||
const response = await fetch(
|
||||
`${this.url}/api/v1/fromradio?all=${
|
||||
this.receiveBatchRequests ? "true" : "false"
|
||||
}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/x-protobuf",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
readBuffer = await response.arrayBuffer();
|
||||
readBuffer = await response.arrayBuffer();
|
||||
|
||||
if (readBuffer.byteLength > 0) {
|
||||
controller.enqueue({
|
||||
type: "packet",
|
||||
data: new Uint8Array(readBuffer),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (readBuffer.byteLength > 0) {
|
||||
controller.enqueue({
|
||||
type: "packet",
|
||||
data: new Uint8Array(readBuffer),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async writeToRadio(data: Uint8Array): Promise<void> {
|
||||
await fetch(`${this.url}/api/v1/toradio`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/x-protobuf",
|
||||
},
|
||||
body: data,
|
||||
});
|
||||
}
|
||||
private async writeToRadio(data: Uint8Array): Promise<void> {
|
||||
await fetch(`${this.url}/api/v1/toradio`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/x-protobuf",
|
||||
},
|
||||
body: data,
|
||||
});
|
||||
}
|
||||
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,73 +4,73 @@ import { Utils } from "@meshtastic/core";
|
||||
import type { Types } from "@meshtastic/core";
|
||||
|
||||
export class TransportNode implements Types.Transport {
|
||||
private readonly _toDevice: WritableStream<Uint8Array>;
|
||||
private readonly _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
private readonly _toDevice: WritableStream<Uint8Array>;
|
||||
private readonly _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
|
||||
/**
|
||||
* Creates and connects a new TransportNode instance.
|
||||
* @param hostname - The IP address or hostname of the Meshtastic device.
|
||||
* @param port - The port number for the TCP connection (defaults to 4403).
|
||||
* @returns A promise that resolves with a connected TransportNode instance.
|
||||
*/
|
||||
public static create(hostname: string, port = 4403): Promise<TransportNode> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const socket = new Socket();
|
||||
/**
|
||||
* Creates and connects a new TransportNode instance.
|
||||
* @param hostname - The IP address or hostname of the Meshtastic device.
|
||||
* @param port - The port number for the TCP connection (defaults to 4403).
|
||||
* @returns A promise that resolves with a connected TransportNode instance.
|
||||
*/
|
||||
public static create(hostname: string, port = 4403): Promise<TransportNode> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const socket = new Socket();
|
||||
|
||||
const onError = (err: Error) => {
|
||||
socket.destroy();
|
||||
reject(err);
|
||||
};
|
||||
const onError = (err: Error) => {
|
||||
socket.destroy();
|
||||
reject(err);
|
||||
};
|
||||
|
||||
socket.once("error", onError);
|
||||
socket.once("error", onError);
|
||||
|
||||
socket.connect(port, hostname, () => {
|
||||
socket.removeListener("error", onError);
|
||||
resolve(new TransportNode(socket));
|
||||
});
|
||||
});
|
||||
}
|
||||
socket.connect(port, hostname, () => {
|
||||
socket.removeListener("error", onError);
|
||||
resolve(new TransportNode(socket));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new TransportNode.
|
||||
* @param connection - An active Node.js net.Socket connection.
|
||||
*/
|
||||
constructor(connection: Socket) {
|
||||
connection.on("error", (err) => {
|
||||
console.error("Socket connection error:", err);
|
||||
});
|
||||
/**
|
||||
* Constructs a new TransportNode.
|
||||
* @param connection - An active Node.js net.Socket connection.
|
||||
*/
|
||||
constructor(connection: Socket) {
|
||||
connection.on("error", (err) => {
|
||||
console.error("Socket connection error:", err);
|
||||
});
|
||||
|
||||
const fromDeviceSource = Readable.toWeb(
|
||||
connection,
|
||||
) as ReadableStream<Uint8Array>;
|
||||
this._fromDevice = fromDeviceSource.pipeThrough(Utils.fromDeviceStream());
|
||||
const fromDeviceSource = Readable.toWeb(
|
||||
connection,
|
||||
) as ReadableStream<Uint8Array>;
|
||||
this._fromDevice = fromDeviceSource.pipeThrough(Utils.fromDeviceStream());
|
||||
|
||||
// Stream for data going FROM the application TO the Meshtastic device.
|
||||
const toDeviceTransform = Utils.toDeviceStream;
|
||||
this._toDevice = toDeviceTransform.writable;
|
||||
|
||||
// The readable end of the transform is then piped to the Node.js socket.
|
||||
// A similar assertion is needed here because `Writable.toWeb` also returns
|
||||
// a generically typed stream (`WritableStream<any>`).
|
||||
toDeviceTransform.readable
|
||||
.pipeTo(Writable.toWeb(connection) as WritableStream<Uint8Array>)
|
||||
.catch((err) => {
|
||||
console.error("Error piping data to socket:", err);
|
||||
connection.destroy(err as Error);
|
||||
});
|
||||
}
|
||||
// The readable end of the transform is then piped to the Node.js socket.
|
||||
// A similar assertion is needed here because `Writable.toWeb` also returns
|
||||
// a generically typed stream (`WritableStream<any>`).
|
||||
toDeviceTransform.readable
|
||||
.pipeTo(Writable.toWeb(connection) as WritableStream<Uint8Array>)
|
||||
.catch((err) => {
|
||||
console.error("Error piping data to socket:", err);
|
||||
connection.destroy(err as Error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The WritableStream to send data to the Meshtastic device.
|
||||
*/
|
||||
public get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
/**
|
||||
* The WritableStream to send data to the Meshtastic device.
|
||||
*/
|
||||
public get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ReadableStream to receive data from the Meshtastic device.
|
||||
*/
|
||||
public get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
/**
|
||||
* The ReadableStream to receive data from the Meshtastic device.
|
||||
*/
|
||||
public get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "@meshtastic/transport-web-bluetooth",
|
||||
"version": "0.1.3",
|
||||
"exports": "./mod.ts"
|
||||
}
|
||||
+5
-5
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "@meshtastic/transport-web-bluetooth",
|
||||
"version": "0.1.2",
|
||||
"name": "@meshtastic/transport-web-bluetooth",
|
||||
"version": "0.1.3",
|
||||
"description": "A transport layer for Meshtastic applications using Web Bluetooth.",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
},
|
||||
"imports": {
|
||||
"devDependencies": {
|
||||
"@types/web-bluetooth": "npm:@types/web-bluetooth@^0.0.20"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"compilerOptions": {
|
||||
"types": ["@types/web-bluetooth"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,133 +1,135 @@
|
||||
import type { Types } from "@meshtastic/core";
|
||||
|
||||
export class TransportWebBluetooth implements Types.Transport {
|
||||
private _toDevice: WritableStream<Uint8Array>;
|
||||
private _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
private _fromDeviceController?: ReadableStreamDefaultController<Types.DeviceOutput>;
|
||||
private _isFirstWrite = true;
|
||||
private _toDevice: WritableStream<Uint8Array>;
|
||||
private _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
private _fromDeviceController?: ReadableStreamDefaultController<Types.DeviceOutput>;
|
||||
private _isFirstWrite = true;
|
||||
|
||||
private toRadioCharacteristic: BluetoothRemoteGATTCharacteristic;
|
||||
private fromRadioCharacteristic: BluetoothRemoteGATTCharacteristic;
|
||||
private fromNumCharacteristic: BluetoothRemoteGATTCharacteristic;
|
||||
private toRadioCharacteristic: BluetoothRemoteGATTCharacteristic;
|
||||
private fromRadioCharacteristic: BluetoothRemoteGATTCharacteristic;
|
||||
private fromNumCharacteristic: BluetoothRemoteGATTCharacteristic;
|
||||
|
||||
static ToRadioUuid = "f75c76d2-129e-4dad-a1dd-7866124401e7";
|
||||
static FromRadioUuid = "2c55e69e-4993-11ed-b878-0242ac120002";
|
||||
static FromNumUuid = "ed9da18c-a800-4f66-a670-aa7547e34453";
|
||||
static ServiceUuid = "6ba1b218-15a8-461f-9fa8-5dcae273eafd";
|
||||
static ToRadioUuid = "f75c76d2-129e-4dad-a1dd-7866124401e7";
|
||||
static FromRadioUuid = "2c55e69e-4993-11ed-b878-0242ac120002";
|
||||
static FromNumUuid = "ed9da18c-a800-4f66-a670-aa7547e34453";
|
||||
static ServiceUuid = "6ba1b218-15a8-461f-9fa8-5dcae273eafd";
|
||||
|
||||
public static async create(): Promise<TransportWebBluetooth> {
|
||||
const device = await navigator.bluetooth.requestDevice({
|
||||
filters: [{ services: [this.ServiceUuid] }],
|
||||
});
|
||||
return await this.prepareConnection(device);
|
||||
}
|
||||
public static async create(): Promise<TransportWebBluetooth> {
|
||||
const device = await navigator.bluetooth.requestDevice({
|
||||
filters: [{ services: [TransportWebBluetooth.ServiceUuid] }],
|
||||
});
|
||||
return await TransportWebBluetooth.prepareConnection(device);
|
||||
}
|
||||
|
||||
public static async createFromDevice(
|
||||
device: BluetoothDevice,
|
||||
): Promise<TransportWebBluetooth> {
|
||||
return await this.prepareConnection(device);
|
||||
}
|
||||
public static async createFromDevice(
|
||||
device: BluetoothDevice,
|
||||
): Promise<TransportWebBluetooth> {
|
||||
return await TransportWebBluetooth.prepareConnection(device);
|
||||
}
|
||||
|
||||
public static async prepareConnection(
|
||||
device: BluetoothDevice,
|
||||
): Promise<TransportWebBluetooth> {
|
||||
const gattServer = await device.gatt?.connect();
|
||||
public static async prepareConnection(
|
||||
device: BluetoothDevice,
|
||||
): Promise<TransportWebBluetooth> {
|
||||
const gattServer = await device.gatt?.connect();
|
||||
|
||||
if (!gattServer) {
|
||||
throw new Error("Failed to connect to GATT server");
|
||||
}
|
||||
if (!gattServer) {
|
||||
throw new Error("Failed to connect to GATT server");
|
||||
}
|
||||
|
||||
const service = await gattServer.getPrimaryService(this.ServiceUuid);
|
||||
const service = await gattServer.getPrimaryService(
|
||||
TransportWebBluetooth.ServiceUuid,
|
||||
);
|
||||
|
||||
const toRadioCharacteristic = await service.getCharacteristic(
|
||||
this.ToRadioUuid,
|
||||
);
|
||||
const fromRadioCharacteristic = await service.getCharacteristic(
|
||||
this.FromRadioUuid,
|
||||
);
|
||||
const fromNumCharacteristic = await service.getCharacteristic(
|
||||
this.FromNumUuid,
|
||||
);
|
||||
const toRadioCharacteristic = await service.getCharacteristic(
|
||||
TransportWebBluetooth.ToRadioUuid,
|
||||
);
|
||||
const fromRadioCharacteristic = await service.getCharacteristic(
|
||||
TransportWebBluetooth.FromRadioUuid,
|
||||
);
|
||||
const fromNumCharacteristic = await service.getCharacteristic(
|
||||
TransportWebBluetooth.FromNumUuid,
|
||||
);
|
||||
|
||||
if (
|
||||
!toRadioCharacteristic ||
|
||||
!fromRadioCharacteristic ||
|
||||
!fromNumCharacteristic
|
||||
) {
|
||||
throw new Error("Failed to find required characteristics");
|
||||
}
|
||||
if (
|
||||
!toRadioCharacteristic ||
|
||||
!fromRadioCharacteristic ||
|
||||
!fromNumCharacteristic
|
||||
) {
|
||||
throw new Error("Failed to find required characteristics");
|
||||
}
|
||||
|
||||
console.log("Connected to device", device.name);
|
||||
console.log("Connected to device", device.name);
|
||||
|
||||
return new TransportWebBluetooth(
|
||||
toRadioCharacteristic,
|
||||
fromRadioCharacteristic,
|
||||
fromNumCharacteristic,
|
||||
);
|
||||
}
|
||||
return new TransportWebBluetooth(
|
||||
toRadioCharacteristic,
|
||||
fromRadioCharacteristic,
|
||||
fromNumCharacteristic,
|
||||
);
|
||||
}
|
||||
|
||||
constructor(
|
||||
toRadioCharacteristic: BluetoothRemoteGATTCharacteristic,
|
||||
fromRadioCharacteristic: BluetoothRemoteGATTCharacteristic,
|
||||
fromNumCharacteristic: BluetoothRemoteGATTCharacteristic,
|
||||
) {
|
||||
this.toRadioCharacteristic = toRadioCharacteristic;
|
||||
this.fromRadioCharacteristic = fromRadioCharacteristic;
|
||||
this.fromNumCharacteristic = fromNumCharacteristic;
|
||||
constructor(
|
||||
toRadioCharacteristic: BluetoothRemoteGATTCharacteristic,
|
||||
fromRadioCharacteristic: BluetoothRemoteGATTCharacteristic,
|
||||
fromNumCharacteristic: BluetoothRemoteGATTCharacteristic,
|
||||
) {
|
||||
this.toRadioCharacteristic = toRadioCharacteristic;
|
||||
this.fromRadioCharacteristic = fromRadioCharacteristic;
|
||||
this.fromNumCharacteristic = fromNumCharacteristic;
|
||||
|
||||
this._fromDevice = new ReadableStream({
|
||||
start: (ctrl) => {
|
||||
this._fromDeviceController = ctrl;
|
||||
},
|
||||
});
|
||||
this._fromDevice = new ReadableStream({
|
||||
start: (ctrl) => {
|
||||
this._fromDeviceController = ctrl;
|
||||
},
|
||||
});
|
||||
|
||||
this._toDevice = new WritableStream({
|
||||
write: async (chunk) => {
|
||||
await this.toRadioCharacteristic.writeValue(chunk);
|
||||
this._toDevice = new WritableStream({
|
||||
write: async (chunk) => {
|
||||
await this.toRadioCharacteristic.writeValue(chunk);
|
||||
|
||||
if (this._isFirstWrite && this._fromDeviceController) {
|
||||
this._isFirstWrite = false;
|
||||
setTimeout(() => {
|
||||
this.readFromRadio(this._fromDeviceController!);
|
||||
}, 50);
|
||||
}
|
||||
},
|
||||
});
|
||||
if (this._isFirstWrite && this._fromDeviceController) {
|
||||
this._isFirstWrite = false;
|
||||
setTimeout(() => {
|
||||
this.readFromRadio(this._fromDeviceController!);
|
||||
}, 50);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
this.fromNumCharacteristic.addEventListener(
|
||||
"characteristicvaluechanged",
|
||||
() => {
|
||||
if (this._fromDeviceController) {
|
||||
this.readFromRadio(this._fromDeviceController);
|
||||
}
|
||||
},
|
||||
);
|
||||
this.fromNumCharacteristic.addEventListener(
|
||||
"characteristicvaluechanged",
|
||||
() => {
|
||||
if (this._fromDeviceController) {
|
||||
this.readFromRadio(this._fromDeviceController);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
this.fromNumCharacteristic.startNotifications();
|
||||
}
|
||||
this.fromNumCharacteristic.startNotifications();
|
||||
}
|
||||
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
|
||||
protected async readFromRadio(
|
||||
controller: ReadableStreamDefaultController<Types.DeviceOutput>,
|
||||
): Promise<void> {
|
||||
let hasMoreData = true;
|
||||
while (hasMoreData && this.fromRadioCharacteristic) {
|
||||
const value = await this.fromRadioCharacteristic.readValue();
|
||||
if (value.byteLength === 0) {
|
||||
hasMoreData = false;
|
||||
continue;
|
||||
}
|
||||
controller.enqueue({
|
||||
type: "packet",
|
||||
data: new Uint8Array(value.buffer),
|
||||
});
|
||||
}
|
||||
}
|
||||
protected async readFromRadio(
|
||||
controller: ReadableStreamDefaultController<Types.DeviceOutput>,
|
||||
): Promise<void> {
|
||||
let hasMoreData = true;
|
||||
while (hasMoreData && this.fromRadioCharacteristic) {
|
||||
const value = await this.fromRadioCharacteristic.readValue();
|
||||
if (value.byteLength === 0) {
|
||||
hasMoreData = false;
|
||||
continue;
|
||||
}
|
||||
controller.enqueue({
|
||||
type: "packet",
|
||||
data: new Uint8Array(value.buffer),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"name": "@meshtastic/transport-web-serial",
|
||||
"version": "0.2.1",
|
||||
"description": "A transport layer for Meshtastic applications using Web Serial API.",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
},
|
||||
"imports": {
|
||||
"@types/w3c-web-serial": "npm:@types/w3c-web-serial@^1.0.7"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"types": ["@types/w3c-web-serial"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "@meshtastic/transport-web-serial",
|
||||
"version": "0.2.2",
|
||||
"exports": "./mod.ts"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "@meshtastic/transport-web-serial",
|
||||
"version": "0.2.2",
|
||||
"description": "A transport layer for Meshtastic applications using Web Serial API.",
|
||||
"exports": {
|
||||
".": "./mod.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/w3c-web-serial": "npm:@types/w3c-web-serial@^1.0.7"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"types": ["@types/w3c-web-serial"]
|
||||
}
|
||||
}
|
||||
@@ -2,41 +2,41 @@ import { Utils } from "@meshtastic/core";
|
||||
import type { Types } from "@meshtastic/core";
|
||||
|
||||
export class TransportWebSerial implements Types.Transport {
|
||||
private _toDevice: WritableStream<Uint8Array>;
|
||||
private _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
private _toDevice: WritableStream<Uint8Array>;
|
||||
private _fromDevice: ReadableStream<Types.DeviceOutput>;
|
||||
|
||||
public static async create(baudRate?: number): Promise<TransportWebSerial> {
|
||||
const port = await navigator.serial.requestPort();
|
||||
await port.open({ baudRate: baudRate || 115200 });
|
||||
return new TransportWebSerial(port);
|
||||
}
|
||||
public static async create(baudRate?: number): Promise<TransportWebSerial> {
|
||||
const port = await navigator.serial.requestPort();
|
||||
await port.open({ baudRate: baudRate || 115200 });
|
||||
return new TransportWebSerial(port);
|
||||
}
|
||||
|
||||
public static async createFromPort(
|
||||
port: SerialPort,
|
||||
baudRate?: number,
|
||||
): Promise<TransportWebSerial> {
|
||||
await port.open({ baudRate: baudRate || 115200 });
|
||||
return new TransportWebSerial(port);
|
||||
}
|
||||
public static async createFromPort(
|
||||
port: SerialPort,
|
||||
baudRate?: number,
|
||||
): Promise<TransportWebSerial> {
|
||||
await port.open({ baudRate: baudRate || 115200 });
|
||||
return new TransportWebSerial(port);
|
||||
}
|
||||
|
||||
constructor(connection: SerialPort) {
|
||||
if (!connection.readable || !connection.writable) {
|
||||
throw new Error("Stream not accessible");
|
||||
}
|
||||
constructor(connection: SerialPort) {
|
||||
if (!connection.readable || !connection.writable) {
|
||||
throw new Error("Stream not accessible");
|
||||
}
|
||||
|
||||
Utils.toDeviceStream.readable.pipeTo(connection.writable);
|
||||
Utils.toDeviceStream.readable.pipeTo(connection.writable);
|
||||
|
||||
this._toDevice = Utils.toDeviceStream.writable;
|
||||
this._fromDevice = connection.readable.pipeThrough(
|
||||
Utils.fromDeviceStream(),
|
||||
);
|
||||
}
|
||||
this._toDevice = Utils.toDeviceStream.writable;
|
||||
this._fromDevice = connection.readable.pipeThrough(
|
||||
Utils.fromDeviceStream(),
|
||||
);
|
||||
}
|
||||
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-20
@@ -18,23 +18,6 @@ or served from a node
|
||||
|
||||

|
||||
|
||||
## Progress Web App Support (PWA)
|
||||
|
||||
Meshtastic Web Client now includes Progressive Web App (PWA) functionality,
|
||||
allowing users to:
|
||||
|
||||
- Install the app on desktop and mobile devices
|
||||
- Access the interface offline
|
||||
- Receive updates automatically
|
||||
- Experience faster load times with caching
|
||||
|
||||
To install as a PWA:
|
||||
|
||||
- On desktop: Look for the install icon in your browser's address bar
|
||||
- On mobile: Use "Add to Home Screen" option in your browser menu
|
||||
|
||||
PWA functionality works with both the hosted version and self-hosted instances.
|
||||
|
||||
## Self-host
|
||||
|
||||
The client can be self hosted using the precompiled container images with an OCI
|
||||
@@ -56,7 +39,7 @@ Our release process follows these guidelines:
|
||||
|
||||
- **Versioning:** We use Semantic Versioning (`Major.Minor.Patch`).
|
||||
- **Stable Releases:** Published around the beginning of each month (e.g.,
|
||||
`v2.3.4`).
|
||||
`v2.6.1`).
|
||||
- **Pre-releases:** A pre-release is typically issued mid-month for testing and
|
||||
early adoption.
|
||||
- **Nightly Builds:** An experimental Docker image containing the latest
|
||||
@@ -106,6 +89,7 @@ instructions listed on the home page.
|
||||
Install the dependencies.
|
||||
|
||||
```bash
|
||||
cd packages/web &&
|
||||
bun install
|
||||
```
|
||||
|
||||
@@ -141,8 +125,6 @@ reasons:
|
||||
configuration, enhancing code quality and developer experience.
|
||||
- **Modern JavaScript**: First-class support for ESM imports, top-level await,
|
||||
and other modern JavaScript features.
|
||||
- **All-in-One Tooling**: Built-in package manager, bundler, test runner, and
|
||||
transpiler eliminate the need for multiple third-party tools.
|
||||
- **Node.js Compatibility**: Drop-in replacement for Node.js with better
|
||||
performance and built-in tooling.
|
||||
- **Reproducible Builds**: Lockfile ensures consistent builds across all
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
|
||||
"files": {
|
||||
"includes": ["**", "!node_modules/**", "!**/*.css", "!dist/**", "!build/**", "!coverage/**", "!**/*.d.ts"],
|
||||
"ignoreUnknown": false
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"formatWithErrors": false,
|
||||
"indentStyle": "space",
|
||||
"indentWidth": 2,
|
||||
"lineWidth": 80,
|
||||
"attributePosition": "auto"
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true,
|
||||
"suspicious": {
|
||||
"noExplicitAny": "error",
|
||||
"noDebugger": "error"
|
||||
},
|
||||
"style": {
|
||||
"useConst": "error",
|
||||
"useBlockStatements": "error",
|
||||
"useSingleVarDeclarator": "off"
|
||||
},
|
||||
"complexity": {
|
||||
"noForEach": "off"
|
||||
},
|
||||
"correctness": {
|
||||
"noUnusedVariables": "error",
|
||||
"noUnusedImports": "error"
|
||||
}
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"quoteStyle": "double",
|
||||
"semicolons": "always"
|
||||
}
|
||||
},
|
||||
"json": {
|
||||
"formatter": {
|
||||
"indentStyle": "space",
|
||||
"indentWidth": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,7 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/meshtastic/web/issues"
|
||||
},
|
||||
"simple-git-hooks": {
|
||||
"pre-commit": "bun run check:fix"
|
||||
},
|
||||
|
||||
"homepage": "https://meshtastic.org",
|
||||
"scripts": {
|
||||
"build": "bunx --bun vite build",
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Avatar } from "@components/UI/Avatar.tsx";
|
||||
import {
|
||||
CommandDialog,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
CommandDialog,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from "@components/UI/Command.tsx";
|
||||
import { usePinnedItems } from "@core/hooks/usePinnedItems.ts";
|
||||
import { useAppStore } from "@core/stores/appStore.ts";
|
||||
@@ -14,345 +14,345 @@ import { cn } from "@core/utils/cn.ts";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { useCommandState } from "cmdk";
|
||||
import {
|
||||
ArrowLeftRightIcon,
|
||||
BoxSelectIcon,
|
||||
BugIcon,
|
||||
CloudOff,
|
||||
EraserIcon,
|
||||
FactoryIcon,
|
||||
LayersIcon,
|
||||
LinkIcon,
|
||||
type LucideIcon,
|
||||
MapIcon,
|
||||
MessageSquareIcon,
|
||||
Pin,
|
||||
PlusIcon,
|
||||
PowerIcon,
|
||||
QrCodeIcon,
|
||||
RefreshCwIcon,
|
||||
SettingsIcon,
|
||||
SmartphoneIcon,
|
||||
TrashIcon,
|
||||
UsersIcon,
|
||||
ArrowLeftRightIcon,
|
||||
BoxSelectIcon,
|
||||
BugIcon,
|
||||
CloudOff,
|
||||
EraserIcon,
|
||||
FactoryIcon,
|
||||
LayersIcon,
|
||||
LinkIcon,
|
||||
type LucideIcon,
|
||||
MapIcon,
|
||||
MessageSquareIcon,
|
||||
Pin,
|
||||
PlusIcon,
|
||||
PowerIcon,
|
||||
QrCodeIcon,
|
||||
RefreshCwIcon,
|
||||
SettingsIcon,
|
||||
SmartphoneIcon,
|
||||
TrashIcon,
|
||||
UsersIcon,
|
||||
} from "lucide-react";
|
||||
import { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
export interface Group {
|
||||
id: string;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
commands: Command[];
|
||||
id: string;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
commands: Command[];
|
||||
}
|
||||
export interface Command {
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
action?: () => void;
|
||||
subItems?: SubItem[];
|
||||
tags?: string[];
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
action?: () => void;
|
||||
subItems?: SubItem[];
|
||||
tags?: string[];
|
||||
}
|
||||
export interface SubItem {
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
action: () => void;
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
action: () => void;
|
||||
}
|
||||
|
||||
export const CommandPalette = () => {
|
||||
const {
|
||||
commandPaletteOpen,
|
||||
setCommandPaletteOpen,
|
||||
setConnectDialogOpen,
|
||||
setSelectedDevice,
|
||||
} = useAppStore();
|
||||
const { getDevices } = useDeviceStore();
|
||||
const { setDialogOpen, getNode, connection } = useDevice();
|
||||
const { pinnedItems, togglePinnedItem } = usePinnedItems({
|
||||
storageName: "pinnedCommandMenuGroups",
|
||||
});
|
||||
const { t } = useTranslation("commandPalette");
|
||||
const navigate = useNavigate({ from: "/" });
|
||||
const {
|
||||
commandPaletteOpen,
|
||||
setCommandPaletteOpen,
|
||||
setConnectDialogOpen,
|
||||
setSelectedDevice,
|
||||
} = useAppStore();
|
||||
const { getDevices } = useDeviceStore();
|
||||
const { setDialogOpen, getNode, connection } = useDevice();
|
||||
const { pinnedItems, togglePinnedItem } = usePinnedItems({
|
||||
storageName: "pinnedCommandMenuGroups",
|
||||
});
|
||||
const { t } = useTranslation("commandPalette");
|
||||
const navigate = useNavigate({ from: "/" });
|
||||
|
||||
const groups: Group[] = [
|
||||
{
|
||||
id: "gotoGroup",
|
||||
label: t("goto.label"),
|
||||
icon: LinkIcon,
|
||||
commands: [
|
||||
{
|
||||
label: t("goto.command.messages"),
|
||||
icon: MessageSquareIcon,
|
||||
action() {
|
||||
navigate({ to: "/messages" });
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("goto.command.map"),
|
||||
icon: MapIcon,
|
||||
action() {
|
||||
navigate({ to: "/map" });
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("goto.command.config"),
|
||||
icon: SettingsIcon,
|
||||
action() {
|
||||
navigate({ to: "/config" });
|
||||
},
|
||||
tags: ["settings"],
|
||||
},
|
||||
{
|
||||
label: t("goto.command.channels"),
|
||||
icon: LayersIcon,
|
||||
action() {
|
||||
navigate({ to: "/channels" });
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("goto.command.nodes"),
|
||||
icon: UsersIcon,
|
||||
action() {
|
||||
navigate({ to: "/nodes" });
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "manageGroup",
|
||||
label: t("manage.label"),
|
||||
icon: SmartphoneIcon,
|
||||
commands: [
|
||||
{
|
||||
label: t("manage.command.switchNode"),
|
||||
icon: ArrowLeftRightIcon,
|
||||
subItems: getDevices().map((device) => ({
|
||||
label:
|
||||
getNode(device.hardware.myNodeNum)?.user?.longName ??
|
||||
t("unknown.shortName"),
|
||||
icon: (
|
||||
<Avatar
|
||||
text={
|
||||
getNode(device.hardware.myNodeNum)?.user?.shortName ??
|
||||
t("unknown.shortName")
|
||||
}
|
||||
/>
|
||||
),
|
||||
action() {
|
||||
setSelectedDevice(device.id);
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
label: t("manage.command.connectNewNode"),
|
||||
icon: PlusIcon,
|
||||
action() {
|
||||
setConnectDialogOpen(true);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "contextualGroup",
|
||||
label: t("contextual.label"),
|
||||
icon: BoxSelectIcon,
|
||||
commands: [
|
||||
{
|
||||
label: t("contextual.command.qrCode"),
|
||||
icon: QrCodeIcon,
|
||||
subItems: [
|
||||
{
|
||||
label: t("contextual.command.qrGenerator"),
|
||||
icon: <QrCodeIcon size={16} />,
|
||||
action() {
|
||||
setDialogOpen("QR", true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.qrImport"),
|
||||
icon: <QrCodeIcon size={16} />,
|
||||
action() {
|
||||
setDialogOpen("import", true);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.scheduleShutdown"),
|
||||
icon: PowerIcon,
|
||||
action() {
|
||||
setDialogOpen("shutdown", true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.scheduleReboot"),
|
||||
icon: RefreshCwIcon,
|
||||
action() {
|
||||
setDialogOpen("reboot", true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.rebootToOtaMode"),
|
||||
icon: RefreshCwIcon,
|
||||
action() {
|
||||
setDialogOpen("rebootOTA", true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.resetNodeDb"),
|
||||
icon: TrashIcon,
|
||||
action() {
|
||||
connection?.resetNodes();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.disconnect"),
|
||||
icon: CloudOff,
|
||||
action() {
|
||||
connection?.disconnect().catch((error) => {
|
||||
console.error("Failed to disconnect:", error);
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.factoryResetDevice"),
|
||||
icon: FactoryIcon,
|
||||
action() {
|
||||
connection?.factoryResetDevice();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.factoryResetConfig"),
|
||||
icon: FactoryIcon,
|
||||
action() {
|
||||
connection?.factoryResetConfig();
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "debugGroup",
|
||||
label: t("debug.label"),
|
||||
icon: BugIcon,
|
||||
commands: [
|
||||
{
|
||||
label: t("debug.command.reconfigure"),
|
||||
icon: RefreshCwIcon,
|
||||
action() {
|
||||
void connection?.configure();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("debug.command.clearAllStoredMessages"),
|
||||
icon: EraserIcon,
|
||||
action() {
|
||||
setDialogOpen("deleteMessages", true);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
const groups: Group[] = [
|
||||
{
|
||||
id: "gotoGroup",
|
||||
label: t("goto.label"),
|
||||
icon: LinkIcon,
|
||||
commands: [
|
||||
{
|
||||
label: t("goto.command.messages"),
|
||||
icon: MessageSquareIcon,
|
||||
action() {
|
||||
navigate({ to: "/messages" });
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("goto.command.map"),
|
||||
icon: MapIcon,
|
||||
action() {
|
||||
navigate({ to: "/map" });
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("goto.command.config"),
|
||||
icon: SettingsIcon,
|
||||
action() {
|
||||
navigate({ to: "/config" });
|
||||
},
|
||||
tags: ["settings"],
|
||||
},
|
||||
{
|
||||
label: t("goto.command.channels"),
|
||||
icon: LayersIcon,
|
||||
action() {
|
||||
navigate({ to: "/channels" });
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("goto.command.nodes"),
|
||||
icon: UsersIcon,
|
||||
action() {
|
||||
navigate({ to: "/nodes" });
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "manageGroup",
|
||||
label: t("manage.label"),
|
||||
icon: SmartphoneIcon,
|
||||
commands: [
|
||||
{
|
||||
label: t("manage.command.switchNode"),
|
||||
icon: ArrowLeftRightIcon,
|
||||
subItems: getDevices().map((device) => ({
|
||||
label:
|
||||
getNode(device.hardware.myNodeNum)?.user?.longName ??
|
||||
t("unknown.shortName"),
|
||||
icon: (
|
||||
<Avatar
|
||||
text={
|
||||
getNode(device.hardware.myNodeNum)?.user?.shortName ??
|
||||
t("unknown.shortName")
|
||||
}
|
||||
/>
|
||||
),
|
||||
action() {
|
||||
setSelectedDevice(device.id);
|
||||
},
|
||||
})),
|
||||
},
|
||||
{
|
||||
label: t("manage.command.connectNewNode"),
|
||||
icon: PlusIcon,
|
||||
action() {
|
||||
setConnectDialogOpen(true);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "contextualGroup",
|
||||
label: t("contextual.label"),
|
||||
icon: BoxSelectIcon,
|
||||
commands: [
|
||||
{
|
||||
label: t("contextual.command.qrCode"),
|
||||
icon: QrCodeIcon,
|
||||
subItems: [
|
||||
{
|
||||
label: t("contextual.command.qrGenerator"),
|
||||
icon: <QrCodeIcon size={16} />,
|
||||
action() {
|
||||
setDialogOpen("QR", true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.qrImport"),
|
||||
icon: <QrCodeIcon size={16} />,
|
||||
action() {
|
||||
setDialogOpen("import", true);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.scheduleShutdown"),
|
||||
icon: PowerIcon,
|
||||
action() {
|
||||
setDialogOpen("shutdown", true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.scheduleReboot"),
|
||||
icon: RefreshCwIcon,
|
||||
action() {
|
||||
setDialogOpen("reboot", true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.rebootToOtaMode"),
|
||||
icon: RefreshCwIcon,
|
||||
action() {
|
||||
setDialogOpen("rebootOTA", true);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.resetNodeDb"),
|
||||
icon: TrashIcon,
|
||||
action() {
|
||||
connection?.resetNodes();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.disconnect"),
|
||||
icon: CloudOff,
|
||||
action() {
|
||||
connection?.disconnect().catch((error) => {
|
||||
console.error("Failed to disconnect:", error);
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.factoryResetDevice"),
|
||||
icon: FactoryIcon,
|
||||
action() {
|
||||
connection?.factoryResetDevice();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("contextual.command.factoryResetConfig"),
|
||||
icon: FactoryIcon,
|
||||
action() {
|
||||
connection?.factoryResetConfig();
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "debugGroup",
|
||||
label: t("debug.label"),
|
||||
icon: BugIcon,
|
||||
commands: [
|
||||
{
|
||||
label: t("debug.command.reconfigure"),
|
||||
icon: RefreshCwIcon,
|
||||
action() {
|
||||
void connection?.configure();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: t("debug.command.clearAllStoredMessages"),
|
||||
icon: EraserIcon,
|
||||
action() {
|
||||
setDialogOpen("deleteMessages", true);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const sortedGroups = [...groups].sort((a, b) => {
|
||||
const aPinned = pinnedItems.includes(a.id) ? 1 : 0;
|
||||
const bPinned = pinnedItems.includes(b.id) ? 1 : 0;
|
||||
return bPinned - aPinned;
|
||||
});
|
||||
const sortedGroups = [...groups].sort((a, b) => {
|
||||
const aPinned = pinnedItems.includes(a.id) ? 1 : 0;
|
||||
const bPinned = pinnedItems.includes(b.id) ? 1 : 0;
|
||||
return bPinned - aPinned;
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeydown = (e: KeyboardEvent) => {
|
||||
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
|
||||
e.preventDefault();
|
||||
setCommandPaletteOpen(true);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
const handleKeydown = (e: KeyboardEvent) => {
|
||||
if (e.key === "k" && (e.metaKey || e.ctrlKey)) {
|
||||
e.preventDefault();
|
||||
setCommandPaletteOpen(true);
|
||||
}
|
||||
};
|
||||
|
||||
globalThis.addEventListener("keydown", handleKeydown);
|
||||
return () => globalThis.removeEventListener("keydown", handleKeydown);
|
||||
}, [setCommandPaletteOpen]);
|
||||
globalThis.addEventListener("keydown", handleKeydown);
|
||||
return () => globalThis.removeEventListener("keydown", handleKeydown);
|
||||
}, [setCommandPaletteOpen]);
|
||||
|
||||
return (
|
||||
<CommandDialog
|
||||
open={commandPaletteOpen}
|
||||
onOpenChange={setCommandPaletteOpen}
|
||||
>
|
||||
<CommandInput placeholder={t("search.commandPalette")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("emptyState")}</CommandEmpty>
|
||||
{sortedGroups.map((group) => (
|
||||
<CommandGroup
|
||||
key={group.label}
|
||||
heading={
|
||||
<div className="flex items-center justify-between">
|
||||
<span>{group.label}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => togglePinnedItem(group.id)}
|
||||
className={cn(
|
||||
"transition-all duration-300 scale-100 cursor-pointer p-2 focus:*:data-label:opacity-100",
|
||||
)}
|
||||
>
|
||||
<span
|
||||
data-label
|
||||
className="transition-all block absolute w-full mb-auto mt-auto ml-0 mr-0 text-xs left-0 -top-5 opacity-0 rounded-lg"
|
||||
/>
|
||||
<Pin
|
||||
size={16}
|
||||
className={cn(
|
||||
"transition-opacity",
|
||||
pinnedItems.includes(group.id)
|
||||
? "opacity-100 text-red-500"
|
||||
: "opacity-40 hover:opacity-70",
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{group.commands.map((command) => (
|
||||
<div key={command.label}>
|
||||
<CommandItem
|
||||
onSelect={() => {
|
||||
command.action?.();
|
||||
setCommandPaletteOpen(false);
|
||||
}}
|
||||
>
|
||||
<command.icon size={16} className="mr-2" />
|
||||
{command.label}
|
||||
</CommandItem>
|
||||
{command.subItems?.map((subItem) => (
|
||||
<SubItem
|
||||
key={subItem.label}
|
||||
label={subItem.label}
|
||||
icon={subItem.icon}
|
||||
action={subItem.action}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</CommandGroup>
|
||||
))}
|
||||
</CommandList>
|
||||
</CommandDialog>
|
||||
);
|
||||
return (
|
||||
<CommandDialog
|
||||
open={commandPaletteOpen}
|
||||
onOpenChange={setCommandPaletteOpen}
|
||||
>
|
||||
<CommandInput placeholder={t("search.commandPalette")} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{t("emptyState")}</CommandEmpty>
|
||||
{sortedGroups.map((group) => (
|
||||
<CommandGroup
|
||||
key={group.label}
|
||||
heading={
|
||||
<div className="flex items-center justify-between">
|
||||
<span>{group.label}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => togglePinnedItem(group.id)}
|
||||
className={cn(
|
||||
"transition-all duration-300 scale-100 cursor-pointer p-2 focus:*:data-label:opacity-100",
|
||||
)}
|
||||
>
|
||||
<span
|
||||
data-label
|
||||
className="transition-all block absolute w-full mb-auto mt-auto ml-0 mr-0 text-xs left-0 -top-5 opacity-0 rounded-lg"
|
||||
/>
|
||||
<Pin
|
||||
size={16}
|
||||
className={cn(
|
||||
"transition-opacity",
|
||||
pinnedItems.includes(group.id)
|
||||
? "opacity-100 text-red-500"
|
||||
: "opacity-40 hover:opacity-70",
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{group.commands.map((command) => (
|
||||
<div key={command.label}>
|
||||
<CommandItem
|
||||
onSelect={() => {
|
||||
command.action?.();
|
||||
setCommandPaletteOpen(false);
|
||||
}}
|
||||
>
|
||||
<command.icon size={16} className="mr-2" />
|
||||
{command.label}
|
||||
</CommandItem>
|
||||
{command.subItems?.map((subItem) => (
|
||||
<SubItem
|
||||
key={subItem.label}
|
||||
label={subItem.label}
|
||||
icon={subItem.icon}
|
||||
action={subItem.action}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
))}
|
||||
</CommandGroup>
|
||||
))}
|
||||
</CommandList>
|
||||
</CommandDialog>
|
||||
);
|
||||
};
|
||||
|
||||
const SubItem = ({
|
||||
label,
|
||||
icon,
|
||||
action,
|
||||
label,
|
||||
icon,
|
||||
action,
|
||||
}: {
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
action: () => void;
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
action: () => void;
|
||||
}) => {
|
||||
const search = useCommandState((state) => state.search);
|
||||
if (!search) {
|
||||
return null;
|
||||
}
|
||||
const search = useCommandState((state) => state.search);
|
||||
if (!search) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<CommandItem onSelect={action}>
|
||||
{icon}
|
||||
{label}
|
||||
</CommandItem>
|
||||
);
|
||||
return (
|
||||
<CommandItem onSelect={action}>
|
||||
{icon}
|
||||
{label}
|
||||
</CommandItem>
|
||||
);
|
||||
};
|
||||
|
||||
Vendored
+4
-4
@@ -1,11 +1,11 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly env: {
|
||||
readonly VITE_COMMIT_HASH: string;
|
||||
};
|
||||
readonly env: {
|
||||
readonly VITE_COMMIT_HASH: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
|
||||
+46
-46
@@ -7,56 +7,56 @@ import { defineConfig } from "vite";
|
||||
|
||||
let hash = "";
|
||||
try {
|
||||
hash = execSync("git rev-parse --short HEAD", { encoding: "utf8" }).trim();
|
||||
hash = execSync("git rev-parse --short HEAD", { encoding: "utf8" }).trim();
|
||||
} catch (error) {
|
||||
console.error("Error getting git hash:", error);
|
||||
hash = "DEV";
|
||||
console.error("Error getting git hash:", error);
|
||||
hash = "DEV";
|
||||
}
|
||||
|
||||
const CONTENT_SECURITY_POLICY =
|
||||
"script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' data: https://rsms.me https://cdn.jsdelivr.net; img-src 'self' data:; font-src 'self' data: https://rsms.me https://cdn.jsdelivr.net; worker-src 'self' blob:; object-src 'none'; base-uri 'self';";
|
||||
"script-src 'self' 'unsafe-inline' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline' data: https://rsms.me https://cdn.jsdelivr.net; img-src 'self' data:; font-src 'self' data: https://rsms.me https://cdn.jsdelivr.net; worker-src 'self' blob:; object-src 'none'; base-uri 'self';";
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
react(),
|
||||
tailwindcss(),
|
||||
// VitePWA({
|
||||
// registerType: "autoUpdate",
|
||||
// strategies: "generateSW",
|
||||
// devOptions: {
|
||||
// enabled: true,
|
||||
// },
|
||||
// workbox: {
|
||||
// cleanupOutdatedCaches: true,
|
||||
// sourcemap: true,
|
||||
// },
|
||||
// }),
|
||||
],
|
||||
optimizeDeps: {
|
||||
include: ["react/jsx-runtime"],
|
||||
},
|
||||
define: {
|
||||
"import.meta.env.VITE_COMMIT_HASH": JSON.stringify(hash),
|
||||
},
|
||||
build: {
|
||||
emptyOutDir: true,
|
||||
assetsDir: "./",
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"@app": path.resolve(process.cwd(), "./src"),
|
||||
"@pages": path.resolve(process.cwd(), "./src/pages"),
|
||||
"@components": path.resolve(process.cwd(), "./src/components"),
|
||||
"@core": path.resolve(process.cwd(), "./src/core"),
|
||||
"@layouts": path.resolve(process.cwd(), "./src/layouts"),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 3000,
|
||||
headers: {
|
||||
"content-security-policy": CONTENT_SECURITY_POLICY,
|
||||
"Cross-Origin-Opener-Policy": "same-origin",
|
||||
"Cross-Origin-Embedder-Policy": "require-corp",
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
react(),
|
||||
tailwindcss(),
|
||||
// VitePWA({
|
||||
// registerType: "autoUpdate",
|
||||
// strategies: "generateSW",
|
||||
// devOptions: {
|
||||
// enabled: true,
|
||||
// },
|
||||
// workbox: {
|
||||
// cleanupOutdatedCaches: true,
|
||||
// sourcemap: true,
|
||||
// },
|
||||
// }),
|
||||
],
|
||||
optimizeDeps: {
|
||||
include: ["react/jsx-runtime"],
|
||||
},
|
||||
define: {
|
||||
"import.meta.env.VITE_COMMIT_HASH": JSON.stringify(hash),
|
||||
},
|
||||
build: {
|
||||
emptyOutDir: true,
|
||||
assetsDir: "./",
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
"@app": path.resolve(process.cwd(), "./src"),
|
||||
"@pages": path.resolve(process.cwd(), "./src/pages"),
|
||||
"@components": path.resolve(process.cwd(), "./src/components"),
|
||||
"@core": path.resolve(process.cwd(), "./src/core"),
|
||||
"@layouts": path.resolve(process.cwd(), "./src/layouts"),
|
||||
},
|
||||
},
|
||||
server: {
|
||||
port: 3000,
|
||||
headers: {
|
||||
"content-security-policy": CONTENT_SECURITY_POLICY,
|
||||
"Cross-Origin-Opener-Policy": "same-origin",
|
||||
"Cross-Origin-Embedder-Policy": "require-corp",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -7,25 +7,25 @@ import { enableMapSet } from "immer";
|
||||
|
||||
enableMapSet();
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@app": path.resolve(process.cwd(), "./src"),
|
||||
"@public": path.resolve(process.cwd(), "./public"),
|
||||
"@core": path.resolve(process.cwd(), "./src/core"),
|
||||
"@pages": path.resolve(process.cwd(), "./src/pages"),
|
||||
"@components": path.resolve(process.cwd(), "./src/components"),
|
||||
"@layouts": path.resolve(process.cwd(), "./src/layouts"),
|
||||
},
|
||||
},
|
||||
test: {
|
||||
environment: "happy-dom",
|
||||
globals: true,
|
||||
mockReset: true,
|
||||
clearMocks: true,
|
||||
restoreMocks: true,
|
||||
root: path.resolve(process.cwd(), "./src"),
|
||||
include: ["**/*.{test,spec}.{ts,tsx}"],
|
||||
setupFiles: ["./src/tests/setup.ts"],
|
||||
},
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
alias: {
|
||||
"@app": path.resolve(process.cwd(), "./src"),
|
||||
"@public": path.resolve(process.cwd(), "./public"),
|
||||
"@core": path.resolve(process.cwd(), "./src/core"),
|
||||
"@pages": path.resolve(process.cwd(), "./src/pages"),
|
||||
"@components": path.resolve(process.cwd(), "./src/components"),
|
||||
"@layouts": path.resolve(process.cwd(), "./src/layouts"),
|
||||
},
|
||||
},
|
||||
test: {
|
||||
environment: "happy-dom",
|
||||
globals: true,
|
||||
mockReset: true,
|
||||
clearMocks: true,
|
||||
restoreMocks: true,
|
||||
root: path.resolve(process.cwd(), "./src"),
|
||||
include: ["**/*.{test,spec}.{ts,tsx}"],
|
||||
setupFiles: ["./src/tests/setup.ts"],
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user