Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@meshtastic/meshtasticjs

Package Overview
Dependencies
Maintainers
1
Versions
181
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@meshtastic/meshtasticjs - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

126

dist/iMeshDevice.d.ts
import { Logger } from "tslog";
import { Types } from "./index.js";
import { clearChannelProps, confirmSetChannelProps, confirmSetConfigProps, factoryResetProps, getChannelProps, getConfigProps, getMetadataProps, getModuleConfigProps, getOwnerProps, handleFromRadioProps, rebootOTAProps, rebootProps, resetPeersProps, sendPacketProps, sendRawProps, sendTextProps, setChannelProps, setConfigProps, setModuleConfigProps, setOwnerProps, setPositionProps, shutdownProps, updateDeviceStatusProps } from "./types.js";
import { clearChannelProps, getChannelProps, getConfigProps, getMetadataProps, getModuleConfigProps, handleFromRadioProps, rebootOTAProps, rebootProps, requestPositionProps, sendPacketProps, sendRawProps, sendTextProps, setChannelProps, setConfigProps, setModuleConfigProps, setOwnerProps, setPositionProps, shutdownProps, traceRouteProps, updateDeviceStatusProps } from "./types.js";
import { EventSystem } from "./utils/eventSystem.js";

@@ -23,4 +23,4 @@ import { Queue } from "./utils/queue.js";

/**
* Keeps track of all requests sent to the radio that have callbacks TODO:
* Update description
* Packert queue, to space out transmissions and routing handle errors and
* acks
*/

@@ -47,7 +47,5 @@ queue: Queue;

