Skip to content

Commit 60b3b57

Browse files
committed
add connecting state for audio
1 parent 2c95bfb commit 60b3b57

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

peerprep-fe/src/app/collaboration/components/AudioSharing.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { SignalData } from '@/types/types';
1212

1313
const AudioSharing = () => {
1414
const [isAudioEnabled, setIsAudioEnabled] = useState(false);
15+
const [connectionStatus, setConnectionStatus] = useState<
16+
'Not Connected' | 'Connecting' | 'Connected'
17+
>('Not Connected');
1518
const socketRef = useRef<Socket | null>(null);
1619
const peerRef = useRef<Instance | null>(null);
1720
const audioStreamRef = useRef<MediaStream | null>(null);
@@ -45,10 +48,12 @@ const AudioSharing = () => {
4548
peerRef.current = null;
4649
}
4750
setIsAudioEnabled(false);
51+
setConnectionStatus('Not Connected');
4852
};
4953

5054
const createPeer = (stream: MediaStream, initiator: boolean) => {
5155
console.log('Creating peer as initiator:', initiator);
56+
setConnectionStatus('Connecting');
5257

5358
const peer = new SimplePeer({
5459
initiator,
@@ -96,6 +101,7 @@ const AudioSharing = () => {
96101
// Add connection state logging
97102
peer.on('connect', () => {
98103
console.log('Peer connection established successfully');
104+
setConnectionStatus('Connected');
99105
});
100106

101107
return peer;
@@ -190,12 +196,18 @@ const AudioSharing = () => {
190196
};
191197

192198
return (
193-
<div>
194-
<button onClick={toggleAudio}>
199+
<div className="flex items-center gap-4">
200+
<button
201+
onClick={toggleAudio}
202+
className="flex items-center gap-1 rounded bg-green-800 px-2 py-1 font-bold text-white transition duration-300 hover:bg-green-700"
203+
>
195204
<FontAwesomeIcon
196205
icon={isAudioEnabled ? faMicrophone : faMicrophoneSlash}
197206
/>
198-
{isAudioEnabled ? ' Mute' : ' Unmute'}
207+
{connectionStatus === 'Connected' &&
208+
(isAudioEnabled ? 'Mute' : 'Unmute')}
209+
{connectionStatus === 'Not Connected' && 'Connect'}
210+
{connectionStatus === 'Connecting' && 'Connecting'}
199211
</button>
200212
</div>
201213
);

0 commit comments

Comments
 (0)