Skip to content

Commit 3dc196b

Browse files
committed
Fix: lint errors
1 parent 575abb7 commit 3dc196b

File tree

5 files changed

+78
-27
lines changed

5 files changed

+78
-27
lines changed

ui/src/components/ActionBar.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ import AudioControlPopover from "@/components/popovers/AudioControlPopover";
2222
import { useDeviceUiNavigation } from "@/hooks/useAppNavigation";
2323
import api from "@/api";
2424

25+
// Type for microphone error
26+
interface MicrophoneError {
27+
type: 'permission' | 'device' | 'network' | 'unknown';
28+
message: string;
29+
}
30+
2531
// Type for microphone hook return value
2632
interface MicrophoneHookReturn {
2733
isMicrophoneActive: boolean;
2834
isMicrophoneMuted: boolean;
2935
microphoneStream: MediaStream | null;
30-
startMicrophone: (deviceId?: string) => Promise<{ success: boolean; error?: any }>;
31-
stopMicrophone: () => Promise<{ success: boolean; error?: any }>;
32-
toggleMicrophoneMute: () => Promise<{ success: boolean; error?: any }>;
36+
startMicrophone: (deviceId?: string) => Promise<{ success: boolean; error?: MicrophoneError }>;
37+
stopMicrophone: () => Promise<{ success: boolean; error?: MicrophoneError }>;
38+
toggleMicrophoneMute: () => Promise<{ success: boolean; error?: MicrophoneError }>;
3339
syncMicrophoneState: () => Promise<void>;
3440
}
3541

ui/src/components/WebRTCVideo.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,20 @@ import {
2525
PointerLockBar,
2626
} from "./VideoOverlay";
2727

28+
// Type for microphone error
29+
interface MicrophoneError {
30+
type: 'permission' | 'device' | 'network' | 'unknown';
31+
message: string;
32+
}
33+
2834
// Interface for microphone hook return type
2935
interface MicrophoneHookReturn {
3036
isMicrophoneActive: boolean;
3137
isMicrophoneMuted: boolean;
3238
microphoneStream: MediaStream | null;
33-
startMicrophone: (deviceId?: string) => Promise<{ success: boolean; error?: any }>;
34-
stopMicrophone: () => Promise<{ success: boolean; error?: any }>;
35-
toggleMicrophoneMute: () => Promise<{ success: boolean; error?: any }>;
39+
startMicrophone: (deviceId?: string) => Promise<{ success: boolean; error?: MicrophoneError }>;
40+
stopMicrophone: () => Promise<{ success: boolean; error?: MicrophoneError }>;
41+
toggleMicrophoneMute: () => Promise<{ success: boolean; error?: MicrophoneError }>;
3642
syncMicrophoneState: () => Promise<void>;
3743
}
3844

ui/src/components/popovers/AudioControlPopover.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,20 @@ import { useAudioLevel } from "@/hooks/useAudioLevel";
1111
import api from "@/api";
1212
import notifications from "@/notifications";
1313

14+
// Type for microphone error
15+
interface MicrophoneError {
16+
type: 'permission' | 'device' | 'network' | 'unknown';
17+
message: string;
18+
}
19+
1420
// Type for microphone hook return value
1521
interface MicrophoneHookReturn {
1622
isMicrophoneActive: boolean;
1723
isMicrophoneMuted: boolean;
1824
microphoneStream: MediaStream | null;
19-
startMicrophone: (deviceId?: string) => Promise<{ success: boolean; error?: any }>;
20-
stopMicrophone: () => Promise<{ success: boolean; error?: any }>;
21-
toggleMicrophoneMute: () => Promise<{ success: boolean; error?: any }>;
25+
startMicrophone: (deviceId?: string) => Promise<{ success: boolean; error?: MicrophoneError }>;
26+
stopMicrophone: () => Promise<{ success: boolean; error?: MicrophoneError }>;
27+
toggleMicrophoneMute: () => Promise<{ success: boolean; error?: MicrophoneError }>;
2228
syncMicrophoneState: () => Promise<void>;
2329
}
2430