* number to send to. Default is `Types.ChannelNumber.PRIMARY`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @returns {Promise<void>}
*/
sendText({ text, destination, wantAck, channel, callback }: sendTextProps): Promise<void>;
sendText({ text, destination, wantAck, channel }: sendTextProps): Promise<number>;
/**

@@ -61,7 +59,5 @@ * Sends a text over the radio

* to send on. Default is `Types.ChannelNumber.PRIMARY`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @returns {Promise<void>}
*/
sendWaypoint({ waypoint, destination, channel, callback }: Types.sendWaypointProps): Promise<void>;
sendWaypoint({ waypoint, destination, channel }: Types.sendWaypointProps): Promise<number>;
/**

@@ -81,8 +77,6 @@ * Sends packet over the radio

* is `false`. Default is `false`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @param {number} [emoji=0] Used for message reactions. Default is `0`
* @param {number} [replyId=0] Used to reply to a message. Default is `0`
*/
sendPacket({ byteData, portNum, destination, wantAck, channel, wantResponse, echoResponse, callback, emoji, replyId }: sendPacketProps): Promise<void>;
sendPacket({ byteData, portNum, destination, wantAck, channel, wantResponse, echoResponse, emoji, replyId }: sendPacketProps): Promise<number>;
/**

@@ -93,6 +87,4 @@ * Sends raw packet over the radio

* @param {Uint8Array} toRadio Binary data to send
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
sendRaw({ id, toRadio, callback }: sendRawProps): Promise<void>;
sendRaw({ id, toRadio }: sendRawProps): Promise<number>;
/**

@@ -102,6 +94,4 @@ * Writes config to device

* @param {Protobuf.Config} config Config object
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
setConfig({ config, callback }: setConfigProps): Promise<void>;
setConfig({ config }: setConfigProps): Promise<number>;
/**

@@ -111,6 +101,4 @@ * Writes module config to device

* @param {Protobuf.ModuleConfig} config Module config object
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
setModuleConfig({ moduleConfig, callback }: setModuleConfigProps): Promise<void>;
setModuleConfig({ moduleConfig }: setModuleConfigProps): Promise<number>;
/**

@@ -120,6 +108,4 @@ * Sets devices owner data

* @param {Protobuf.User} owner Owner data to apply to the device
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
setOwner({ owner, callback }: setOwnerProps): Promise<void>;
setOwner({ owner }: setOwnerProps): Promise<number>;
/**

@@ -129,7 +115,5 @@ * Sets devices ChannelSettings

* @param {Protobuf.Channel} channel Channel data to be set
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
setChannel({ channel, callback }: setChannelProps): Promise<void>;
setPosition({ position, callback }: setPositionProps): Promise<void>;
setChannel({ channel }: setChannelProps): Promise<number>;
setPosition({ position }: setPositionProps): Promise<number>;
/**

@@ -139,6 +123,4 @@ * Gets specified channel information from the radio

* @param {number} index Channel index to be retrieved
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
getChannel({ index, callback }: getChannelProps): Promise<void>;
getChannel({ index }: getChannelProps): Promise<number>;
/**

@@ -149,6 +131,4 @@ * Gets devices config

* request
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
getConfig({ configType, callback }: getConfigProps): Promise<void>;
getConfig({ configType }: getConfigProps): Promise<number>;
/**

@@ -159,21 +139,12 @@ * Gets Module config

* module config type to request
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
getModuleConfig({ moduleConfigType, callback }: getModuleConfigProps): Promise<void>;
getModuleConfig({ moduleConfigType }: getModuleConfigProps): Promise<number>;
/** Gets devices Owner */
getOwner(): Promise<number>;
/**
* Gets devices Owner
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
getOwner({ callback }: getOwnerProps): Promise<void>;
/**
* Gets devices metadata
*
* @param {number} nodeNum Destination Node to be queried
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
getMetadata({ nodeNum, callback }: getMetadataProps): Promise<void>;
getMetadata({ nodeNum }: getMetadataProps): Promise<number>;
/**

@@ -183,63 +154,38 @@ * Clears specific channel with the designated index

* @param {number} index Channel index to be cleared
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
clearChannel({ index, callback }: clearChannelProps): Promise<void>;
clearChannel({ index }: clearChannelProps): Promise<number>;
/**
* Confirms the currently set channels, and prevents changes from reverting
* after 10 minutes.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
confirmSetChannel({ callback }: confirmSetChannelProps): Promise<void>;
beginEditSettings(): Promise<void>;
commitEditSettings(): Promise<void>;
confirmSetChannel(): Promise<number>;
beginEditSettings(): Promise<number>;
commitEditSettings(): Promise<number>;
/**
* Confirms the currently set config, and prevents changes from reverting
* after 10 minutes.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
confirmSetConfig({ callback }: confirmSetConfigProps): Promise<void>;
confirmSetConfig(): Promise<number>;
/**
* Resets the internal NodeDB of the radio, usefull for removing old nodes
* that no longer exist.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
resetPeers({ callback }: resetPeersProps): Promise<void>;
resetPeers(): Promise<number>;
/** Shuts down the current node after the specified amount of time has elapsed. */
shutdown({ time }: shutdownProps): Promise<number>;
/** Reboots the current node after the specified amount of time has elapsed. */
reboot({ time }: rebootProps): Promise<number>;
/**
* Shuts down the current node after the specified amount of time has elapsed.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
shutdown({ time, callback }: shutdownProps): Promise<void>;
/**
* Reboots the current node after the specified amount of time has elapsed.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
reboot({ callback, time }: rebootProps): Promise<void>;
/**
* Reboots the current node into OTA mode after the specified amount of time
* has elapsed.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
rebootOTA({ callback, time }: rebootOTAProps): Promise<void>;
/**
* Factory resets the current node
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
factoryReset({ callback }: factoryResetProps): Promise<void>;
rebootOTA({ time }: rebootOTAProps): Promise<number>;
/** Factory resets the current node */
factoryReset(): Promise<number>;
/** Triggers the device configure process */
configure(): void;
/** Sends a trace route packet to the designated node */
traceRoute({ destination }: traceRouteProps): Promise<number>;
/** Requests position from the designated node */
requestPosition({ destination }: requestPositionProps): Promise<number>;
/**

@@ -263,3 +209,3 @@ * Updates the device status eliminating duplicate status events

*/
protected handleFromRadio({ fromRadio }: handleFromRadioProps): Promise<void>;
protected handleFromRadio({ fromRadio }: handleFromRadioProps): void;
/** Completes all SubEvents */

@@ -266,0 +212,0 @@ complete(): void;

@@ -21,4 +21,4 @@ import { Logger } from "tslog";

/**
* Keeps track of all requests sent to the radio that have callbacks TODO:
* Update description
* Packert queue, to space out transmissions and routing handle errors and
* acks
*/

@@ -59,7 +59,5 @@ queue;

* number to send to. Default is `Types.ChannelNumber.PRIMARY`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @returns {Promise<void>}
*/
sendText({ text, destination, wantAck, channel, callback }) {
async sendText({ text, destination, wantAck, channel }) {
this.log.debug(Types.Emitter[Types.Emitter.sendText], `📤 Sending message to ${destination ?? "broadcast"} on channel ${channel?.toString() ?? 0}`);

@@ -73,4 +71,3 @@ const enc = new TextEncoder();

channel,
echoResponse: true,
callback
echoResponse: true
});

@@ -86,7 +83,5 @@ }

