Skip to content

Commit 8780265

Browse files
AlbertMingXuMing Xu
andauthored
chore: dispatch starting_recording and stop_recording. (#342)
Co-authored-by: Ming Xu <[email protected]>
1 parent 6875d66 commit 8780265

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

backend/fastrtc/webrtc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class WebRTC(Component, WebRTCConnectionMixin):
5757
Demos: video_identity_2
5858
"""
5959

60-
EVENTS = ["tick", "state_change", "submit"]
60+
EVENTS = ["tick", "state_change", "submit", "start_recording", "stop_recording"]
6161
data_model = WebRTCModel
6262

6363
def __init__(

frontend/Index.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@
208208
{pulse_color}
209209
{button_labels}
210210
{variant}
211+
on:start_recording={() => gradio.dispatch("start_recording")}
212+
on:stop_recording={() => gradio.dispatch("stop_recording")}
211213
on:tick={() => gradio.dispatch("tick")}
212214
on:error={({ detail }) => gradio.dispatch("error", detail)}
213215
on:warning={({ detail }) => gradio.dispatch("warning", detail)}

frontend/shared/InteractiveAudio.svelte

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
error: string;
105105
play: undefined;
106106
stop: undefined;
107+
start_recording: undefined;
108+
stop_recording: undefined;
107109
}>();
108110
109111
async function access_mic(): Promise<void> {
@@ -147,13 +149,16 @@
147149
148150
async function start_stream(): Promise<void> {
149151
if (stream_state === "open") {
152+
dispatch("stop_recording");
150153
stop(pc);
151154
stream_state = "closed";
152155
_time_limit = null;
153156
await access_mic();
154157
await server.quit_output_stream({ webrtc_id: _webrtc_id });
155158
return;
156159
}
160+
161+
dispatch("start_recording");
157162
_webrtc_id = Math.random().toString(36).substring(2);
158163
value.webrtc_id = _webrtc_id;
159164
stream_state = "waiting";
@@ -325,6 +330,8 @@
325330
bind:this={audio_player}
326331
on:ended={() => dispatch("stop")}
327332
on:play={() => dispatch("play")}
333+
on:start_recording
334+
on:stop_recording
328335
/>
329336
{#if variant === "textbox"}
330337
<TextboxWithMic

frontend/shared/Webcam.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
147147
async function start_webrtc(): Promise<void> {
148148
if (stream_state === "closed") {
149+
dispatch("start_recording");
149150
await server.turn().then((rtc_configuration_) => {
150151
if (rtc_configuration_.error) {
151152
dispatch("error", rtc_configuration_.error);
@@ -207,6 +208,7 @@
207208
stream_state = "closed";
208209
});
209210
} else {
211+
dispatch("stop_recording");
210212
stop(pc);
211213
stream_state = "closed";
212214
_time_limit = null;

0 commit comments

Comments
 (0)