Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a099440
Update config.js
Aug 5, 2015
92b4189
Merge branch 'gh-pages' of github.com:QuickBlox/quickblox-javascript-…
Aug 10, 2015
4e1791e
Merge branch 'develop.webrtc' into gh-pages
Aug 11, 2015
5ad880a
Merge branch 'develop' into gh-pages
Aug 11, 2015
884e531
Merge branch 'develop' into gh-pages
Aug 20, 2015
c608335
Merge branch 'develop' into gh-pages
Aug 20, 2015
8499ba0
Merge branch 'develop' into gh-pages
Aug 21, 2015
0c72395
Update config.js
Aug 25, 2015
94f7587
Merge branch 'develop' into gh-pages
Sep 2, 2015
d2c0dd6
Merge branch 'gh-pages' of github.com:QuickBlox/quickblox-javascript-…
Sep 2, 2015
b773b87
Merge branch 'develop' into gh-pages
Sep 18, 2015
5b1ad63
Merge branch 'develop' into gh-pages
Sep 22, 2015
d16040b
Merge branch 'develop' into gh-pages
Oct 2, 2015
f27e865
Merge branch 'develop' into gh-pages
Oct 16, 2015
75f7296
cleanup
Oct 16, 2015
22b27a3
Merge branch 'develop' into gh-pages
Oct 16, 2015
e54aeb9
Wrapped in try...catch all chat listeners callbacks
Vladlukhanin Nov 3, 2015
761e20b
Merge branch 'develop.try-catch' of https://github.com/QuickBlox/quic…
Vladlukhanin Nov 3, 2015
919e23a
added function name where the error happened to console.error
Vladlukhanin Nov 4, 2015
e916b24
added function name where the error happened to console.error
Vladlukhanin Nov 4, 2015
f3d07cd
deleted throw '...'; from some listners in samples/chat/js/messages.js
Vladlukhanin Nov 4, 2015
a2e45d9
removed Array.prototype.apply(arguments) in Utils.safeCallbackCall(),…
Vladlukhanin Nov 4, 2015
670849b
renamed argumentsArr to argumentsCopy
Vladlukhanin Nov 4, 2015
ddac1a2
function isMessageForCurrentDialog() in chat now with one return
Vladlukhanin Nov 5, 2015
c3ea120
merged with dev
Nov 9, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions js/modules/qbChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function ChatProxy(service, webrtcModule, conn) {
//
if(composing || paused){
if (typeof self.onMessageTypingListener === 'function' && (type === 'chat' || type === 'groupchat' || !delay)){
self.onMessageTypingListener(composing != null, userId, dialogId);
Utils.safeCallbackCall(self.onMessageTypingListener, composing != null, userId, dialogId);
}
return true;
}
Expand All @@ -109,11 +109,11 @@ function ChatProxy(service, webrtcModule, conn) {
if (marker) {
if (delivered) {
if (typeof self.onDeliveredStatusListener === 'function' && type === 'chat') {
self.onDeliveredStatusListener(delivered.getAttribute('id'), dialogId, userId);
Utils.safeCallbackCall(self.onDeliveredStatusListener, delivered.getAttribute('id'), dialogId, userId);
}
} else {
if (typeof self.onReadStatusListener === 'function' && type === 'chat') {
self.onReadStatusListener(read.getAttribute('id'), dialogId, userId);
Utils.safeCallbackCall(self.onReadStatusListener, read.getAttribute('id'), dialogId, userId);
}
}
return true;
Expand Down Expand Up @@ -144,7 +144,7 @@ function ChatProxy(service, webrtcModule, conn) {
message.markable = 1;
}
if (typeof self.onMessageListener === 'function' && (type === 'chat' || type === 'groupchat')){
self.onMessageListener(userId, message);
Utils.safeCallbackCall(self.onMessageListener, userId, message);
}

// we must return true to keep the handler alive
Expand All @@ -159,7 +159,7 @@ function ChatProxy(service, webrtcModule, conn) {

if (!type) {
if (typeof self.onContactListListener === 'function' && roster[userId] && roster[userId].subscription !== 'none')
self.onContactListListener(userId);
Utils.safeCallbackCall(self.onContactListListener, userId);
} else {

// subscriptions callbacks
Expand All @@ -176,7 +176,7 @@ function ChatProxy(service, webrtcModule, conn) {
});
} else {
if (typeof self.onSubscribeListener === 'function')
self.onSubscribeListener(userId);
Utils.safeCallbackCall(self.onSubscribeListener, userId);
}
break;
case 'subscribed':
Expand All @@ -191,7 +191,7 @@ function ChatProxy(service, webrtcModule, conn) {
ask: null
};
if (typeof self.onConfirmSubscribeListener === 'function')
self.onConfirmSubscribeListener(userId);
Utils.safeCallbackCall(self.onConfirmSubscribeListener, userId);
}
break;
case 'unsubscribed':
Expand All @@ -200,7 +200,7 @@ function ChatProxy(service, webrtcModule, conn) {
ask: null
};
if (typeof self.onRejectSubscribeListener === 'function')
self.onRejectSubscribeListener(userId);
Utils.safeCallbackCall(self.onRejectSubscribeListener, userId);
break;
case 'unsubscribe':
roster[userId] = {
Expand All @@ -212,7 +212,7 @@ function ChatProxy(service, webrtcModule, conn) {
break;
case 'unavailable':
if (typeof self.onContactListListener === 'function' && roster[userId] && roster[userId].subscription !== 'none')
self.onContactListListener(userId, type);
Utils.safeCallbackCall(self.onContactListListener, userId, type);
break;
}

Expand Down Expand Up @@ -251,7 +251,7 @@ function ChatProxy(service, webrtcModule, conn) {
extension: extraParamsParsed.extension
};

self.onSystemMessageListener(message);
Utils.safeCallbackCall(self.onSystemMessageListener, message);
}

return true;
Expand Down Expand Up @@ -341,7 +341,7 @@ ChatProxy.prototype = {

// fire 'onReconnectListener'
if (typeof self.onReconnectListener === 'function'){
self.onReconnectListener();
Utils.safeCallbackCall(self.onReconnectListener);
}
}
});
Expand All @@ -358,7 +358,7 @@ ChatProxy.prototype = {

// fire 'onDisconnectedListener' only once
if (!self._isDisconnected && typeof self.onDisconnectedListener === 'function'){
self.onDisconnectedListener();
Utils.safeCallbackCall(self.onDisconnectedListener);
}

self._isDisconnected = true;
Expand Down
21 changes: 21 additions & 0 deletions js/qbUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ var ObjectId = {
};

var Utils = {
safeCallbackCall: function() {
if(!isBrowser) throw unsupported;

var listenerString = arguments[0].toString(),
listenerName = listenerString.split('(')[0].split(' ')[1],
argumentsCopy = [],
listenerCall;

for (var i = 0; i < arguments.length; i++) {
argumentsCopy.push(arguments[i]);
}

listenerCall = argumentsCopy.shift();

try {
listenerCall.apply(null, argumentsCopy);
} catch (err) {
console.error('Error in the ' + listenerName + ': ' + err);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мы разве оставляем console?
У нас вроде QBLog есть или что то такое. Которое следит за параметром debug конфига и пишит.

}
},

randomNonce: function() {
return Math.floor(Math.random() * 10000);
},
Expand Down
16 changes: 8 additions & 8 deletions quickblox.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions samples/chat/js/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ function showUserIsTypingView(isTyping, userId, dialogId) {

// filter for current dialog
function isMessageForCurrentDialog(userId, dialogId) {
var result = false;
if (dialogId == currentDialog._id || (dialogId === null && currentDialog.type == 3 && opponentId == userId)) {
return true;
result = true;
}
return false;
return result;
}
26 changes: 24 additions & 2 deletions spec/QB-HelpersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,30 @@ describe('Helpers', function() {
});

it("can generate user's jid", function() {
var userJid = QB.chat.helpers.getUserJid(5, 92);
expect(userJid).toEqual("5-92@chat.quickblox.com");
var userJid = QB.chat.helpers.getUserJid(5, 29650);
expect(userJid).toEqual("5-29650@chat.quickblox.com");
});

it("can return jid from jid or from user's id", function() {
var jid = QB.chat.helpers.jidOrUserId(100500);
expect(jid).toEqual("100500-29650@chat.quickblox.com");
});

it("can get type chat from jid or from user's id", function() {
var id = QB.chat.helpers.typeChat(100500);
expect(id).toEqual("chat");
var jid = QB.chat.helpers.typeChat("100500-29650@chat.quickblox.com");
expect(jid).toEqual("chat");
var room = QB.chat.helpers.typeChat("29650_562f271ba28f9aa53e004788@muc.chat.quickblox.com");
expect(room).toEqual("groupchat");
});

it("can get recipient id from privat chat", function() {
var occupantsIds = [100500, 707070];
var userId = 100500;
var recipientId = QB.chat.helpers.getRecipientId(occupantsIds, userId);
expect(recipientId).toEqual(707070);
});

});