feat(realtime): add voice/video recording activity events
Some checks are pending
CI / test (push) Has started running

This commit is contained in:
2026-03-08 19:53:48 +03:00
parent 1ef0cdf29d
commit ac82e25d16
8 changed files with 135 additions and 9 deletions

View File

@@ -307,6 +307,22 @@ export function MessageComposer() {
return wsRef.current;
}
function sendRealtimeChatEvent(
eventName:
| "typing_start"
| "typing_stop"
| "recording_voice_start"
| "recording_voice_stop"
| "recording_video_start"
| "recording_video_stop"
) {
if (!activeChatId) {
return;
}
const ws = getWs();
ws?.send(JSON.stringify({ event: eventName, payload: { chat_id: activeChatId } }));
}
async function handleSend() {
if (!activeChatId || !text.trim() || !me || !canSendInActiveChat) {
return;
@@ -347,8 +363,7 @@ export function MessageComposer() {
setText("");
clearDraft(activeChatId);
setReplyToMessage(activeChatId, null);
const ws = getWs();
ws?.send(JSON.stringify({ event: "typing_stop", payload: { chat_id: activeChatId } }));
sendRealtimeChatEvent("typing_stop");
} catch {
removeOptimisticMessage(activeChatId, clientMessageId);
setUploadError("Message send failed. Please try again.");
@@ -619,6 +634,8 @@ export function MessageComposer() {
recordingStartedAtRef.current = Date.now();
setRecordSeconds(0);
setRecordingState("recording");
sendRealtimeChatEvent("typing_stop");
sendRealtimeChatEvent("recording_voice_start");
return true;
} catch {
setUploadError("Microphone access denied. Please allow microphone and retry.");
@@ -627,6 +644,9 @@ export function MessageComposer() {
}
function stopRecord(send: boolean) {
if (recordingStateRef.current !== "idle") {
sendRealtimeChatEvent("recording_voice_stop");
}
sendVoiceOnStopRef.current = send;
pointerCancelArmedRef.current = false;
setDragHint("idle");
@@ -1274,8 +1294,7 @@ export function MessageComposer() {
setText(next);
if (activeChatId) {
setDraft(activeChatId, next);
const ws = getWs();
ws?.send(JSON.stringify({ event: "typing_start", payload: { chat_id: activeChatId } }));
sendRealtimeChatEvent(next.trim().length > 0 ? "typing_start" : "typing_stop");
}
}}
/>