Notification sound now also plays when nickname is mentioned in chat room.

updates #62
This commit is contained in:
JC Brand 2014-09-03 18:47:24 +02:00
parent 01ba7361d6
commit 3aaa8df41a
5 changed files with 24 additions and 14 deletions

View File

@ -32,6 +32,7 @@
console = { log: function () {}, error: function () {} };
}
// TODO: these non-backbone methods should all be moved to utils.
$.fn.addHyperlinks = function() {
if (this.length > 0) {
this.each(function(i, obj) {
@ -71,6 +72,19 @@
};
};
var playNotification = function () {
var audio;
if (converse.play_sounds && typeof Audio !== "undefined"){
audio = new Audio("sounds/msg_received.ogg");
if (audio.canPlayType('/audio/ogg')) {
audio.play();
} else {
audio = new Audio("/sounds/msg_received.mp3");
audio.play();
}
}
};
$.fn.addEmoticons = function() {
if (converse.visible_toolbar_buttons.emoticons) {
if (this.length > 0) {
@ -2438,6 +2452,9 @@
}
if (!body) { return true; }
var display_sender = sender === this.model.get('nick') && 'me' || 'room';
if (!delayed && display_sender === 'room' && (new RegExp("\\b"+this.model.get('nick')+"\\b")).test(body)) {
playNotification();
}
this.showMessage({
'message': body,
'sender': display_sender,
@ -2517,19 +2534,6 @@
});
},
playNotification: function () {
var audio;
if (converse.play_sounds && typeof Audio !== "undefined"){
audio = new Audio("sounds/msg_received.ogg");
if (audio.canPlayType('/audio/ogg')) {
audio.play();
} else {
audio = new Audio("/sounds/msg_received.mp3");
audio.play();
}
}
},
isOnlyChatStateNotification: function ($msg) {
// See XEP-0085 Chat State Notification
return (
@ -2627,7 +2631,7 @@
});
}
if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) {
this.playNotification();
playNotification();
}
chatbox.receiveMessage($message);
converse.roster.addResource(buddy_jid, resource);

View File

@ -1199,6 +1199,7 @@ select#select-xmpp-status {
border-top-left-radius: 0;
border-top-right-radius: 0;
width: 200px;
height: 84px;
}
#conversejs .chatroom form.sendXMPPMessage {
-webkit-border-bottom-right-radius: 0;

View File

@ -7,6 +7,7 @@ Changelog
* Converse.js now responds to XEP-0030: Service Discovery requests. [jcbrand]
* Bugfix. Roster groups all appear offline after page reload (with prebind).
See http://librelist.com/browser//conversejs/2014/8/26/problem-with-contact-list-everyone-is-offline/ [heban and jcbrand]
* #62 Sound notifications will now also play when you are mentioned in a chat room. [jcbrand]
* #212 Bugfix. Groups weren't being show again after the live filter was cleared. [jcbrand]
* #215 (and also #75) XEP-0249: Direct MUC Invitations. [jcbrand]
* #216 Contacts tab empty when using xhr_user_search. [hcderaad and jcbrand]

View File

@ -975,6 +975,9 @@ play_sounds
Default: ``false``
Plays a notification sound when you receive a personal message or when your
nickname is mentioned in a chat room.
Inside the ``./sounds`` directory of the Converse.js repo, you'll see MP3 and Ogg
formatted sound files. We need both, because neither format is supported by all browsers.

View File

@ -1356,6 +1356,7 @@ select#select-xmpp-status {
border-top-left-radius: 0;
border-top-right-radius: 0;
width: 200px;
height: 84px;
}
#conversejs .chatroom form.sendXMPPMessage {