-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40a8f62
commit a7236b8
Showing
5 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "chatter", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"module": "index.ts", | ||
"type": "module", | ||
"packageManager": "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export class AudioManager { | ||
constructor() { | ||
this.notificationSound = new Audio('/public/sounds/notification.mp3'); | ||
this.notificationSound.volume = 1; // Full volume | ||
|
||
// Handle loading errors | ||
this.notificationSound.addEventListener('error', (e) => { | ||
console.error('Error loading notification sound:', e.error); | ||
}); | ||
|
||
// Preload the audio | ||
this.notificationSound.load(); | ||
} | ||
|
||
playMessageNotification(overrideFocus = false) { | ||
// Only play if the window is not focused (unless overrideFocus is true) | ||
if (!document.hasFocus() || overrideFocus) { | ||
try { | ||
this.notificationSound.currentTime = 0; // Reset audio to start | ||
const playPromise = this.notificationSound.play(); | ||
|
||
if (playPromise !== undefined) { | ||
playPromise.catch(error => { | ||
console.log('Error playing notification sound:', error); | ||
}); | ||
} | ||
} catch (error) { | ||
console.error('Error playing notification sound:', error); | ||
} | ||
} | ||
} | ||
|
||
setVolume(volume) { | ||
// volume should be between 0 and 1 | ||
this.notificationSound.volume = Math.max(0, Math.min(1, volume)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.