Skip to content

Commit b79b858

Browse files
author
Igor Khomenko
committed
added QB.chat.onMessageErrorListener(messageId, error)
1 parent 3f3b482 commit b79b858

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

js/modules/qbChat.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function ChatProxy(service, webrtcModule, conn) {
5050
/*
5151
* User's callbacks (listener-functions):
5252
* - onMessageListener
53+
* - onMessageErrorListener(messageId, error)
5354
* - onMessageTypingListener
5455
* - onDeliveredStatusListener
5556
* - onReadStatusListener
@@ -277,16 +278,23 @@ function ChatProxy(service, webrtcModule, conn) {
277278
};
278279

279280
this._onMessageErrorListener = function(stanza) {
280-
console.log(stanza);
281-
var type = stanza.getAttribute('type'),
282-
error = stanza.querySelector('text').textContent;
281+
282+
283+
// <error code="503" type="cancel">
284+
// <service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
285+
// <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" xml:lang="en">Service not available.</text>
286+
// </error>
287+
288+
var messageId = stanza.getAttribute('id');
289+
//
290+
var error = getErrorFromXMLNode(stanza);
283291

284292
// fire 'onMessageErrorListener'
285293
//
286-
if (typeof self.onMessageErrorListener === 'function' && type === 'error') {
294+
if (typeof self.onMessageErrorListener === 'function') {
287295
Utils.safeCallbackCall(self.onMessageErrorListener, messageId, error);
288296
}
289-
297+
290298
// we must return true to keep the handler alive
291299
// returning false would remove it after it finishes
292300
return true;
@@ -950,7 +958,7 @@ MucProxy.prototype = {
950958

951959
/* Chat module: Privacy list
952960
*
953-
* Privacy list
961+
* Privacy list
954962
* http://xmpp.org/extensions/xep-0016.html
955963
*
956964
----------------------------------------------------------------------------- */
@@ -1085,7 +1093,7 @@ PrivacyListProxy.prototype = {
10851093
}).up().c('presence-in', {
10861094
}).up().c('presence-out', {
10871095
}).up().c('iq', {
1088-
}).up().up();
1096+
}).up().up();
10891097
}
10901098

10911099
connection.sendIQ(iq, function(stanzaResult) {
@@ -1414,6 +1422,9 @@ function getError(code, detail) {
14141422
case 408:
14151423
msg = 'Timeout';
14161424
break;
1425+
case 503:
1426+
msg = 'Service not available';
1427+
break;
14171428
default:
14181429
msg = 'Bad request'; // 400
14191430
}

0 commit comments

Comments
 (0)