diff --git a/Cargo.lock b/Cargo.lock index b0db3b12b8..983ae2c882 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1595,7 +1595,7 @@ dependencies = [ [[package]] name = "moq-web" -version = "0.3.7" +version = "0.3.8" dependencies = [ "console_error_panic_hook", "gloo-net", diff --git a/README.md b/README.md index a7ab6d812b..dfa8ebcef7 100644 --- a/README.md +++ b/README.md @@ -79,22 +79,31 @@ For example: ```html ``` -Because it uses WASM, it's not part of the main workspace and requires some extra steps to build. +The package is a gross frankenstein of Rust+Typescript. +To make changes, you'll need to install (Bun)[https://bun.sh/] and then run: ```sh -cd moq-web bun i bun dev ``` -This will start a development server on `http://localhost:3000`. -There's two separate compilation steps, the first building with `wasm-pack` and the second bundling with `rspack`. +You can also test the package locally by linking. +Replace `bun` with your favorite package manager; it might work. + +```sh +bun pack +bun link + +# In your other package +bun link @kixelated/moq +``` + See the [moq-web README](moq-web/README.md) for more information. ## moq-karp diff --git a/moq-web/Cargo.toml b/moq-web/Cargo.toml index d242ee972f..8737191a1e 100644 --- a/moq-web/Cargo.toml +++ b/moq-web/Cargo.toml @@ -2,7 +2,7 @@ name = "moq-web" authors = ["Luke Curley "] edition = "2021" -version = "0.3.7" +version = "0.3.8" license = "MIT OR Apache-2.0" repository = "https://github.com/kixelated/moq-web" description = "Web implementation for MoQ utilizing WebAssembly+Typescript" diff --git a/moq-web/src/bridge.ts b/moq-web/src/bridge.ts new file mode 100644 index 0000000000..b443abbb8d --- /dev/null +++ b/moq-web/src/bridge.ts @@ -0,0 +1,20 @@ +import * as Comlink from "comlink"; +import type { Api } from "./worker"; + +// Create a new worker instance +// We wait until the worker is fully initialized before we return the proxy. +function init(): Promise> { + return new Promise((resolve) => { + const worker = new Worker(new URL("./worker", import.meta.url), { type: "module" }); + worker.addEventListener( + "message", + (event) => { + const proxy: Comlink.Remote = Comlink.wrap(worker); + resolve(proxy); + }, + { once: true }, + ); + }); +} + +export { init }; diff --git a/moq-web/src/demo/index.ts b/moq-web/src/demo/index.ts index 911e5281e0..64138ab69e 100644 --- a/moq-web/src/demo/index.ts +++ b/moq-web/src/demo/index.ts @@ -1 +1 @@ -export { MoqVideoElement } from "../element/video"; +export { MoqVideoElement } from ".."; diff --git a/moq-web/src/element/index.ts b/moq-web/src/element/index.ts index d3ea5a116d..0e56991ba7 100644 --- a/moq-web/src/element/index.ts +++ b/moq-web/src/element/index.ts @@ -1 +1,2 @@ -export { MoqVideoElement } from "./video"; +import MoqVideoElement from "./video"; +export { MoqVideoElement }; diff --git a/moq-web/src/element/video.ts b/moq-web/src/element/video.ts index 0c33c1fd2c..530938ef27 100644 --- a/moq-web/src/element/video.ts +++ b/moq-web/src/element/video.ts @@ -3,7 +3,7 @@ import * as Moq from ".."; // Supports a subset of the