diff --git a/public/sound/chat-incoming.wav b/public/sound/chat-incoming.wav new file mode 100644 index 0000000000..4ad54e4a67 Binary files /dev/null and b/public/sound/chat-incoming.wav differ diff --git a/public/sound/chat-outgoing.wav b/public/sound/chat-outgoing.wav index 4ad54e4a67..cb50a587a6 100644 Binary files a/public/sound/chat-outgoing.wav and b/public/sound/chat-outgoing.wav differ diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js index a79e213b48..5818c36b03 100644 --- a/public/src/modules/chat.js +++ b/public/src/modules/chat.js @@ -1,4 +1,4 @@ -define(['taskbar', 'string'], function(taskbar, S) { +define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) { var module = {}; @@ -69,6 +69,8 @@ define(['taskbar', 'string'], function(taskbar, S) { app.alternatingTitle(data.username + ' has messaged you'); }); } + + sound.play('chat-incoming'); }); } @@ -220,6 +222,7 @@ define(['taskbar', 'string'], function(taskbar, S) { msg = msg +'\n'; socket.emit('modules.chats.send', { touid:chatModal.touid, message:msg}); chatModal.find('#chat-message-input').val(''); + sound.play('chat-outgoing'); } } diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index 2d150379a2..37bb81329d 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -1,4 +1,4 @@ -define(function() { +define(['sound'], function(sound) { var Notifications = {}; Notifications.prepareDOM = function() { @@ -108,6 +108,8 @@ define(function() { var savedCount = parseInt(localStorage.getItem('notifications:count'), 10) || 0; updateNotifCount(savedCount + 1); + + sound.play('notification'); }); socket.on('event:notifications.updateCount', function(count) { updateNotifCount(count); diff --git a/public/src/modules/sound.js b/public/src/modules/sound.js new file mode 100644 index 0000000000..0c51cdf9a6 --- /dev/null +++ b/public/src/modules/sound.js @@ -0,0 +1,43 @@ +"use strict"; + +define(['buzz'], function(buzz) { + var Sound = {}; + + Sound.initialised = false; + Sound.loaded = {}; + + Sound.init = function(callback) { + var sounds = { + notification: RELATIVE_PATH + '/sound/notification.wav', + 'chat-outgoing': RELATIVE_PATH + '/sound/chat-outgoing.wav', + 'chat-incoming': RELATIVE_PATH + '/sound/chat-incoming.wav' + }; + + for(var name in sounds) { + if (sounds.hasOwnProperty(name)) { + var path = sounds[name]; + + Sound.loaded[name] = new buzz.sound(path); + } + } + + this.initialised = true; + + callback(); + }; + + Sound.play = function(name) { + var ready = function() { + if (Sound.loaded[name]) { + Sound.loaded[name].play(); + } else { + console.log('[sound] Not found:', name); + } + }; + + if (!this.initialised) this.init(ready); + else ready(); + }; + + return Sound; +}); \ No newline at end of file