Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/assets/app/sounds/vcConnect.mp3
Binary file not shown.
Binary file added public/assets/app/sounds/vcDisconnect.mp3
Binary file not shown.
15 changes: 14 additions & 1 deletion src/sockets/voiceChatSocket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import io from 'socket.io-client';
import { playSound, SOUNDS } from '../utils/playSound';

const SOCKET_URL = import.meta.env.VITE_SERVER_URL;

Expand Down Expand Up @@ -468,6 +469,10 @@ export function createVoiceChatSocket(
socket.on('user-joined-voice', async ({ userId: newUserId }) => {
if (newUserId === userId) return;

if (localStream) {
playSound(SOUNDS.VC_CONNECT, 0.6).catch(() => {});
}

if (!localStream) {
console.log(`[VoiceChat] user-joined-voice from ${newUserId} ignored — not in voice yet`);
return;
Expand Down Expand Up @@ -499,6 +504,10 @@ export function createVoiceChatSocket(
});

socket.on('user-left-voice', ({ userId: leftUserId }) => {
if (localStream) {
playSound(SOUNDS.VC_DISCONNECT, 0.6).catch(() => {});
}

const pc = peerConnections.get(leftUserId);
if (pc) { pc.close(); peerConnections.delete(leftUserId); }
const stream = audioStreams.get(leftUserId);
Expand Down Expand Up @@ -595,7 +604,10 @@ export function createVoiceChatSocket(
socket,
joinVoice: () => {
initializeAudio().then(ok => {
if (ok) socket.emit('join-voice-session');
if (ok) {
socket.emit('join-voice-session');
playSound(SOUNDS.VC_CONNECT, 0.6).catch(() => {});
}
});
},
getVoiceUsers: () => socket.emit('get-voice-users'),
Expand Down Expand Up @@ -642,6 +654,7 @@ export function createVoiceChatSocket(
},
leaveVoice: () => {
socket.emit('leave-voice-session');
playSound(SOUNDS.VC_DISCONNECT, 0.6).catch(() => {});
cleanupRTC();
},
cleanup,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/playSound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,6 @@ export const SOUNDS = {
NEW_STRIP: '/assets/app/sounds/newStrip.mp3',
ACARS_BEEP: '/assets/app/sounds/ACARSBeep.wav',
ACARS_CHAT_POP: '/assets/app/sounds/ACARSChatPop.mp3',
VC_CONNECT: '/assets/app/sounds/vcConnect.mp3',
VC_DISCONNECT: '/assets/app/sounds/vcDisconnect.mp3',
} as const;