diff --git a/README.md b/README.md index c3c51d6..a7eb15a 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,11 @@ It can also be used in NodeJS to connect to MeshCore Companion devices over TCP/ npm install @liamcottle/meshcore.js ``` -## Simple Example +## Simple Examples -``` +### Enumerate Contacts (Node.js) + +```javascript import { TCPConnection, NodeJSSerialConnection } from "@liamcottle/meshcore.js"; // serial connections are supported by "companion_radio_usb" firmware @@ -53,6 +55,34 @@ connection.on("connected", async () => { await connection.connect(); ``` +### Enumerate Contacts (Browser) + +```html + + + +``` + ## Examples There's a few other examples scripts in the [examples](./examples) folder. diff --git a/index.html b/index.html index 05ec84a..dfbff1d 100644 --- a/index.html +++ b/index.html @@ -195,10 +195,12 @@ - \ No newline at end of file + diff --git a/package.json b/package.json index 6aae9f0..4798f3a 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,15 @@ "description": "", "main": "src/index.js", "type": "module", + "exports": { + ".": { + "browser": "./src/browser.js", + "import": "./src/index.js", + "default": "./src/index.js" + }, + "./browser": "./src/browser.js", + "./node": "./src/node.js" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/src/browser.js b/src/browser.js new file mode 100644 index 0000000..6d8e263 --- /dev/null +++ b/src/browser.js @@ -0,0 +1,20 @@ +// Browser-only entrypoint – does NOT import Node-only transports (TCP, NodeJSSerial) +import Connection from "./connection/connection.js"; +import WebBleConnection from "./connection/web_ble_connection.js"; +import WebSerialConnection from "./connection/web_serial_connection.js"; +import Constants from "./constants.js"; +import Advert from "./advert.js"; +import Packet from "./packet.js"; +import BufferUtils from "./buffer_utils.js"; +import CayenneLpp from "./cayenne_lpp.js"; + +export { + Connection, + WebBleConnection, + WebSerialConnection, + Constants, + Advert, + Packet, + BufferUtils, + CayenneLpp, +}; diff --git a/src/node.js b/src/node.js new file mode 100644 index 0000000..75f743c --- /dev/null +++ b/src/node.js @@ -0,0 +1,2 @@ +// Node-only entrypoint – re-exports everything including Node transports +export * from "./index.js";