Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

Page media: React's muted reaches the host's player, so an unmuted video plays its sound

shinyobjectzada5e5b5a3f2
diff --git a/sdk/ui/src/dom/host.ts b/sdk/ui/src/dom/host.ts
index 709b5f81..eb8a276e 100644
--- a/sdk/ui/src/dom/host.ts
+++ b/sdk/ui/src/dom/host.ts
@@ -1,7 +1,7 @@
// An element on the wire, React's host instances in DOM mode, and which events the host sends each element.
import * as wire from "../wire";
import type { Ev } from "../wire";
-import { Control_, Element_, FOCUSABLE_TAGS, HTMLOptionElement_, HTMLSelectElement_, HTML_HIDDEN, Node_, S, SKIP_PROPS, SVG_NS, TEXT_INPUTS, Text_, attrName, attrValue, body, cssText, doc, g, hostEvent, html, htmlDoc, htmlValue, installed, isEditable, makeElement, mutated, nativelyFocusable, query, rootContainer, scrollable, tellCapture, typesOn, unwire } from "./all";
+import { Control_, Element_, FOCUSABLE_TAGS, HTMLMediaElement_, HTMLOptionElement_, HTMLSelectElement_, HTML_HIDDEN, Node_, S, SKIP_PROPS, SVG_NS, TEXT_INPUTS, Text_, attrName, attrValue, body, cssText, doc, g, hostEvent, html, htmlDoc, htmlValue, installed, isEditable, makeElement, mutated, nativelyFocusable, query, rootContainer, scrollable, tellCapture, typesOn, unwire } from "./all";
// ---------------------------------------------------------------- what an element is on the wire
@@ -81,7 +81,8 @@ export function hostElement(id: number, type: string, props: Record<string, unkn
el._wired = true;
el._fiber = fiber;
applyProps(el, {}, props, true);
- const w = wireOf(type, props, el);
+ // a video's or audio's own props for its player (__muted) go with its create
+ const w = wireOf(type, el instanceof HTMLMediaElement_ ? { ...props, ...el._extra } : props, el);
if (type === "text" && (typeof props.children === "string" || typeof props.children === "number")) el._inline = String(props.children);
return { el, kind: w.kind, props: svgNs(el, w.props), text: el._inline };
}
@@ -151,6 +152,12 @@ function applyProps(el: Element_, old: Record<string, unknown>, next: Record<str
else el._attrs.delete("style");
if (!init && before !== (el._attrs.get("style") ?? null)) mutated(el, { type: "attributes", attributeName: "style", oldValue: before });
}
+ // muted: React DOM sets the property, so the host's player hears it (dom/media.ts's setter tells it; at creation,
+ // _extra goes with the create). As a prop alone, an unmuted player stayed silent (11-09).
+ if (el instanceof HTMLMediaElement_ && next.muted !== undefined) {
+ if (init) el._extra.__muted = el._muted = !!next.muted;
+ else if (next.muted !== old.muted) el.muted = !!next.muted;
+ }
el._props = next;
}
diff --git a/sdk/ui/test/dom.test.tsx b/sdk/ui/test/dom.test.tsx
index 8857d45a..e959e770 100644
--- a/sdk/ui/test/dom.test.tsx
+++ b/sdk/ui/test/dom.test.tsx
@@ -356,6 +356,7 @@ describe("video and audio play on the host's player (runtime/dom media.rs, raea-
news("timeupdate", { time: 2 });
v.muted = false;
expect(prop("__muted")).toBe(false);
+ v.muted = true;
v.pause();
expect(v.paused).toBe(true);
expect(prop("__play")).toEqual([false, 2, 2, true]);
@@ -389,4 +390,21 @@ describe("video and audio play on the host's player (runtime/dom media.rs, raea-
expect(v.canPlayType("video/mp4")).toBe("maybe");
expect(v.canPlayType("video/x-unknown")).toBe("");
});
+
+ test("React's muted reaches the host's player when it changes, as React DOM sets the property", () => {
+ const host = fresh();
+ let setMuted: (m: boolean) => void = () => {};
+ function App() {
+ const [muted, set] = useState(true);
+ setMuted = set;
+ return <video data-testid="v" src="/media/renders/film.mp4" muted={muted} />;
+ }
+ mount(<App />, 0, { dom: true });
+ const id = host.tid("v");
+ flush();
+ expect(host.nodes.get(id)!.props.__muted).toBe(true);
+ flushSync(() => setMuted(false));
+ flush();
+ expect(host.nodes.get(id)!.props.__muted).toBe(false);
+ });
});