* to send on. Default is `Types.ChannelNumber.PRIMARY`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @returns {Promise<void>}
*/
sendWaypoint({ waypoint, destination, channel, callback }) {
sendWaypoint({ waypoint, destination, channel }) {
this.log.debug(Types.Emitter[Types.Emitter.sendWaypoint], `📤 Sending waypoint to ${destination} on channel ${channel?.toString() ?? 0}`);

@@ -99,4 +94,3 @@ return this.sendPacket({

channel,
echoResponse: true,
callback
echoResponse: true
});

@@ -118,8 +112,6 @@ }

* is `false`. Default is `false`
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
* @param {number} [emoji=0] Used for message reactions. Default is `0`
* @param {number} [replyId=0] Used to reply to a message. Default is `0`
*/
async sendPacket({ byteData, portNum, destination, wantAck = false, channel = Types.ChannelNumber.PRIMARY, wantResponse = false, echoResponse = false, callback, emoji = 0, replyId = 0 }) {
async sendPacket({ byteData, portNum, destination, wantAck = false, channel = Types.ChannelNumber.PRIMARY, wantResponse = false, echoResponse = false, emoji = 0, replyId = 0 }) {
this.log.trace(Types.Emitter[Types.Emitter.sendPacket], `📤 Sending ${Protobuf.PortNum[portNum]} to ${destination}`);

@@ -157,5 +149,5 @@ const meshPacket = Protobuf.MeshPacket.create({

if (echoResponse) {
await this.handleMeshPacket(meshPacket);
this.handleMeshPacket(meshPacket);
}
await this.sendRaw({ id: meshPacket.id, toRadio, callback });
return this.sendRaw({ id: meshPacket.id, toRadio });
}

@@ -167,8 +159,6 @@ /**

* @param {Uint8Array} toRadio Binary data to send
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async sendRaw({ id, toRadio, callback }) {
async sendRaw({ id, toRadio }) {
if (toRadio.length > 512) {
this.log.warn(Types.Emitter[Types.Emitter.sendRaw], `Message longer than 512 bytes, it will not be sent!`);
throw new Error("Message longer than 512 bytes, it will not be sent!");
}

@@ -179,6 +169,2 @@ else {

data: toRadio,
callback: callback ??
(async () => {
return Promise.resolve();
}),
waitingAck: false

@@ -189,2 +175,3 @@ });

});
return this.queue.wait(id);
}

@@ -196,7 +183,5 @@ }

* @param {Protobuf.Config} config Config object
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async setConfig({ config, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.setConfig], `Setting config ${callback ? "with" : "without"} callback`);
async setConfig({ config }) {
this.log.debug(Types.Emitter[Types.Emitter.setConfig], `Setting config`);
let configType;

@@ -232,3 +217,3 @@ switch (config.payloadVariant.oneofKind) {

});
await this.sendPacket({
return this.sendPacket({
byteData: setRadio,

@@ -238,7 +223,6 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
await this.getConfig({ configType });
await callback?.(id);
}
wantResponse: true
}).then(async (id) => {
await this.getConfig({ configType });
return id;
});

@@ -250,7 +234,5 @@ }

* @param {Protobuf.ModuleConfig} config Module config object
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async setModuleConfig({ moduleConfig, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.setModuleConfig], `Setting module config ${callback ? "with" : "without"} callback`);
async setModuleConfig({ moduleConfig }) {
this.log.debug(Types.Emitter[Types.Emitter.setModuleConfig], `Setting module config`);
let moduleConfigType;

@@ -291,3 +273,3 @@ switch (moduleConfig.payloadVariant.oneofKind) {

});
await this.sendPacket({
return this.sendPacket({
byteData: setRadio,

@@ -297,7 +279,6 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
await this.getModuleConfig({ moduleConfigType });
await callback?.(id);
}
wantResponse: true
}).then(async (id) => {
await this.getModuleConfig({ moduleConfigType });
return id;
});

@@ -309,7 +290,5 @@ }

* @param {Protobuf.User} owner Owner data to apply to the device
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async setOwner({ owner, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.setOwner], `Setting owner ${callback ? "with" : "without"} callback`);
async setOwner({ owner }) {
this.log.debug(Types.Emitter[Types.Emitter.setOwner], `Setting owner`);
const setOwner = Protobuf.AdminMessage.toBinary({

@@ -321,3 +300,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: setOwner,

@@ -327,7 +306,6 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
await this.getOwner({});
await callback?.(id);
}
wantResponse: true
}).then(async (id) => {
await this.getOwner();
return id;
});

@@ -339,7 +317,5 @@ }

* @param {Protobuf.Channel} channel Channel data to be set
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async setChannel({ channel, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.setChannel], `📻 Setting Channel: ${channel.index} ${callback ? "with" : "without"} callback`);
async setChannel({ channel }) {
this.log.debug(Types.Emitter[Types.Emitter.setChannel], `📻 Setting Channel: ${channel.index}`);
const setChannel = Protobuf.AdminMessage.toBinary({

@@ -351,3 +327,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: setChannel,

@@ -357,11 +333,10 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
await this.getChannel({ index: channel.index });
await callback?.(id);
}
wantResponse: true
}).then(async (id) => {
await this.getChannel({ index: channel.index });
return id;
});
}
async setPosition({ position, callback }) {
await this.sendPacket({
async setPosition({ position }) {
return this.sendPacket({
byteData: Protobuf.Position.toBinary(position),

@@ -371,4 +346,3 @@ portNum: Protobuf.PortNum.POSITION_APP,

wantAck: true,
wantResponse: true,
callback
wantResponse: true
});

@@ -380,7 +354,5 @@ }

* @param {number} index Channel index to be retrieved
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getChannel({ index, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.getChannel], `📻 Requesting Channel: ${index} ${callback ? "with" : "without"} callback`);
async getChannel({ index }) {
this.log.debug(Types.Emitter[Types.Emitter.getChannel], `📻 Requesting Channel: ${index}`);
const getChannelRequest = Protobuf.AdminMessage.toBinary({

@@ -392,3 +364,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: getChannelRequest,

@@ -398,4 +370,3 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback
wantResponse: true
});

@@ -408,7 +379,5 @@ }

* request
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getConfig({ configType, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.getConfig], `Requesting config ${callback ? "with" : "without"} callback`);
async getConfig({ configType }) {
this.log.debug(Types.Emitter[Types.Emitter.getConfig], `Requesting config`);
const getRadioRequest = Protobuf.AdminMessage.toBinary({

@@ -420,3 +389,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: getRadioRequest,

@@ -426,4 +395,3 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback
wantResponse: true
});

@@ -436,7 +404,5 @@ }

* module config type to request
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getModuleConfig({ moduleConfigType, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.getModuleConfig], `Requesting module config ${callback ? "with" : "without"} callback`);
async getModuleConfig({ moduleConfigType }) {
this.log.debug(Types.Emitter[Types.Emitter.getModuleConfig], `Requesting module config`);
const getRadioRequest = Protobuf.AdminMessage.toBinary({

@@ -448,3 +414,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: getRadioRequest,

@@ -454,14 +420,8 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback
wantResponse: true
});
}
/**
* Gets devices Owner
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getOwner({ callback }) {
this.log.debug(Types.Emitter[Types.Emitter.getOwner], `Requesting owner ${callback ? "with" : "without"} callback`);
/** Gets devices Owner */
async getOwner() {
this.log.debug(Types.Emitter[Types.Emitter.getOwner], `Requesting owner`);
const getOwnerRequest = Protobuf.AdminMessage.toBinary({

@@ -473,3 +433,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: getOwnerRequest,

@@ -479,4 +439,3 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback
wantResponse: true
});

@@ -488,7 +447,5 @@ }

* @param {number} nodeNum Destination Node to be queried
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async getMetadata({ nodeNum, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.getMetadata], `Requesting metadata from ${nodeNum} ${callback ? "with" : "without"} callback`);
async getMetadata({ nodeNum }) {
this.log.debug(Types.Emitter[Types.Emitter.getMetadata], `Requesting metadata from ${nodeNum}`);
const getDeviceMetricsRequest = Protobuf.AdminMessage.toBinary({

@@ -500,3 +457,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: getDeviceMetricsRequest,

@@ -507,4 +464,3 @@ portNum: Protobuf.PortNum.ADMIN_APP,

channel: Types.ChannelNumber.ADMIN,
wantResponse: true,
callback
wantResponse: true
});

@@ -516,7 +472,5 @@ }

* @param {number} index Channel index to be cleared
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async clearChannel({ index, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.clearChannel], `📻 Clearing Channel ${index} ${callback ? "with" : "without"} callback`);
async clearChannel({ index }) {
this.log.debug(Types.Emitter[Types.Emitter.clearChannel], `📻 Clearing Channel ${index}`);
const channel = Protobuf.Channel.create({

@@ -532,3 +486,3 @@ index,

});
await this.sendPacket({
return this.sendPacket({
byteData: setChannel,

@@ -538,7 +492,6 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
await this.getChannel({ index: channel.index });
await callback?.(id);
}
wantResponse: true
}).then(async (id) => {
await this.getChannel({ index: channel.index });
return id;
});

@@ -549,8 +502,5 @@ }

* after 10 minutes.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async confirmSetChannel({ callback }) {
this.log.debug(Types.Emitter[Types.Emitter.confirmSetChannel], `📻 Confirming Channel config ${callback ? "with" : "without"} callback`);
async confirmSetChannel() {
this.log.debug(Types.Emitter[Types.Emitter.confirmSetChannel], `📻 Confirming Channel config`);
const confirmSetChannel = Protobuf.AdminMessage.toBinary({

@@ -562,3 +512,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: confirmSetChannel,

@@ -568,4 +518,3 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback
wantResponse: true
});

@@ -581,3 +530,3 @@ }

});
await this.sendPacket({
return this.sendPacket({
byteData: beginEditSettings,

@@ -589,2 +538,3 @@ portNum: Protobuf.PortNum.ADMIN_APP,

async commitEditSettings() {
this.events.onPendingSettingsChange.emit(false);
const commitEditSettings = Protobuf.AdminMessage.toBinary({

@@ -596,3 +546,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: commitEditSettings,

@@ -602,3 +552,2 @@ portNum: Protobuf.PortNum.ADMIN_APP,

});
this.events.onPendingSettingsChange.emit(false);
}

@@ -608,8 +557,5 @@ /**

* after 10 minutes.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async confirmSetConfig({ callback }) {
this.log.debug(Types.Emitter[Types.Emitter.confirmSetConfig], `Confirming config ${callback ? "with" : "without"} callback`);
async confirmSetConfig() {
this.log.debug(Types.Emitter[Types.Emitter.confirmSetConfig], `Confirming config`);
if (!this.pendingSettingsChanges) {

@@ -624,3 +570,3 @@ await this.beginEditSettings();

});
await this.sendPacket({
return this.sendPacket({
byteData: confirmSetRadio,

@@ -630,4 +576,3 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback
wantResponse: true
});

@@ -638,8 +583,5 @@ }

* that no longer exist.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async resetPeers({ callback }) {
this.log.debug(Types.Emitter[Types.Emitter.resetPeers], `📻 Resetting Peers ${callback ? "with" : "without"} callback`);
async resetPeers() {
this.log.debug(Types.Emitter[Types.Emitter.resetPeers], `📻 Resetting Peers`);
const resetPeers = Protobuf.AdminMessage.toBinary({

@@ -651,3 +593,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: resetPeers,

@@ -657,16 +599,8 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
callback && (await callback(id));
}
wantResponse: true
});
}
/**
* Shuts down the current node after the specified amount of time has elapsed.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async shutdown({ time, callback }) {
this.log.debug(Types.Emitter[Types.Emitter.shutdown], `🔌 Shutting down ${time > 0 ? "now" : `in ${time} seconds`} ${callback ? "with" : "without"} callback`);
/** Shuts down the current node after the specified amount of time has elapsed. */
async shutdown({ time }) {
this.log.debug(Types.Emitter[Types.Emitter.shutdown], `🔌 Shutting down ${time > 0 ? "now" : `in ${time} seconds`}`);
const shutdown = Protobuf.AdminMessage.toBinary({

@@ -678,3 +612,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: shutdown,

@@ -684,16 +618,8 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
callback && (await callback(id));
}
wantResponse: true
});
}
/**
* Reboots the current node after the specified amount of time has elapsed.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async reboot({ callback, time }) {
this.log.debug(Types.Emitter[Types.Emitter.reboot], `🔌 Rebooting node ${time > 0 ? "now" : `in ${time} seconds`} ${callback ? "with" : "without"} callback`);
/** Reboots the current node after the specified amount of time has elapsed. */
async reboot({ time }) {
this.log.debug(Types.Emitter[Types.Emitter.reboot], `🔌 Rebooting node ${time > 0 ? "now" : `in ${time} seconds`}`);
const reboot = Protobuf.AdminMessage.toBinary({

@@ -705,3 +631,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: reboot,

@@ -711,6 +637,3 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
callback && (await callback(id));
}
wantResponse: true
});

@@ -721,8 +644,5 @@ }

* has elapsed.
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async rebootOTA({ callback, time }) {
this.log.debug(Types.Emitter[Types.Emitter.rebootOTA], `🔌 Rebooting into OTA mode ${time > 0 ? "now" : `in ${time} seconds`} ${callback ? "with" : "without"} callback`);
async rebootOTA({ time }) {
this.log.debug(Types.Emitter[Types.Emitter.rebootOTA], `🔌 Rebooting into OTA mode ${time > 0 ? "now" : `in ${time} seconds`}`);
const rebootOTA = Protobuf.AdminMessage.toBinary({

@@ -734,3 +654,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: rebootOTA,

@@ -740,16 +660,8 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
callback && (await callback(id));
}
wantResponse: true
});
}
/**
* Factory resets the current node
*
* @param {(id: number) => Promise<void>} [callback] If wantAck is true,
* callback is called when the ack is received
*/
async factoryReset({ callback }) {
this.log.debug(Types.Emitter[Types.Emitter.factoryReset], `♻️ Factory resetting node ${callback ? "with" : "without"} callback`);
/** Factory resets the current node */
async factoryReset() {
this.log.debug(Types.Emitter[Types.Emitter.factoryReset], `♻️ Factory resetting node`);
const factoryReset = Protobuf.AdminMessage.toBinary({

@@ -761,3 +673,3 @@ payloadVariant: {

});
await this.sendPacket({
return this.sendPacket({
byteData: factoryReset,

@@ -767,9 +679,7 @@ portNum: Protobuf.PortNum.ADMIN_APP,

wantAck: true,
wantResponse: true,
callback: async (id) => {
callback && (await callback(id));
}
wantResponse: true
});
}
/** Triggers the device configure process */
// TODO: Make more robust and await the sendRaw
configure() {

@@ -791,2 +701,25 @@ // TODO: this not always logged

}
/** Sends a trace route packet to the designated node */
async traceRoute({ destination }) {
const routeDiscovery = Protobuf.RouteDiscovery.toBinary({
route: []
});
return this.sendPacket({
byteData: routeDiscovery,
portNum: Protobuf.PortNum.ROUTING_APP,
destination: destination,
wantAck: true,
wantResponse: true
});
}
/** Requests position from the designated node */
async requestPosition({ destination }) {
return this.sendPacket({
byteData: new Uint8Array(),
portNum: Protobuf.PortNum.POSITION_APP,
destination: destination,
wantAck: true,
wantResponse: true
});
}
/**

@@ -816,3 +749,3 @@ * Updates the device status eliminating duplicate status events

*/
async handleFromRadio({ fromRadio }) {
handleFromRadio({ fromRadio }) {
const decodedMessage = Protobuf.FromRadio.fromBinary(fromRadio);

@@ -823,3 +756,3 @@ this.events.onFromRadio.emit(decodedMessage);

case "packet":
await this.handleMeshPacket(decodedMessage.payloadVariant.packet);
this.handleMeshPacket(decodedMessage.payloadVariant.packet);
break;

@@ -949,3 +882,3 @@ case "myInfo":

*/
async handleMeshPacket(meshPacket) {
handleMeshPacket(meshPacket) {
this.events.onMeshPacket.emit(meshPacket);

@@ -961,3 +894,2 @@ if (meshPacket.from !== this.myNodeInfo.myNodeNum) {

case "decoded":
await this.queue.processAck(meshPacket.payloadVariant.decoded.requestId);
this.handleDataPacket({

@@ -975,5 +907,10 @@ dataPacket: meshPacket.payloadVariant.decoded,

let adminMessage = undefined;
let routingPacket = undefined;
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], `📦 Received ${Protobuf.PortNum[dataPacket.portnum]} packet`);
if (dataPacket.requestId !== 0 &&
dataPacket.portnum !== Protobuf.PortNum.ROUTING_APP) {
this.queue.processAck(dataPacket.requestId);
}
switch (dataPacket.portnum) {
case Protobuf.PortNum.TEXT_MESSAGE_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received TEXT_MESSAGE_APP packet", new TextDecoder().decode(dataPacket.payload));
this.events.onMessagePacket.emit({

@@ -985,3 +922,2 @@ packet: meshPacket,

case Protobuf.PortNum.REMOTE_HARDWARE_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received REMOTE_HARDWARE_APP packet", Protobuf.HardwareMessage.fromBinary(dataPacket.payload));
this.events.onRemoteHardwarePacket.emit({

@@ -993,3 +929,2 @@ packet: meshPacket,

case Protobuf.PortNum.POSITION_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received POSITION_APP packet", Protobuf.Position.fromBinary(dataPacket.payload));
this.events.onPositionPacket.emit({

@@ -1001,7 +936,2 @@ packet: meshPacket,

case Protobuf.PortNum.NODEINFO_APP:
/**
* TODO: workaround for NODEINFO_APP plugin sending a User protobuf
* instead of a NodeInfo protobuf
*/
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received NODEINFO_APP packet", Protobuf.User.fromBinary(dataPacket.payload));
this.events.onUserPacket.emit({

@@ -1013,13 +943,26 @@ packet: meshPacket,

case Protobuf.PortNum.ROUTING_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received ROUTING_APP packet", Protobuf.Routing.fromBinary(dataPacket.payload));
routingPacket = Protobuf.Routing.fromBinary(dataPacket.payload);
this.events.onRoutingPacket.emit({
packet: meshPacket,
data: Protobuf.Routing.fromBinary(dataPacket.payload)
data: routingPacket
});
switch (routingPacket.variant.oneofKind) {
case "errorReason":
this.queue.processError({
id: dataPacket.requestId,
error: routingPacket.variant.errorReason
});
break;
case "routeReply":
console.log("routeReply");
console.log(routingPacket.variant.routeReply);
break;
case "routeRequest":
console.log("routeRequest");
console.log(routingPacket.variant.routeRequest);
break;
}
break;
case Protobuf.PortNum.ADMIN_APP:
adminMessage = Protobuf.AdminMessage.fromBinary(dataPacket.payload);
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], `📦 Received ADMIN_APP packet of variant ${
//change
adminMessage.payloadVariant.oneofKind ?? "UNK"}`, adminMessage);
switch (adminMessage.payloadVariant.oneofKind) {

@@ -1061,6 +1004,4 @@ case "getChannelResponse":

case Protobuf.PortNum.TEXT_MESSAGE_COMPRESSED_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received TEXT_MESSAGE_COMPRESSED_APP packet", dataPacket.payload);
break;
case Protobuf.PortNum.WAYPOINT_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received WAYPOINT_APP packet", Protobuf.Waypoint.fromBinary(dataPacket.payload));
this.events.onWaypointPacket.emit({

@@ -1072,3 +1013,2 @@ packet: meshPacket,

case Protobuf.PortNum.REPLY_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received REPLY_APP packet", dataPacket.payload);
this.events.onPingPacket.emit({

@@ -1080,3 +1020,2 @@ packet: meshPacket,

case Protobuf.PortNum.IP_TUNNEL_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received IP_TUNNEL_APP packet", dataPacket.payload);
this.events.onIpTunnelPacket.emit({

@@ -1088,3 +1027,2 @@ packet: meshPacket,

case Protobuf.PortNum.SERIAL_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received SERIAL_APP packet", dataPacket.payload);
this.events.onSerialPacket.emit({

@@ -1096,3 +1034,2 @@ packet: meshPacket,

case Protobuf.PortNum.STORE_FORWARD_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received STORE_FORWARD_APP packet", dataPacket.payload);
this.events.onStoreForwardPacket.emit({

@@ -1104,3 +1041,2 @@ packet: meshPacket,

case Protobuf.PortNum.RANGE_TEST_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received RANGE_TEST_APP packet", dataPacket.payload);
this.events.onRangeTestPacket.emit({

@@ -1112,3 +1048,2 @@ packet: meshPacket,

case Protobuf.PortNum.TELEMETRY_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received TELEMETRY_APP packet", Protobuf.Telemetry.fromBinary(dataPacket.payload));
this.events.onTelemetryPacket.emit({

@@ -1120,3 +1055,2 @@ packet: meshPacket,

case Protobuf.PortNum.PRIVATE_APP:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received PRIVATE_APP packet", dataPacket.payload);
this.events.onPrivatePacket.emit({

@@ -1128,3 +1062,2 @@ packet: meshPacket,

case Protobuf.PortNum.ATAK_FORWARDER:
this.log.trace(Types.Emitter[Types.Emitter.handleMeshPacket], "📦 Received ATAK_FORWARDER packet", dataPacket.payload);
this.events.onAtakPacket.emit({

@@ -1135,5 +1068,2 @@ packet: meshPacket,

break;
default:
this.log.warn(Types.Emitter[Types.Emitter.handleMeshPacket], `⚠️ Received unhandled PortNum: ${Protobuf.PortNum[dataPacket.portnum]}`, dataPacket.payload);
break;
}

@@ -1140,0 +1070,0 @@ }

@@ -49,5 +49,3 @@ import { SubEvent } from "sub-events";

if (value) {
void this.handleFromRadio({ fromRadio: value }).catch((e) => {
this.log.info(Types.Emitter[Types.Emitter.readFromRadio], `Device errored or disconnected: ${e.message}`);
});
this.handleFromRadio({ fromRadio: value });
}

@@ -54,0 +52,0 @@ })

@@ -180,3 +180,2 @@ /// <reference types="web-bluetooth" />

export type destination = number | "self" | "broadcast";
export type callback = (id: number) => Promise<void>;
export interface sendTextProps {

@@ -187,3 +186,2 @@ text: string;

channel?: ChannelNumber;
callback: callback;
}

@@ -194,3 +192,2 @@ export interface sendWaypointProps {

channel?: ChannelNumber;
callback?: callback;
}

@@ -205,3 +202,2 @@ export interface sendPacketProps {

echoResponse?: boolean;
callback?: callback;
emoji?: number;

@@ -213,70 +209,47 @@ replyId?: number;

toRadio: Uint8Array;
callback?: callback;
}
export interface setConfigProps {
config: Protobuf.Config;
callback?: callback;
}
export interface setModuleConfigProps {
moduleConfig: Protobuf.ModuleConfig;
callback?: callback;
}
export interface setOwnerProps {
owner: Protobuf.User;
callback?: callback;
}
export interface setChannelProps {
channel: Protobuf.Channel;
callback?: callback;
}
export interface setPositionProps {
position: Protobuf.Position;
callback?: callback;
}
export interface getChannelProps {
index: number;
callback?: callback;
}
export interface getConfigProps {
configType: Protobuf.AdminMessage_ConfigType;
callback?: callback;
}
export interface getModuleConfigProps {
moduleConfigType: Protobuf.AdminMessage_ModuleConfigType;
callback?: callback;
}
export interface getOwnerProps {
callback?: callback;
}
export interface getMetadataProps {
nodeNum: number;
callback?: callback;
}
export interface clearChannelProps {
index: number;
callback?: callback;
}
export interface confirmSetChannelProps {
callback?: callback;
export interface traceRouteProps {
destination: number;
}
export interface confirmSetConfigProps {
callback?: callback;
export interface requestPositionProps {
destination: number;
}
export interface resetPeersProps {
callback?: callback;
}
export interface factoryResetProps {
callback?: callback;
}
export interface shutdownProps {
time: number;
callback?: callback;
}
export interface rebootProps {
time: number;
callback?: callback;
}
export interface rebootOTAProps {
time: number;
callback?: callback;
}

@@ -283,0 +256,0 @@ export interface updateDeviceStatusProps {

@@ -0,15 +1,24 @@

import { Protobuf } from "../index.js";
export interface IQueueItem {
id: number;
data: Uint8Array;
callback: (id: number) => Promise<void>;
waitingAck: boolean;
promise: Promise<number>;
}
export interface packetError {
id: number;
error: Protobuf.Routing_Error;
}
export declare class Queue {
private queue;
private locked;
private ackNotifier;
private errorNotifier;
clear(): void;
push(item: IQueueItem): void;
push(item: Omit<IQueueItem, "promise">): void;
remove(id: number): void;
processAck(id: number): Promise<void>;
processAck(id: number): void;
processError(e: packetError): void;
wait(id: number): Promise<number>;
processQueue(writeToRadio: (data: Uint8Array) => Promise<void>): Promise<void>;
}

@@ -0,4 +1,7 @@

import { SubEvent } from "sub-events";
export class Queue {
queue = [];
locked = false;
ackNotifier = new SubEvent();
errorNotifier = new SubEvent();
clear() {

@@ -8,15 +11,42 @@ this.queue = [];

push(item) {
this.queue.push(item);
const queueItem = {
...item,
promise: new Promise((resolve, reject) => {
this.ackNotifier.subscribe((id) => {
resolve(id);
if (item.id === id) {
resolve(id);
this.remove(item.id);
}
});
this.errorNotifier.subscribe((e) => {
reject(e);
if (item.id === e.id) {
reject(e);
this.remove(item.id);
}
});
})
};
this.queue.push(queueItem);
}
remove(id) {
this.queue = this.queue.filter((item) => {
return item.id !== id;
});
this.queue = this.queue.filter((item) => item.id !== id);
}
async processAck(id) {
const item = this.queue.find((queueItem) => queueItem.id === id);
if (item) {
await item.callback(id);
this.remove(item.id);
processAck(id) {
console.warn("PROCESSING ACK", id);
console.log(this.queue);
this.ackNotifier.emit(id);
}
processError(e) {
console.warn("PROCESSING ERROR", e.id);
console.log(this.queue);
this.errorNotifier.emit(e);
}
async wait(id) {
const queueItem = this.queue.find((qi) => qi.id === id);
if (!queueItem) {
throw new Error("Packet does not exist");
}
return queueItem.promise;
}

@@ -29,3 +59,3 @@ async processQueue(writeToRadio) {

while (this.queue.filter((p) => !p.waitingAck).length > 0) {
const item = this.queue.filter((p) => !p.waitingAck).shift();
const item = this.queue.filter((p) => !p.waitingAck)[0];
if (item) {

@@ -35,3 +65,2 @@ await new Promise((resolve) => setTimeout(resolve, 200));

item.waitingAck = true;
this.queue.push(item);
}

@@ -38,0 +67,0 @@ }

{
"name": "@meshtastic/meshtasticjs",
"version": "0.8.0",
"version": "0.9.0",
"description": "Browser library for interfacing with meshtastic devices",

@@ -5,0 +5,0 @@ "license": "GPL-3.0-only",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc