import type { Types } from "@meshtastic/core"; import { Utils } from "@meshtastic/core"; export class TransportDeno implements Types.Transport { private _toDevice: WritableStream; private _fromDevice: ReadableStream; private connection: Deno.Conn | undefined; public static async create(hostname: string): Promise { const connection = await Deno.connect({ hostname, port: 4403, }); return new TransportDeno(connection); } constructor(connection: Deno.Conn) { this.connection = connection; Utils.toDeviceStream.readable.pipeTo(this.connection.writable); this._toDevice = Utils.toDeviceStream.writable; this._fromDevice = this.connection.readable.pipeThrough( Utils.fromDeviceStream(), ); } get toDevice(): WritableStream { return this._toDevice; } get fromDevice(): ReadableStream { return this._fromDevice; } disconnect(): Promise { this.connection.close(); this.connection = undefined; return Promise.resolve(); } }