Feat/add js repo to monorepo (#683)
* feat: move js repo into web monorepo * added readme * Update packages/core/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/transport-http/README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/transport-web-bluetooth/README.md 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:
@@ -0,0 +1,34 @@
|
||||
# @meshtastic/transport-web-serial
|
||||
|
||||
[](https://jsr.io/@meshtastic/transport-web-serial)
|
||||
[](https://github.com/meshtastic/js/actions/workflows/ci.yml)
|
||||
[](https://cla-assistant.io/meshtastic/meshtastic.js)
|
||||
[](https://opencollective.com/meshtastic/)
|
||||
[](https://vercel.com?utm_source=meshtastic&utm_campaign=oss)
|
||||
|
||||
## Overview
|
||||
|
||||
`@meshtastic/transport-web-serial` Provides Web Serial transport for Meshtastic
|
||||
devices. Installation instructions are avaliable at
|
||||
[JSR](https://jsr.io/@meshtastic/transport-web-serial)
|
||||
|
||||
## Usage
|
||||
|
||||
```ts
|
||||
import { MeshDevice } from "@meshtastic/core";
|
||||
import { TransportWebSerial } from "@meshtastic/transport-web-serial";
|
||||
|
||||
const transport = await TransportWebSerial.create();
|
||||
const device = new MeshDevice(transport);
|
||||
```
|
||||
|
||||
## Stats
|
||||
|
||||

|
||||
|
||||
### Compatibility
|
||||
|
||||
The Web Serial API's have limited support in browsers, compatibility is
|
||||
represented in the matrix below.
|
||||
|
||||

|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "@meshtastic/transport-web-serial",
|
||||
"version": "0.2.1",
|
||||
"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 @@
|
||||
export { TransportWebSerial } from "./src/transport.ts";
|
||||
@@ -0,0 +1,42 @@
|
||||
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>;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
constructor(connection: SerialPort) {
|
||||
if (!connection.readable || !connection.writable) {
|
||||
throw new Error("Stream not accessible");
|
||||
}
|
||||
|
||||
Utils.toDeviceStream.readable.pipeTo(connection.writable);
|
||||
|
||||
this._toDevice = Utils.toDeviceStream.writable;
|
||||
this._fromDevice = connection.readable.pipeThrough(
|
||||
Utils.fromDeviceStream(),
|
||||
);
|
||||
}
|
||||
|
||||
get toDevice(): WritableStream<Uint8Array> {
|
||||
return this._toDevice;
|
||||
}
|
||||
|
||||
get fromDevice(): ReadableStream<Types.DeviceOutput> {
|
||||
return this._fromDevice;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user