Add support for sound notifications. updates #62

(on incoming messages)
This commit is contained in:
JC Brand 2014-08-20 21:00:28 +02:00
parent 278c2c428d
commit 882bbcb02e
6 changed files with 50 additions and 13 deletions

View File

@ -2,7 +2,7 @@
BOWER ?= node_modules/.bin/bower BOWER ?= node_modules/.bin/bower
BUILDDIR = ./docs BUILDDIR = ./docs
PAPER = PAPER =
PHANTOMJS ?= node_modules/.bin/phantomjs PHANTOMJS ?= phantomjs
SPHINXBUILD = sphinx-build SPHINXBUILD = sphinx-build
SPHINXOPTS = SPHINXOPTS =

View File

@ -132,6 +132,12 @@
'dnd': 2, 'dnd': 2,
'online': 1 'online': 1
}; };
var INACTIVE = 'inactive';
var ACTIVE = 'active';
var COMPOSING = 'composing';
var PAUSED = 'paused';
var HAS_CSPRNG = ((typeof crypto !== 'undefined') && var HAS_CSPRNG = ((typeof crypto !== 'undefined') &&
((typeof crypto.randomBytes === 'function') || ((typeof crypto.randomBytes === 'function') ||
(typeof crypto.getRandomValues === 'function') (typeof crypto.getRandomValues === 'function')
@ -165,6 +171,7 @@
this.i18n = locales.en; this.i18n = locales.en;
this.message_carbons = false; this.message_carbons = false;
this.no_trimming = false; // Set to true for phantomjs tests (where browser apparently has no width) this.no_trimming = false; // Set to true for phantomjs tests (where browser apparently has no width)
this.play_sounds = false;
this.prebind = false; this.prebind = false;
this.roster_groups = false; this.roster_groups = false;
this.show_controlbox_by_default = false; this.show_controlbox_by_default = false;
@ -206,6 +213,7 @@
'i18n', 'i18n',
'jid', 'jid',
'no_trimming', 'no_trimming',
'play_sounds',
'prebind', 'prebind',
'rid', 'rid',
'roster_groups', 'roster_groups',
@ -814,19 +822,21 @@
var body = $message.children('body').text(), var body = $message.children('body').text(),
from = Strophe.getBareJidFromJid($message.attr('from')), from = Strophe.getBareJidFromJid($message.attr('from')),
composing = $message.find('composing'), composing = $message.find('composing'),
paused = $message.find('paused'),
delayed = $message.find('delay').length > 0, delayed = $message.find('delay').length > 0,
fullname = this.get('fullname'), fullname = this.get('fullname'),
stamp, time, sender; stamp, time, sender;
fullname = (_.isEmpty(fullname)? from: fullname).split(' ')[0]; fullname = (_.isEmpty(fullname)? from: fullname).split(' ')[0];
if (!body) { if (!body) {
if (composing.length) { if (composing.length || paused.length) {
this.messages.add({ this.messages.add({
fullname: fullname, fullname: fullname,
sender: 'them', sender: 'them',
delayed: delayed, delayed: delayed,
time: moment().format(), time: moment().format(),
composing: composing.length composing: composing.length,
paused: paused.length
}); });
} }
} else { } else {
@ -1031,8 +1041,11 @@
})); }));
} }
} }
if (message.get('composing')) { if (message.get(COMPOSING)) {
this.showStatusNotification(message.get('fullname')+' '+'is typing'); this.showStatusNotification(message.get('fullname')+' '+__('is typing'));
return;
} else if (message.get(PAUSED)) {
this.showStatusNotification(message.get('fullname')+' '+__('has stopped typing'));
return; return;
} else { } else {
this.showMessage(_.clone(message.attributes)); this.showMessage(_.clone(message.attributes));
@ -2442,6 +2455,31 @@
}); });
}, },
playNotification: function () {
var ping;
if (converse.play_sounds && typeof Audio !== "undefined"){
ping = new Audio("sounds/ping.ogg");
if (ping.canPlayType('audio/ogg')) {
ping.play();
} else {
ping = new Audio("sounds/ping.mp3");
ping.play();
}
}
},
isOnlyChatStateNotification: function ($msg) {
// See XEP-0085 Chat State Notification
return (
$msg.find('body').length === 0 && (
$msg.find(ACTIVE).length !== 0 ||
$msg.find(COMPOSING).length !== 0 ||
$msg.find(INACTIVE).length !== 0 ||
$msg.find(PAUSED).length !== 0
)
);
},
onMessage: function (message) { onMessage: function (message) {
var buddy_jid, $message = $(message), var buddy_jid, $message = $(message),
message_from = $message.attr('from'); message_from = $message.attr('from');
@ -2490,6 +2528,9 @@
'url': roster_item.get('url') 'url': roster_item.get('url')
}); });
} }
if (!this.isOnlyChatStateNotification($message) && from !== converse.bare_jid) {
this.playNotification();
}
chatbox.receiveMessage($message); chatbox.receiveMessage($message);
converse.roster.addResource(buddy_jid, resource); converse.roster.addResource(buddy_jid, resource);
converse.emit('message', message); converse.emit('message', message);

View File

@ -4,9 +4,10 @@ Changelog
0.8.1 (Unreleased) 0.8.1 (Unreleased)
------------------ ------------------
* Bugfix: Contacts weren't properly sorted according to chat status. [jcbrand]
* #63 Support for sound notification on message received. [jcbrand]
* #212 Provide a live filter of the roster contacts. [jcbrand] * #212 Provide a live filter of the roster contacts. [jcbrand]
0.8.0 (2014-08-04) 0.8.0 (2014-08-04)
------------------ ------------------

View File

@ -12,13 +12,7 @@
<link type="text/css" rel="stylesheet" media="screen" href="components/fontawesome/css/font-awesome.min.css" /> <link type="text/css" rel="stylesheet" media="screen" href="components/fontawesome/css/font-awesome.min.css" />
<link type="text/css" rel="stylesheet" media="screen" href="css/theme.css" /> <link type="text/css" rel="stylesheet" media="screen" href="css/theme.css" />
<link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" /> <link type="text/css" rel="stylesheet" media="screen" href="css/converse.css" />
<!-- Only for development: <script data-main="main" src="components/requirejs/require.js"></script> --> <script data-main="main" src="components/requirejs/require.js"></script>
<![if gte IE 9]>
<script src="builds/converse.website.min.js"></script>
<![endif]>
<!--[if lt IE 9]>
<script src="builds/converse.website-no-otr.min.js"></script>
<![endif]-->
</head> </head>
<body id="page-top" data-spy="scroll" data-target=".navbar-custom"> <body id="page-top" data-spy="scroll" data-target=".navbar-custom">
@ -239,6 +233,7 @@
hide_muc_server: false, hide_muc_server: false,
i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported i18n: locales['en'], // Refer to ./locale/locales.js to see which locales are supported
prebind: false, prebind: false,
play_sounds: true,
show_controlbox_by_default: true, show_controlbox_by_default: true,
xhr_user_search: false, xhr_user_search: false,
roster_groups: true roster_groups: true

BIN
sounds/ping.mp3 Normal file

Binary file not shown.

BIN
sounds/ping.ogg Normal file

Binary file not shown.