No description
Find a file
Michael Lynch 486a075b8e Add a browser-only export for Web clients
This package has a single export that includes both NodeJS and browser modules. When a web project imports this library, the build generates a bunch of warnings, like this in vite:

[plugin vite:resolve] Module net has been externalized for browser compatibility...
[plugin vite:resolve] Module stream has been externalized for browser compatibility...
...

We can clean this up by creating a special browser-only export. Bundlers like Vite and Webpack know to choose the 'browser' export in projects that are web-only (not NodeJS).

This change adds a 'browser' export and updates the documentation to use browser-only examples.
2025-12-29 16:41:42 -05:00
examples add example to parse advert from meshcore packet url 2025-10-08 22:38:20 +13:00
src Add a browser-only export for Web clients 2025-12-29 16:41:42 -05:00
.gitignore add node_modules to .gitignore 2025-03-03 09:46:24 +13:00
.npmignore add .idea to .npmignore 2025-02-13 13:32:49 +13:00
index.html Add a browser-only export for Web clients 2025-12-29 16:41:42 -05:00
LICENSE Create LICENSE 2025-02-12 23:09:24 +13:00
package-lock.json 1.10.0 2025-10-14 15:32:44 +13:00
package.json Add a browser-only export for Web clients 2025-12-29 16:41:42 -05:00
README.md Add a browser-only export for Web clients 2025-12-29 16:41:42 -05:00

MeshCore.js

A Javascript library for interacting with a MeshCore device running the Companion Radio Firmware.

This library can be used in a Web Browser to connect to MeshCore Companion devices over BLE or USB Serial.

It can also be used in NodeJS to connect to MeshCore Companion devices over TCP/WiFi or USB Serial.

Supported Connection Methods

Install

npm install @liamcottle/meshcore.js

Simple Examples

Enumerate Contacts (Node.js)

import { TCPConnection, NodeJSSerialConnection } from "@liamcottle/meshcore.js";

// serial connections are supported by "companion_radio_usb" firmware
const connection = new NodeJSSerialConnection("/dev/cu.usbmodem14401");

// tcp connections are supported by "companion_radio_wifi" firmware
// const connection = new TCPConnection("10.1.0.226", 5000);

// wait until connected
connection.on("connected", async () => {

    // we are now connected
    console.log("connected!");

    // log contacts
    const contacts = await connection.getContacts();
    for(const contact of contacts) {
        console.log(`Contact: ${contact.advName}`);
    }

    // disconnect
    connection.close();

});

// connect to meshcore device
await connection.connect();

Enumerate Contacts (Browser)

<button id="connect-serial">Connect via Serial</button>

<script type="module">
import { WebBleConnection, WebSerialConnection } from "@liamcottle/meshcore.js";

// wait until connected
async function onConnected(connection) {

    // we are now connected
    console.log("connected!");

    // log contacts
    const contacts = await connection.getContacts();
    for (const contact of contacts) {
        console.log(`Contact: ${contact.advName}`);
    }
}

document.getElementById("connect-serial").addEventListener("click", async () => {
    const connection = await WebSerialConnection.open();
    connection.on("connected", () => onConnected(connection));
});
</script>

Examples

There's a few other examples scripts in the examples folder.

License

MIT