diff --git a/README.md b/README.md index c418bbf..50043ac 100755 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ pnpm build Optionally the doccumentation can be built with: ```bash -pnpm generate:docs +pnpm docs ``` ### Compatibility diff --git a/package.json b/package.json index dffadba..a4e5f74 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "@meshtastic/meshtasticjs", - "version": "2.1.20-0", + "version": "2.1.20-1", "description": "Browser library for interfacing with meshtastic devices", "license": "GPL-3.0-only", "scripts": { "build": "tsc", "watch": "tsc -w", - "generate:docs": "typedoc src/index.ts" + "check": "rome check .", + "docs": "typedoc src/index.ts" }, "keywords": [ "meshtastic bluetooth serial webserial webbluetooth ble http library meshtasticjs" diff --git a/rome.json b/rome.json index 2766ee5..1f5dbcd 100644 --- a/rome.json +++ b/rome.json @@ -13,5 +13,11 @@ }, "organizeImports": { "enabled": true + }, + "files": { + "ignore": [ + "node_modules", + "dist" + ] } } \ No newline at end of file diff --git a/src/adapters/iBleConnection.ts b/src/adapters/iBleConnection.ts index e94adba..808ff61 100755 --- a/src/adapters/iBleConnection.ts +++ b/src/adapters/iBleConnection.ts @@ -1,4 +1,3 @@ -import { Types } from "../index.js"; import { fromNumUUID, fromRadioUUID, @@ -6,6 +5,7 @@ import { toRadioUUID, } from "../constants.js"; import { IMeshDevice } from "../iMeshDevice.js"; +import { Types } from "../index.js"; import { typedArrayToBuffer } from "../utils/general.js"; /** Allows to connect to a Meshtastic device via bluetooth */ diff --git a/src/adapters/iHttpConnection.ts b/src/adapters/iHttpConnection.ts index 6678edb..56a3b6f 100755 --- a/src/adapters/iHttpConnection.ts +++ b/src/adapters/iHttpConnection.ts @@ -1,5 +1,5 @@ -import { Types } from "../index.js"; import { IMeshDevice } from "../iMeshDevice.js"; +import { Types } from "../index.js"; import { typedArrayToBuffer } from "../utils/general.js"; /** Allows to connect to a Meshtastic device over HTTP(S) */ diff --git a/src/adapters/iSerialConnection.ts b/src/adapters/iSerialConnection.ts index d6fe784..cd8874f 100644 --- a/src/adapters/iSerialConnection.ts +++ b/src/adapters/iSerialConnection.ts @@ -1,7 +1,7 @@ import { SubEvent } from "sub-events"; -import { Types } from "../index.js"; import { IMeshDevice } from "../iMeshDevice.js"; +import { Types } from "../index.js"; import { transformHandler } from "../utils/transformHandler.js"; /** Allows to connect to a Meshtastic device over WebSerial */ @@ -11,7 +11,7 @@ export class ISerialConnection extends IMeshDevice { /** Serial port used to communicate with device. */ private port: SerialPort | undefined; - private readerHack: ReadableStreamDefaultReader | undefined; + private readerHack: ReadableStreamDefaultReader | undefined; /** Transform stream for parsing raw serial data */ private transformer?: TransformStream; @@ -55,9 +55,9 @@ export class ISerialConnection extends IMeshDevice { ): Promise { this.onReleaseEvent.subscribe(async () => { this.preventLock = true; - await reader.cancel(); - await this.pipePromise?.catch(() => {}); - reader.releaseLock(); + await reader.cancel(); + await this.pipePromise?.catch(() => {}); + reader.releaseLock(); await this.port?.close(); }); @@ -72,9 +72,8 @@ export class ISerialConnection extends IMeshDevice { .catch(() => { this.log.debug( Types.Emitter[Types.Emitter.readFromRadio], - `Releasing reader`, + "Releasing reader", ); - ("Releasing reader"); }); } } @@ -134,8 +133,11 @@ export class ISerialConnection extends IMeshDevice { concurrentLogOutput, ); - this.pipePromise = this.port.readable.pipeTo(this.transformer.writable); - const reader = this.readerHack = this.transformer.readable.getReader(); + this.pipePromise = this.port.readable.pipeTo( + this.transformer.writable, + ); + const reader = (this.readerHack = + this.transformer.readable.getReader()); void this.readFromRadio(reader); this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_CONNECTED); @@ -166,10 +168,10 @@ export class ISerialConnection extends IMeshDevice { // HACK: Inline onReleaseEvent // -- This should be used as an event, like intened this.preventLock = true; - await this.readerHack?.cancel(); - await this.pipePromise?.catch(() => {}); - this.readerHack?.releaseLock(); - if(this.port?.readable) await this.port?.close(); + await this.readerHack?.cancel(); + await this.pipePromise?.catch(() => {}); + this.readerHack?.releaseLock(); + if (this.port?.readable) await this.port?.close(); // ------- this.updateDeviceStatus(Types.DeviceStatusEnum.DEVICE_DISCONNECTED); this.complete(); diff --git a/src/client.ts b/src/client.ts index d708a2e..8036a11 100755 --- a/src/client.ts +++ b/src/client.ts @@ -1,7 +1,7 @@ import { IBLEConnection } from "./adapters/iBleConnection.js"; import { IHTTPConnection } from "./adapters/iHttpConnection.js"; -import { Types } from "./index.js"; import { ISerialConnection } from "./adapters/iSerialConnection.js"; +import { Types } from "./index.js"; /** * Allows to create new connections to devices and manages them. Alternatively, diff --git a/src/iMeshDevice.ts b/src/iMeshDevice.ts index 56fd4b5..1bb8a2e 100755 --- a/src/iMeshDevice.ts +++ b/src/iMeshDevice.ts @@ -230,7 +230,7 @@ export abstract class IMeshDevice { public async setConfig(config: Protobuf.Config): Promise { this.log.debug( Types.Emitter[Types.Emitter.setConfig], - `Setting config, Variant: ${config.payloadVariant.case ?? "Unknown"}`, + `⚙️ Setting config, Variant: ${config.payloadVariant.case ?? "Unknown"}`, ); if (!this.pendingSettingsChanges) { @@ -259,7 +259,7 @@ export abstract class IMeshDevice { ): Promise { this.log.debug( Types.Emitter[Types.Emitter.setModuleConfig], - "Setting module config", + "⚙️ Setting module config", ); const moduleConfigMessage = new Protobuf.AdminMessage({ @@ -280,7 +280,7 @@ export abstract class IMeshDevice { * Sets devices owner data */ public async setOwner(owner: Protobuf.User): Promise { - this.log.debug(Types.Emitter[Types.Emitter.setOwner], "Setting owner"); + this.log.debug(Types.Emitter[Types.Emitter.setOwner], "👤 Setting owner"); const setOwnerMessage = new Protobuf.AdminMessage({ payloadVariant: { @@ -359,7 +359,10 @@ export abstract class IMeshDevice { public async getConfig( configType: Protobuf.AdminMessage_ConfigType, ): Promise { - this.log.debug(Types.Emitter[Types.Emitter.getConfig], "Requesting config"); + this.log.debug( + Types.Emitter[Types.Emitter.getConfig], + "⚙️ Requesting config", + ); const getRadioRequestMessage = new Protobuf.AdminMessage({ payloadVariant: { @@ -383,7 +386,7 @@ export abstract class IMeshDevice { ): Promise { this.log.debug( Types.Emitter[Types.Emitter.getModuleConfig], - "Requesting module config", + "⚙️ Requesting module config", ); const getRadioRequestMessage = new Protobuf.AdminMessage({ @@ -402,7 +405,10 @@ export abstract class IMeshDevice { /** Gets devices Owner */ public async getOwner(): Promise { - this.log.debug(Types.Emitter[Types.Emitter.getOwner], "Requesting owner"); + this.log.debug( + Types.Emitter[Types.Emitter.getOwner], + "👤 Requesting owner", + ); const getOwnerRequestMessage = new Protobuf.AdminMessage({ payloadVariant: { @@ -424,7 +430,7 @@ export abstract class IMeshDevice { public async getMetadata(nodeNum: number): Promise { this.log.debug( Types.Emitter[Types.Emitter.getMetadata], - `Requesting metadata from ${nodeNum}`, + `🏷️ Requesting metadata from ${nodeNum}`, ); const getDeviceMetricsRequestMessage = new Protobuf.AdminMessage({ @@ -879,7 +885,7 @@ export abstract class IMeshDevice { case "encrypted": this.log.debug( Types.Emitter[Types.Emitter.handleMeshPacket], - "Device received encrypted data packet, ignoring.", + "🔐 Device received encrypted data packet, ignoring.", ); break; } diff --git a/src/index.ts b/src/index.ts index 6bf6730..ab6eac5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ -import { Client } from "./client.js"; -import { IMeshDevice } from "./iMeshDevice.js"; import { IBLEConnection } from "./adapters/iBleConnection.js"; import { IHTTPConnection } from "./adapters/iHttpConnection.js"; import { ISerialConnection } from "./adapters/iSerialConnection.js"; +import { Client } from "./client.js"; +import * as Constants from "./constants.js"; +import { IMeshDevice } from "./iMeshDevice.js"; import * as Protobuf from "./protobufs.js"; import * as Types from "./types.js"; -import * as Constants from "./constants.js"; export { Client, diff --git a/src/types.ts b/src/types.ts index 49bc2b0..491a217 100644 --- a/src/types.ts +++ b/src/types.ts @@ -6,13 +6,13 @@ import type { } from "./index.js"; export enum DeviceStatusEnum { - DEVICE_RESTARTING, - DEVICE_DISCONNECTED, - DEVICE_CONNECTING, - DEVICE_RECONNECTING, - DEVICE_CONNECTED, - DEVICE_CONFIGURING, - DEVICE_CONFIGURED, + DEVICE_RESTARTING = 1, + DEVICE_DISCONNECTED = 2, + DEVICE_CONNECTING = 3, + DEVICE_RECONNECTING = 4, + DEVICE_CONNECTED = 5, + DEVICE_CONFIGURING = 6, + DEVICE_CONFIGURED = 7, } export type ConnectionParameters = @@ -66,45 +66,45 @@ export interface PacketMetadata { } export enum EmitterScope { - iMeshDevice, - iSerialConnection, - iNodeSerialConnection, - iBleConnection, - iHttpConnection, + iMeshDevice = 1, + iSerialConnection = 2, + iNodeSerialConnection = 3, + iBleConnection = 4, + iHttpConnection = 5, } export enum Emitter { - constructor, - sendText, - sendWaypoint, - sendPacket, - sendRaw, - setConfig, - setModuleConfig, - confirmSetConfig, - setOwner, - setChannel, - confirmSetChannel, - clearChannel, - getChannel, - getAllChannels, - getConfig, - getModuleConfig, - getOwner, - configure, - handleFromRadio, - handleMeshPacket, - connect, - ping, - readFromRadio, - writeToRadio, - setDebugMode, - getMetadata, - resetPeers, - shutdown, - reboot, - rebootOTA, - factoryReset, + 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, + resetPeers = 26, + shutdown = 27, + reboot = 28, + rebootOTA = 29, + factoryReset = 30, } export interface LogEvent { @@ -116,14 +116,14 @@ export interface LogEvent { } export enum ChannelNumber { - PRIMARY, - CHANNEL1, - CHANNEL2, - CHANNEL3, - CHANNEL4, - CHANNEL5, - CHANNEL6, - ADMIN, + PRIMARY = 1, + CHANNEL1 = 2, + CHANNEL2 = 3, + CHANNEL3 = 4, + CHANNEL4 = 5, + CHANNEL5 = 6, + CHANNEL6 = 7, + ADMIN = 8, } export type ConnectionType = diff --git a/src/utils/eventSystem.ts b/src/utils/eventSystem.ts index 092283e..61b0635 100644 --- a/src/utils/eventSystem.ts +++ b/src/utils/eventSystem.ts @@ -1,6 +1,6 @@ -import { SubEvent } from "sub-events"; import { Protobuf, Types } from "../index.js"; import { PacketMetadata } from "../types.js"; +import { SubEvent } from "sub-events"; export class EventSystem { /** diff --git a/src/utils/queue.ts b/src/utils/queue.ts index c04c86d..29c52de 100644 --- a/src/utils/queue.ts +++ b/src/utils/queue.ts @@ -1,6 +1,6 @@ -import { SubEvent } from "sub-events"; import { Protobuf } from "../index.js"; import { PacketError } from "../types.js"; +import { SubEvent } from "sub-events"; export interface IQueueItem { id: number;