Skip to content

Commit

Permalink
Merge pull request #148 from CS3219-AY2425S1/fix-any
Browse files Browse the repository at this point in the history
fix bugs in fe
  • Loading branch information
tyouwei authored Nov 6, 2024
2 parents b4dc7ba + 24453f9 commit fc2e57f
Show file tree
Hide file tree
Showing 6 changed files with 921 additions and 1,088 deletions.
11 changes: 6 additions & 5 deletions peerprep-fe/src/app/collaboration/components/AudioSharing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
faMicrophone,
faMicrophoneSlash,
} from '@fortawesome/free-solid-svg-icons';
import { SignalData } from '@/types/types';

const AudioSharing = () => {
const [isAudioEnabled, setIsAudioEnabled] = useState(false);
Expand Down Expand Up @@ -48,7 +49,7 @@ const AudioSharing = () => {
},
});

peer.on('signal', (data: any) => {
peer.on('signal', (data: SignalData) => {
console.log('Sending signal data:', data);
socketRef.current?.emit('signal', data);
});
Expand All @@ -62,7 +63,7 @@ const AudioSharing = () => {
.catch((error) => console.error('Error playing audio:', error));
});

peer.on('error', (err: any) => {
peer.on('error', (err: Error) => {
console.error('Peer connection error:', err);
cleanupAudio();
});
Expand Down Expand Up @@ -91,12 +92,12 @@ const AudioSharing = () => {
console.log('Socket connected');
});

socketRef.current.on('connect_error', (error: any) => {
socketRef.current.on('connect_error', (error: Error) => {
console.error('Connection error:', error);
cleanupAudio();
});

socketRef.current.on('signal', async (data: any) => {
socketRef.current.on('signal', async (data: SignalData) => {
console.log('Received signal data:', data);

if (data.type === 'offer' && !peerRef.current) {
Expand All @@ -122,7 +123,7 @@ const AudioSharing = () => {

if (peerRef.current) {
try {
peerRef.current.signal(data);
peerRef.current.signal(data as SimplePeer.SignalData);
} catch (error) {
console.error('Error signaling peer:', error);
cleanupAudio();
Expand Down
5 changes: 3 additions & 2 deletions peerprep-fe/src/app/collaboration/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import Editor, { OnMount } from '@monaco-editor/react';
import { Button } from '@/components/ui/button';
import { Play } from 'lucide-react';
import ConsoleCard from './ConsoleCard';
import { toast, useToast } from '@/hooks/use-toast';
import { toast } from '@/hooks/use-toast';
import { executeCode } from '../api/codeRunner';
import { editor } from 'monaco-editor';

interface CodeEditorProps {
onMount: OnMount;
Expand All @@ -22,7 +23,7 @@ const CodeEditor: React.FC<CodeEditorProps> = ({
const [showOutput, setShowOutput] = useState(false);
const [output, setOutput] = useState('');
const cardRef = useRef<HTMLDivElement>(null);
const editorRef = useRef<any>(null);
const editorRef = useRef<editor.IStandaloneCodeEditor | null>(null);

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
Expand Down
2 changes: 2 additions & 0 deletions peerprep-fe/src/app/collaboration/components/ConsoleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ const ConsoleCard = forwardRef<HTMLDivElement, ConsoleCardProp>(
},
);

ConsoleCard.displayName = 'ConsoleCard';

export default ConsoleCard;
11 changes: 10 additions & 1 deletion peerprep-fe/src/app/collaboration/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ import React, {
import { useSearchParams } from 'next/navigation';
import LoadingSpinner from '@/components/loading/LoadingSpinner';
import { useCollaborationStore } from '@/state/useCollaborationStore';
import CollaborationEditor from './components/CollaborationEditor';
import dynamic from 'next/dynamic';
import EditorSkeleton from './components/EditorSkeleton';

const CollaborationEditor = dynamic(
() => import('./components/CollaborationEditor'),
{
ssr: false,
loading: () => <EditorSkeleton />,
},
);

function CollaborationPageContent() {
const [selectionProblem, setSelectionProblem] = useState<Problem | null>(
Expand Down
7 changes: 7 additions & 0 deletions peerprep-fe/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ interface ConnectedClient {
user: AwarenessUser;
}

// audio
interface SignalData {
type?: string;
[key: string]: string | undefined;
}

export type {
Problem,
ProblemDialogData,
Expand All @@ -92,4 +98,5 @@ export type {
UserMatchingRequest,
AwarenessState,
ConnectedClient,
SignalData,
};
Loading

0 comments on commit fc2e57f

Please sign in to comment.