mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 09:59:22 +08:00
Make sure channel is always set, be able to raise UI errors with WebRTCError (#45)
* Code * test * code * user guide
This commit is contained in:
@@ -38,7 +38,11 @@
|
||||
export let icon_button_color: string = "var(--color-accent)";
|
||||
export let pulse_color: string = "var(--color-accent)";
|
||||
|
||||
const on_change_cb = (msg: "change" | "tick") => {
|
||||
const on_change_cb = (msg: "change" | "tick" | any) => {
|
||||
if (msg?.type === "info" || msg?.type === "warning" || msg?.type === "error") {
|
||||
console.log("dispatching info", msg.message);
|
||||
gradio.dispatch(msg?.type === "error"? "error": "warning", msg.message);
|
||||
}
|
||||
gradio.dispatch(msg === "change" ? "state_change" : "tick");
|
||||
}
|
||||
|
||||
@@ -93,6 +97,7 @@
|
||||
i18n={gradio.i18n}
|
||||
on:tick={() => gradio.dispatch("tick")}
|
||||
on:error={({ detail }) => gradio.dispatch("error", detail)}
|
||||
|
||||
/>
|
||||
{:else if (mode === "send-receive" || mode == "send") && modality === "video"}
|
||||
<Video
|
||||
@@ -141,6 +146,7 @@
|
||||
{pulse_color}
|
||||
on:tick={() => gradio.dispatch("tick")}
|
||||
on:error={({ detail }) => gradio.dispatch("error", detail)}
|
||||
on:warning={({ detail }) => gradio.dispatch("warning", detail)}
|
||||
/>
|
||||
{/if}
|
||||
</Block>
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
});
|
||||
|
||||
let _on_change_cb = (msg: "change" | "tick" | "stopword") => {
|
||||
console.log("msg", msg);
|
||||
if (msg === "stopword") {
|
||||
console.log("stopword recognized");
|
||||
stopword_recognized = true;
|
||||
@@ -53,6 +54,7 @@
|
||||
stopword_recognized = false;
|
||||
}, 3000);
|
||||
} else {
|
||||
console.log("calling on_change_cb with msg", msg);
|
||||
on_change_cb(msg);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -64,13 +64,22 @@ export async function start(
|
||||
|
||||
data_channel.onmessage = (event) => {
|
||||
console.debug("Received message:", event.data);
|
||||
let event_json;
|
||||
try {
|
||||
event_json = JSON.parse(event.data);
|
||||
} catch (e) {
|
||||
console.debug("Error parsing JSON")
|
||||
}
|
||||
console.log("event_json", event_json);
|
||||
if (
|
||||
event.data === "change" ||
|
||||
event.data === "tick" ||
|
||||
event.data === "stopword"
|
||||
event.data === "stopword" ||
|
||||
event_json?.type === "warning" ||
|
||||
event_json?.type === "error"
|
||||
) {
|
||||
console.debug(`${event.data} event received`);
|
||||
on_change_cb(event.data);
|
||||
on_change_cb(event_json ?? event.data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user