From 5f3237d559b5d21b2f3b8dfbd645e27a0c9ecd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=9D=D0=B0=D0=B4=D0=B5?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Wed, 3 Dec 2025 13:27:24 +0300 Subject: [PATCH] =?UTF-8?q?feat(notifications):=20=D1=83=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D1=88=D0=B5=D0=BD=D0=B0=20=D1=81=D0=B8=D1=81=D1=82=D0=B5=D0=BC?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B2=D1=83=D0=BA=D0=BE=D0=B2=20=D1=83=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Приоритет: сначала MP3 файл, fallback на Web Audio API - Удален дублирующийся метод playNotificationSound() - Добавлен playFallbackSound() для резервного синтетического звука - Удалено неиспользуемое поле notificationSound - Улучшена обработка ошибок воспроизведения --- .../js/notifications/notification-manager.js | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/backend/static/js/notifications/notification-manager.js b/backend/static/js/notifications/notification-manager.js index 68e389ce..956320ad 100644 --- a/backend/static/js/notifications/notification-manager.js +++ b/backend/static/js/notifications/notification-manager.js @@ -13,7 +13,6 @@ class NotificationManager { this.isConnected = false; this.notificationPermission = 'default'; this.soundEnabled = this.loadSoundPreference(); - this.notificationSound = null; this.init(); } @@ -36,12 +35,30 @@ class NotificationManager { /** * Воспроизвести звук уведомления + * Приоритет: 1) MP3 файл, 2) Web Audio API (fallback) */ playNotificationSound() { if (!this.soundEnabled) return; - if (!this.notificationSound) { - // Создаем короткий звук через Web Audio API + try { + // Попытка воспроизвести MP3 файл + const audio = new Audio('/static/sounds/notification.mp3'); + audio.volume = 0.3; + audio.play().catch(() => { + // Fallback на Web Audio API если MP3 недоступен + this.playFallbackSound(); + }); + } catch (error) { + // Fallback на Web Audio API + this.playFallbackSound(); + } + } + + /** + * Резервный метод: синтетический звук через Web Audio API + */ + playFallbackSound() { + try { const audioContext = new (window.AudioContext || window.webkitAudioContext)(); const oscillator = audioContext.createOscillator(); const gainNode = audioContext.createGain(); @@ -57,6 +74,8 @@ class NotificationManager { oscillator.start(audioContext.currentTime); oscillator.stop(audioContext.currentTime + 0.3); + } catch (error) { + console.warn('[Notifications] Sound playback failed:', error); } } @@ -425,19 +444,6 @@ class NotificationManager { }); } - playNotificationSound() { - // Опциональный звук уведомления - try { - const audio = new Audio('/static/sounds/notification.mp3'); - audio.volume = 0.3; - audio.play().catch(() => { - // Игнорировать ошибки воспроизведения - }); - } catch (error) { - // Звук не критичен - } - } - async markAsRead(notificationId) { try { const response = await fetch(`/api/notifications/${notificationId}/read/`, {