a
This commit is contained in:
@@ -228,6 +228,7 @@ export default function App() {
|
||||
voiceChannels={voice.voiceChannels}
|
||||
selectedGuild={selectedVoiceGuild}
|
||||
selectedChannel={uiState.selectedVoiceChannel || ""}
|
||||
micLevel={0}
|
||||
status={voice.voiceStatus}
|
||||
voiceLoading={voice.loading}
|
||||
activeSpeakers={activeSpeakers}
|
||||
|
||||
@@ -22,6 +22,7 @@ export function useVoiceControl() {
|
||||
activeGuildId: null,
|
||||
activeChannelId: null,
|
||||
activeChannelName: null,
|
||||
connections: [],
|
||||
});
|
||||
const { loading, error, execute, clearError } = useAsyncAction();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ─── 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";
|
||||
|
||||
const logger = createLogger("use-audio-playback");
|
||||
@@ -17,7 +17,15 @@ const LEVEL_SHAPE = Array.from(
|
||||
/** Reverse lookup: userIdHash → userId, populated by handleIncomingBinary */
|
||||
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 [levels, setLevels] = useState<number[]>(
|
||||
Array.from({ length: LEVEL_COUNT }, () => 0.04),
|
||||
|
||||
@@ -41,9 +41,20 @@ function sendWsCommand(
|
||||
return false;
|
||||
}
|
||||
|
||||
export function useAudioTransmit(socketRef: {
|
||||
readonly current: WebSocket | null;
|
||||
}) {
|
||||
export function useAudioTransmit(
|
||||
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 [micError, setMicError] = useState<string | null>(null);
|
||||
const [micLevel, setMicLevel] = useState(0);
|
||||
|
||||
Reference in New Issue
Block a user