mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 18:09:23 +08:00
@@ -51,12 +51,16 @@
|
||||
}
|
||||
});
|
||||
|
||||
let _on_change_cb = (msg: "change" | "tick" | "stopword") => {
|
||||
let _on_change_cb = (msg: "change" | "tick" | "stopword" | any) => {
|
||||
if (msg === "stopword") {
|
||||
stopword_recognized = true;
|
||||
setTimeout(() => {
|
||||
stopword_recognized = false;
|
||||
}, 3000);
|
||||
} else if (msg.type === "end_stream") {
|
||||
stream_state = "closed";
|
||||
stop(pc);
|
||||
on_change_cb(msg);
|
||||
} else {
|
||||
console.debug("calling on_change_cb with msg", msg);
|
||||
on_change_cb(msg);
|
||||
|
||||
@@ -29,6 +29,17 @@
|
||||
let pc: RTCPeerConnection;
|
||||
let _webrtc_id = Math.random().toString(36).substring(2);
|
||||
|
||||
let _on_change_cb = (msg: "change" | "tick" | "stopword" | any) => {
|
||||
if (msg.type === "end_stream") {
|
||||
on_change_cb(msg);
|
||||
stream_state = "closed";
|
||||
stop(pc);
|
||||
} else {
|
||||
console.debug("calling on_change_cb with msg", msg);
|
||||
on_change_cb(msg);
|
||||
}
|
||||
};
|
||||
|
||||
const dispatch = createEventDispatcher<{
|
||||
tick: undefined;
|
||||
error: string;
|
||||
@@ -75,7 +86,7 @@
|
||||
server.offer,
|
||||
_webrtc_id,
|
||||
"audio",
|
||||
on_change_cb,
|
||||
_on_change_cb,
|
||||
)
|
||||
.then((connection) => {
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
@@ -25,6 +25,17 @@
|
||||
tick: undefined;
|
||||
}>();
|
||||
|
||||
let _on_change_cb = (msg: "change" | "tick" | "stopword" | any) => {
|
||||
if (msg.type === "end_stream") {
|
||||
on_change_cb(msg);
|
||||
stream_state = "closed";
|
||||
stop(pc);
|
||||
} else {
|
||||
console.debug("calling on_change_cb with msg", msg);
|
||||
on_change_cb(msg);
|
||||
}
|
||||
};
|
||||
|
||||
let stream_state = "closed";
|
||||
|
||||
$: if (value === "start_webrtc_stream") {
|
||||
@@ -62,7 +73,7 @@
|
||||
server.offer,
|
||||
_webrtc_id,
|
||||
"video",
|
||||
on_change_cb,
|
||||
_on_change_cb,
|
||||
)
|
||||
.then((connection) => {
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
@@ -124,6 +124,18 @@
|
||||
}
|
||||
}
|
||||
|
||||
let _on_change_cb = (msg: "change" | "tick" | "stopword" | any) => {
|
||||
if (msg.type === "end_stream") {
|
||||
on_change_cb(msg);
|
||||
stream_state = "closed";
|
||||
stop(pc);
|
||||
access_webcam();
|
||||
} else {
|
||||
console.debug("calling on_change_cb with msg", msg);
|
||||
on_change_cb(msg);
|
||||
}
|
||||
};
|
||||
|
||||
let recording = false;
|
||||
let stream: MediaStream;
|
||||
|
||||
@@ -171,7 +183,7 @@
|
||||
server.offer,
|
||||
webrtc_id,
|
||||
"video",
|
||||
on_change_cb,
|
||||
_on_change_cb,
|
||||
rtp_params,
|
||||
undefined,
|
||||
reject_cb,
|
||||
|
||||
@@ -80,7 +80,8 @@ export async function start(
|
||||
event_json?.type === "error" ||
|
||||
event_json?.type === "send_input" ||
|
||||
event_json?.type === "fetch_output" ||
|
||||
event_json?.type === "stopword"
|
||||
event_json?.type === "stopword" ||
|
||||
event_json?.type === "end_stream"
|
||||
) {
|
||||
on_change_cb(event_json ?? event.data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user