@@ -276,9 +282,9 @@ export default function AudioControlPopover({ microphone }: AudioControlPopoverP
276282
const videoElement = document.querySelector('video');
277283
if (videoElement && 'setSinkId' in videoElement) {
278284
try {
279-
await (videoElement as any).setSinkId(deviceId);
285+
await (videoElement as HTMLVideoElement & { setSinkId: (deviceId: string) => Promise<void> }).setSinkId(deviceId);
280286
console.log('Audio output device changed to:', deviceId);
281-
} catch (error) {
287+
} catch (error: unknown) {
282288
console.error('Failed to change audio output device:', error);
283289
}
284290
} else {

ui/src/hooks/useAudioLevel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const useAudioLevel = (stream: MediaStream | null): AudioLevelHookResult
4343

4444
try {
4545
// Create audio context and analyser
46-
const audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
46+
const audioContext = new (window.AudioContext || (window as Window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext)();
4747
const analyser = audioContext.createAnalyser();
4848
const source = audioContext.createMediaStreamSource(stream);
4949

@@ -68,8 +68,8 @@ export const useAudioLevel = (stream: MediaStream | null): AudioLevelHookResult
6868

6969
// Calculate RMS (Root Mean Square) for more accurate level representation
7070
let sum = 0;
71-
for (let i = 0; i < dataArray.length; i++) {
72-
sum += dataArray[i] * dataArray[i];
71+
for (const value of dataArray) {
72+
sum += value * value;
7373
}
7474
const rms = Math.sqrt(sum / dataArray.length);
7575

ui/src/hooks/useMicrophone.ts

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useCallback, useEffect, useRef } from "react";
2+
23
import { useRTCStore } from "@/hooks/stores";
34
import api from "@/api";
45

@@ -97,9 +98,9 @@ export function useMicrophone() {
9798

9899
// Make debug function available globally for console access
99100
useEffect(() => {
100-
(window as any).debugMicrophoneState = debugMicrophoneState;
101+
(window as Window & { debugMicrophoneState?: () => unknown }).debugMicrophoneState = debugMicrophoneState;
101102
return () => {
102-
delete (window as any).debugMicrophoneState;
103+
delete (window as Window & { debugMicrophoneState?: () => unknown }).debugMicrophoneState;
103104
};
104105
}, [debugMicrophoneState]);
105106

@@ -396,7 +397,7 @@ export function useMicrophone() {
396397
isStartingRef.current = false;
397398
return { success: false, error: micError };
398399
}
399-
}, [peerConnection, setMicrophoneStream, setMicrophoneSender, setMicrophoneActive, setMicrophoneMuted, syncMicrophoneState, stopMicrophoneStream]);
400+
}, [peerConnection, setMicrophoneStream, setMicrophoneSender, setMicrophoneActive, setMicrophoneMuted, stopMicrophoneStream, isMicrophoneActive, isMicrophoneMuted, microphoneStream]);
400401

401402
// Stop microphone
402403
const stopMicrophone = useCallback(async (): Promise<{ success: boolean; error?: MicrophoneError }> => {
@@ -519,7 +520,15 @@ export function useMicrophone() {
519520

520521
try {
521522
const stats = await microphoneSender.getStats();
522-
const audioStats: any[] = [];
523+
const audioStats: {
524+
id: string;
525+
type: string;
526+
kind: string;
527+
packetsSent?: number;
528+
bytesSent?: number;
529+
timestamp?: number;
530+
ssrc?: number;
531+
}[] = [];
523532

524533
stats.forEach((report, id) => {
525534
if (report.type === 'outbound-rtp' && report.kind === 'audio') {
@@ -576,7 +585,7 @@ export function useMicrophone() {
576585

577586
// 3. Test audio level detection manually
578587
try {
579-
const audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
588+
const audioContext = new (window.AudioContext || (window as Window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext)();
580589
const analyser = audioContext.createAnalyser();
581590
const source = audioContext.createMediaStreamSource(stream);
582591

@@ -595,8 +604,8 @@ export function useMicrophone() {
595604
analyser.getByteFrequencyData(dataArray);
596605

597606
let sum = 0;
598-
for (let i = 0; i < dataArray.length; i++) {
599-
sum += dataArray[i] * dataArray[i];
607+
for (const value of dataArray) {
608+
sum += value * value;
600609
}
601610
const rms = Math.sqrt(sum / dataArray.length);
602611
const level = Math.min(100, (rms / 255) * 100);
@@ -672,13 +681,37 @@ export function useMicrophone() {
672681

673682
// Make debug functions available globally for console access
674683
useEffect(() => {
675-
(window as any).debugMicrophone = debugMicrophoneState;
676-
(window as any).checkAudioStats = checkAudioTransmissionStats;
677-
(window as any).testMicrophoneAudio = testMicrophoneAudio;
684+
(window as Window & {
685+
debugMicrophone?: () => unknown;
686+
checkAudioStats?: () => unknown;
687+
testMicrophoneAudio?: () => unknown;
688+
}).debugMicrophone = debugMicrophoneState;
689+
(window as Window & {
690+
debugMicrophone?: () => unknown;
691+
checkAudioStats?: () => unknown;
692+
testMicrophoneAudio?: () => unknown;
693+
}).checkAudioStats = checkAudioTransmissionStats;
694+
(window as Window & {
695+
debugMicrophone?: () => unknown;
696+
checkAudioStats?: () => unknown;
697+
testMicrophoneAudio?: () => unknown;
698+
}).testMicrophoneAudio = testMicrophoneAudio;
678699
return () => {
679-
delete (window as any).debugMicrophone;
680-
delete (window as any).checkAudioStats;
681-
delete (window as any).testMicrophoneAudio;
700+
delete (window as Window & {
701+
debugMicrophone?: () => unknown;
702+
checkAudioStats?: () => unknown;
703+
testMicrophoneAudio?: () => unknown;
704+
}).debugMicrophone;
705+
delete (window as Window & {
706+
debugMicrophone?: () => unknown;
707+
checkAudioStats?: () => unknown;
708+
testMicrophoneAudio?: () => unknown;
709+
}).checkAudioStats;
710+
delete (window as Window & {
711+
debugMicrophone?: () => unknown;
712+
checkAudioStats?: () => unknown;
713+
testMicrophoneAudio?: () => unknown;
714+
}).testMicrophoneAudio;
682715
};
683716
}, [debugMicrophoneState, checkAudioTransmissionStats, testMicrophoneAudio]);
684717

0 commit comments

Comments
 (0)