Skip to content
Open
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
45 changes: 45 additions & 0 deletions client/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ let chat: any = null;
let userId: string = '';
let channelHash: string = '';
let privateKey: string = '';
let joinAudio: HTMLAudioElement | null = null;

let isMuted: boolean = false;

try {
isMuted = localStorage.getItem('mute') === 'true';
} catch {
isMuted = false;
}

const toggleSoundBtn = document.getElementById('toggle-sound-btn');

if (toggleSoundBtn instanceof HTMLButtonElement) {
toggleSoundBtn.textContent = isMuted ? '🔕' : '🔔';

toggleSoundBtn.addEventListener('click', () => {
isMuted = !isMuted;

try {
localStorage.setItem('mute', String(isMuted));
} catch (err) {
console.warn('Unable to persist mute preference', err);
}

toggleSoundBtn.textContent = isMuted ? '🔕' : '🔔';
});
}


// DOM Elements
// DOM Elements
Expand Down Expand Up @@ -41,12 +69,28 @@ const callStatusText = document.getElementById('call-status')!;
const endCallBtn = document.getElementById('end-call-btn') as HTMLButtonElement;
const callDuration = document.getElementById('call-duration')!;


function playJoinBeep() {
if (!joinAudio || isMuted) return;

try {
joinAudio.currentTime = 0;
joinAudio.play().catch((err) => {
console.warn('Audio playback prevented:',err);
});
} catch (err) {
console.error('Audio play error:', err);
}
}

// Initialize Chat
async function initChat() {
try {
setupStatus.textContent = 'Initializing secure keys...';
chat = createChatInstance();
await chat.init();
joinAudio = new Audio('/sound/beep.mp3');
joinAudio.volume = 0.5;

const keys = chat.getKeyPair();
privateKey = keys.privateKey;
Expand Down Expand Up @@ -183,6 +227,7 @@ function setupChatListeners() {
chat.on('on-alice-join', () => {
chatHeader.classList.add('active');
participantInfo.textContent = 'Peer joined. Communication is encrypted.';
playJoinBeep();
});

chat.on('on-alice-disconnect', () => {
Expand Down
2 changes: 2 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ <h2 id="channel-title">Secure Channel</h2>
</path>
</svg>
</button>

<button id="toggle-sound-btn">🔔</button>
</div>
</header>

Expand Down
Binary file added client/sound/beep.mp3
Binary file not shown.
Loading