a
This commit is contained in:
@@ -228,6 +228,7 @@ export default function App() {
|
|||||||
voiceChannels={voice.voiceChannels}
|
voiceChannels={voice.voiceChannels}
|
||||||
selectedGuild={selectedVoiceGuild}
|
selectedGuild={selectedVoiceGuild}
|
||||||
selectedChannel={uiState.selectedVoiceChannel || ""}
|
selectedChannel={uiState.selectedVoiceChannel || ""}
|
||||||
|
micLevel={0}
|
||||||
status={voice.voiceStatus}
|
status={voice.voiceStatus}
|
||||||
voiceLoading={voice.loading}
|
voiceLoading={voice.loading}
|
||||||
activeSpeakers={activeSpeakers}
|
activeSpeakers={activeSpeakers}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export function useVoiceControl() {
|
|||||||
activeGuildId: null,
|
activeGuildId: null,
|
||||||
activeChannelId: null,
|
activeChannelId: null,
|
||||||
activeChannelName: null,
|
activeChannelName: null,
|
||||||
|
connections: [],
|
||||||
});
|
});
|
||||||
const { loading, error, execute, clearError } = useAsyncAction();
|
const { loading, error, execute, clearError } = useAsyncAction();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// ─── Audio playback hook — receives PCM from WebSocket and plays through Web Audio API ──
|
// ─── Audio playback hook — receives PCM from WebSocket and plays through Web Audio API ──
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState, type RefObject } from "react";
|
||||||
import { createLogger } from "../lib/logger.js";
|
import { createLogger } from "../lib/logger.js";
|
||||||
|
|
||||||
const logger = createLogger("use-audio-playback");
|
const logger = createLogger("use-audio-playback");
|
||||||
@@ -17,7 +17,15 @@ const LEVEL_SHAPE = Array.from(
|
|||||||
/** Reverse lookup: userIdHash → userId, populated by handleIncomingBinary */
|
/** Reverse lookup: userIdHash → userId, populated by handleIncomingBinary */
|
||||||
const userIdHashToId = new Map<number, string>();
|
const userIdHashToId = new Map<number, string>();
|
||||||
|
|
||||||
export function useAudioPlayback() {
|
export function useAudioPlayback(): {
|
||||||
|
isListening: boolean;
|
||||||
|
levels: number[];
|
||||||
|
handleIncomingPcm: (data: { userId: string; pcm: string }) => void;
|
||||||
|
handleIncomingBinary: (data: ArrayBuffer) => void;
|
||||||
|
registerUserId: (userId: string) => void;
|
||||||
|
toggleListening: () => Promise<void>;
|
||||||
|
audioContextRef: RefObject<AudioContext | null>;
|
||||||
|
} {
|
||||||
const [isListening, setIsListening] = useState(false);
|
const [isListening, setIsListening] = useState(false);
|
||||||
const [levels, setLevels] = useState<number[]>(
|
const [levels, setLevels] = useState<number[]>(
|
||||||
Array.from({ length: LEVEL_COUNT }, () => 0.04),
|
Array.from({ length: LEVEL_COUNT }, () => 0.04),
|
||||||
|
|||||||
@@ -41,9 +41,20 @@ function sendWsCommand(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAudioTransmit(socketRef: {
|
export function useAudioTransmit(
|
||||||
readonly current: WebSocket | null;
|
socketRef: {
|
||||||
}) {
|
readonly current: WebSocket | null;
|
||||||
|
},
|
||||||
|
): {
|
||||||
|
isStreaming: boolean;
|
||||||
|
micError: string | null;
|
||||||
|
micLevel: number;
|
||||||
|
toggle: () => Promise<void>;
|
||||||
|
stopTransmit: () => void;
|
||||||
|
startTransmit: () => Promise<void>;
|
||||||
|
stop: () => void;
|
||||||
|
start: () => Promise<void>;
|
||||||
|
} {
|
||||||
const [isStreaming, setIsStreaming] = useState(false);
|
const [isStreaming, setIsStreaming] = useState(false);
|
||||||
const [micError, setMicError] = useState<string | null>(null);
|
const [micError, setMicError] = useState<string | null>(null);
|
||||||
const [micLevel, setMicLevel] = useState(0);
|
const [micLevel, setMicLevel] = useState(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user