refactored sound system so that they can be specified in ACP, updated soundfile to work in FF, which fixes #1209

v1.18.x
Julian Lam 11 years ago
parent 175230e337
commit 553cabdcfa

Binary file not shown.

Binary file not shown.

@ -1,8 +1,7 @@
'use strict';
"use strict";
/* globals app, config, define, socket, translator, templates, utils */
define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) {
define(['taskbar', 'string', 'sounds'], function(taskbar, S, sounds) {
var module = {};
@ -53,9 +52,8 @@ define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) {
});
socket.on('event:chats.receive', function(data) {
if (module.modalExists(data.fromuid)) {
var modal = module.getModal(data.fromuid);
if (module.modalExists(data.uid)) {
var modal = module.getModal(data.uid);
module.appendChatMessage(modal, data.message, data.timestamp);
if (modal.is(":visible")) {
@ -71,13 +69,15 @@ define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) {
app.alternatingTitle(data.username + ' has messaged you');
}
} else {
module.createModal(data.username, data.fromuid, function(modal) {
module.createModal(data.username, data.uid, function(modal) {
module.toggleNew(modal.attr('UUID'), true);
app.alternatingTitle(data.username + ' has messaged you');
});
}
sound.play('chat-incoming');
if (parseInt(app.uid, 10) !== parseInt(data.fromUid, 10)) {
sounds.play('chat-incoming');
}
});
};
@ -229,7 +229,8 @@ define(['taskbar', 'string', 'sound'], function(taskbar, S, sound) {
msg = msg +'\n';
socket.emit('modules.chats.send', { touid:chatModal.touid, message:msg});
chatModal.find('#chat-message-input').val('');
sound.play('chat-outgoing');
console.log('outgoing');
sounds.play('chat-outgoing');
}
}

@ -1,4 +1,4 @@
define(['sound'], function(sound) {
define(['sounds'], function(sound) {
var Notifications = {};
Notifications.prepareDOM = function() {

@ -1,43 +0,0 @@
"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;
});

@ -0,0 +1,74 @@
"use strict";
define(['buzz'], function(buzz) {
var Sounds = {};
Sounds.initialised = false;
Sounds.loaded = {};
Sounds.mapping = {};
Sounds.init = function(callback) {
var ready = false,
onComplete = function() {
callback();
};
loadFiles(function() {
if (ready) {
onComplete();
} else {
ready = true;
}
});
loadMapping(function() {
if (ready) {
onComplete();
} else {
ready = true;
}
});
};
var loadFiles = function(callback) {
socket.emit('modules.sounds.getSounds', function(err, sounds) {
if (err) {
return console.log('[sounds] Could not initialise!');
}
for(var name in sounds) {
if (sounds.hasOwnProperty(name)) {
var path = sounds[name];
Sounds.loaded[name] = new buzz.sound(path);
}
}
this.initialised = true;
callback();
});
};
var loadMapping = function(callback) {
socket.emit('modules.sounds.getMapping', function(err, mapping) {
Sounds.mapping = mapping;
callback();
});
};
Sounds.play = function(name) {
var ready = function() {
if (Sounds.mapping[name] && Sounds.loaded[Sounds.mapping[name]]) {
Sounds.loaded[Sounds.mapping[name]].play();
} else {
console.log('[sounds] Not found:', name);
}
};
if (!this.initialised) this.init(ready);
else ready();
};
return Sounds;
});

@ -325,6 +325,47 @@ var fs = require('fs'),
}
};
/* Sounds */
Meta.sounds = {};
// todo: Possibly move these into a bundled module?
Meta.sounds.getLocal = function(callback) {
fs.readdir(path.join(__dirname, '../public/sounds'), function(err, files) {
var localList = {};
if (err) {
winston.error('Could not get local sound files:' + err.message);
console.log(err.stack);
return callback(null, []);
}
// Return proper paths
files.forEach(function(filename) {
localList[filename] = nconf.get('url') + '/sounds/' + filename;
});
callback(null, localList);
});
};
Meta.sounds.getMapping = function(callback) {
db.getObject('sounds', function(err, sounds) {
if (err || !sounds) {
// Send default sounds
var defaults = {
notification: 'notification.wav',
'chat-incoming': 'waterdrop-high.wav',
'chat-outgoing': 'waterdrop-low.wav'
};
return callback(null, defaults);
}
callback.apply(null, arguments);
});
};
/* Assorted */
Meta.css = {
cache: undefined
};

@ -198,7 +198,8 @@ SocketModules.chats.send = function(socket, data) {
server.getUserSockets(touid).forEach(function(s) {
s.emit('event:chats.receive', {
fromuid: socket.uid,
uid: socket.uid,
fromUid: socket.uid,
username: username,
message: parsed,
timestamp: Date.now()
@ -207,7 +208,8 @@ SocketModules.chats.send = function(socket, data) {
server.getUserSockets(socket.uid).forEach(function(s) {
s.emit('event:chats.receive', {
fromuid: touid,
uid: touid,
fromUid: socket.uid,
username: toUsername,
message: parsed,
timestamp: Date.now()
@ -234,4 +236,17 @@ SocketModules.notifications.mark_all_read = function(socket, data, callback) {
notifications.mark_all_read(socket.uid, callback);
};
/* Sounds */
SocketModules.sounds = {};
SocketModules.sounds.getSounds = function(socket, data, callback) {
// Read sounds from local directory
meta.sounds.getLocal(callback);
};
SocketModules.sounds.getMapping = function(socket, data, callback) {
meta.sounds.getMapping(callback);
};
module.exports = SocketModules;
Loading…
Cancel
Save