Skip to content

Commit c679dca

Browse files
author
Igor Khomenko
committed
merged
2 parents 0681caf + 32e8777 commit c679dca

File tree

20 files changed

+500
-62
lines changed

20 files changed

+500
-62
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "1.16.0",
4+
"version": "1.16.1",
55
"homepage": "http://quickblox.com/developers/Javascript",
66
"main": "quickblox.js",
77
"license": "MIT",

js/modules/qbChat.js

Lines changed: 271 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (isBrowser) {
1717
// add extra namespaces for Strophe
1818
Strophe.addNamespace('CARBONS', 'urn:xmpp:carbons:2');
1919
Strophe.addNamespace('CHAT_MARKERS', 'urn:xmpp:chat-markers:0');
20-
Strophe.addNamespace('BLOCKING_COMMAND', 'urn:xmpp:blocking');
20+
Strophe.addNamespace('PRIVACY_LIST', 'jabber:iq:privacy');
2121
Strophe.addNamespace('CHAT_STATES', 'http://jabber.org/protocol/chatstates');
2222
}
2323

@@ -38,6 +38,7 @@ function ChatProxy(service, webrtcModule, conn) {
3838
if(isBrowser) {
3939
this.roster = new RosterProxy(service);
4040
this.muc = new MucProxy(service);
41+
this.privacylist = new PrivacyListProxy(service);
4142

4243
this._isLogout = false;
4344
this._isDisconnected = false;
@@ -121,9 +122,9 @@ function ChatProxy(service, webrtcModule, conn) {
121122
return true;
122123
}
123124

124-
// autosend 'received' status
125+
// autosend 'received' status (ignore messages from self)
125126
//
126-
if (markable) {
127+
if (markable && userId != self.helpers.getIdFromNode(connection.jid)) {
127128
var params = {
128129
messageId: messageId,
129130
userId: userId,
@@ -226,6 +227,22 @@ function ChatProxy(service, webrtcModule, conn) {
226227
};
227228

228229
this._onIQ = function(stanza) {
230+
// var type = stanza.getAttribute('type'),
231+
// typeId = stanza.getAttribute('id').split(':')[1];
232+
233+
// if (typeof self.onListEditListener === 'function' && typeId === 'push') {
234+
// var listName = (stanza.getElementsByTagName('list')[0]).getAttribute('name');
235+
236+
// var iq = $iq({
237+
// from: connection.jid,
238+
// type: 'result',
239+
// id: connection.getUniqueId('push')
240+
// });
241+
242+
// connection.sendIQ(iq);
243+
244+
// Utils.safeCallbackCall(self.onListEditListener(listName));
245+
// }
229246

230247
// we must return true to keep the handler alive
231248
// returning false would remove it after it finishes
@@ -914,6 +931,257 @@ MucProxy.prototype = {
914931
};
915932

916933

934+
/* Chat module: Privacy list
935+
*
936+
* Privacy list
937+
* http://xmpp.org/extensions/xep-0016.html
938+
*
939+
----------------------------------------------------------------------------- */
940+
function PrivacyListProxy(service) {
941+
this.service = service;
942+
this.helpers = new Helpers();
943+
}
944+
945+
PrivacyListProxy.prototype = {
946+
947+
getNames: function(callback) {
948+
var iq = $iq({
949+
from: connection.jid,
950+
type: 'get',
951+
id: connection.getUniqueId('getNames')
952+
}).c('query', {
953+
xmlns: Strophe.NS.PRIVACY_LIST
954+
});
955+
956+
connection.sendIQ(iq, function(stanzaResult) {
957+
var allNames = [], namesList = {},
958+
defaultList = stanzaResult.getElementsByTagName('default'),
959+
activeList = stanzaResult.getElementsByTagName('active'),
960+
allLists = stanzaResult.getElementsByTagName('list'),
961+
defaultName = defaultList[0].getAttribute('name'),
962+
activeName = activeList[0].getAttribute('name');
963+
for (var i = 0, len = allLists.length; i < len; i++) {
964+
allNames.push(allLists[i].getAttribute('name'));
965+
}
966+
namesList = {
967+
'default': defaultName,
968+
'active': activeName,
969+
'names': allNames
970+
};
971+
callback(null, namesList);
972+
}, function(stanzaError){
973+
if(stanzaError){
974+
var errorObject = getErrorFromXMLNode(stanzaError);
975+
callback(errorObject, null);
976+
}else{
977+
callback(getError(408), null);
978+
}
979+
});
980+
},
981+
982+
getList: function(name, callback) {
983+
var iq, self = this,
984+
items, userJid, userId,
985+
usersList = [], list = {};
986+
987+
iq = $iq({
988+
from: connection.jid,
989+
type: 'get',
990+
id: connection.getUniqueId('getlist')
991+
}).c('query', {
992+
xmlns: Strophe.NS.PRIVACY_LIST
993+
}).c('list', {
994+
name: name
995+
});
996+
997+
connection.sendIQ(iq, function(stanzaResult) {
998+
items = stanzaResult.getElementsByTagName('item');
999+
for (var i = 0, len = items.length; i < len; i=i+2) {
1000+
userJid = items[i].getAttribute('value'),
1001+
userId = self.helpers.getIdFromNode(userJid);
1002+
usersList.push({
1003+
user_id: userId,
1004+
action: items[i].getAttribute('action')
1005+
});
1006+
}
1007+
list = {
1008+
name: name,
1009+
items: usersList
1010+
};
1011+
callback(null, list);
1012+
}, function(stanzaError){
1013+
if(stanzaError){
1014+
var errorObject = getErrorFromXMLNode(stanzaError);
1015+
callback(errorObject, null);
1016+
}else{
1017+
callback(getError(408), null);
1018+
}
1019+
});
1020+
},
1021+
1022+
create: function(list, callback) {
1023+
var iq, self = this,
1024+
userId, userJid,
1025+
userAction, userMuc,
1026+
listObj = {},
1027+
listKeys = [];
1028+
1029+
iq = $iq({
1030+
from: connection.jid,
1031+
type: 'set',
1032+
id: connection.getUniqueId('edit')
1033+
}).c('query', {
1034+
xmlns: Strophe.NS.PRIVACY_LIST
1035+
}).c('list', {
1036+
name: list.name
1037+
});
1038+
1039+
$(list.items).each(function(e, i){
1040+
listObj[i.user_id] = i.action;
1041+
});
1042+
1043+
listKeys = Object.keys(listObj);
1044+
1045+
for (var index = 0, i = 0, len = listKeys.length; index < len; index++, i=i+2) {
1046+
userId = listKeys[index];
1047+
userAction = listObj[userId];
1048+
userJid = self.helpers.jidOrUserId(parseInt(userId, 10));
1049+
userMuc = self.helpers.getUserNickWithMucDomain(userId);
1050+
1051+
iq.c('item', {
1052+
type: 'jid',
1053+
value: userJid,
1054+
action: userAction,
1055+
order: i+1
1056+
}).c('message', {
1057+
}).up().c('presence-in', {
1058+
}).up().c('presence-out', {
1059+
}).up().c('iq', {
1060+
}).up().up();
1061+
1062+
iq.c('item', {
1063+
type: 'jid',
1064+
value: userMuc,
1065+
action: userAction,
1066+
order: i+2
1067+
}).c('message', {
1068+
}).up().c('presence-in', {
1069+
}).up().c('presence-out', {
1070+
}).up().c('iq', {
1071+
}).up().up();
1072+
}
1073+
1074+
connection.sendIQ(iq, function(stanzaResult) {
1075+
callback(null);
1076+
}, function(stanzaError){
1077+
if(stanzaError){
1078+
var errorObject = getErrorFromXMLNode(stanzaError);
1079+
callback(errorObject);
1080+
}else{
1081+
callback(getError(408));
1082+
}
1083+
});
1084+
},
1085+
1086+
update: function(list, callback) {
1087+
var self = this, copyList = list;
1088+
1089+
self.getList(copyList.name, function(error, response) {
1090+
if (error) {
1091+
callback(error, null);
1092+
}else{
1093+
var oldArray = response.items,
1094+
newArray = copyList.items,
1095+
updatedArray = [],
1096+
createList = {};
1097+
1098+
updatedArray = $.merge(oldArray, newArray);
1099+
copyList.items = updatedArray;
1100+
createList = copyList;
1101+
1102+
self.create(createList, function(error, response) {
1103+
if (error) {
1104+
callback(error, null);
1105+
}else{
1106+
callback(null, createList);
1107+
}
1108+
});
1109+
}
1110+
});
1111+
},
1112+
1113+
delete: function(name, callback) {
1114+
var iq = $iq({
1115+
from: connection.jid,
1116+
type: 'set',
1117+
id: connection.getUniqueId('remove')
1118+
}).c('query', {
1119+
xmlns: Strophe.NS.PRIVACY_LIST
1120+
}).c('list', {
1121+
name: name ? name : ''
1122+
});
1123+
1124+
connection.sendIQ(iq, function(stanzaResult) {
1125+
callback(null);
1126+
}, function(stanzaError){
1127+
if(stanzaError){
1128+
var errorObject = getErrorFromXMLNode(stanzaError);
1129+
callback(errorObject);
1130+
}else{
1131+
callback(getError(408));
1132+
}
1133+
});
1134+
},
1135+
1136+
setAsDefault: function(name, callback) {
1137+
var iq = $iq({
1138+
from: connection.jid,
1139+
type: 'set',
1140+
id: connection.getUniqueId('default')
1141+
}).c('query', {
1142+
xmlns: Strophe.NS.PRIVACY_LIST
1143+
}).c('default', {
1144+
name: name ? name : ''
1145+
});
1146+
1147+
connection.sendIQ(iq, function(stanzaResult) {
1148+
callback(null);
1149+
}, function(stanzaError){
1150+
if(stanzaError){
1151+
var errorObject = getErrorFromXMLNode(stanzaError);
1152+
callback(errorObject);
1153+
}else{
1154+
callback(getError(408));
1155+
}
1156+
});
1157+
},
1158+
1159+
setAsActive: function(name, callback) {
1160+
var iq = $iq({
1161+
from: connection.jid,
1162+
type: 'set',
1163+
id: connection.getUniqueId('active')
1164+
}).c('query', {
1165+
xmlns: Strophe.NS.PRIVACY_LIST
1166+
}).c('active', {
1167+
name: name ? name : ''
1168+
});
1169+
1170+
connection.sendIQ(iq, function(stanzaResult) {
1171+
callback(null);
1172+
}, function(stanzaError){
1173+
if(stanzaError){
1174+
var errorObject = getErrorFromXMLNode(stanzaError);
1175+
callback(errorObject);
1176+
}else{
1177+
callback(getError(408));
1178+
}
1179+
});
1180+
}
1181+
1182+
};
1183+
1184+
9171185
/* Chat module: History
9181186
----------------------------------------------------------------------------- */
9191187

js/modules/qbWebRTC.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ WebRTCProxy.prototype.attachMediaStream = function(id, stream, options) {
297297
elem.style.transform = 'scaleX(-1)';
298298
}
299299
elem.play();
300+
} else {
301+
throw new Error('Unable to attach media stream, element ' + id + ' is undefined');
300302
}
301303
};
302304

js/qbConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
var config = {
9-
version: '1.16.0',
9+
version: '1.16.1',
1010
creds: {
1111
appId: '',
1212
authKey: '',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "1.16.0",
4+
"version": "1.16.1",
55
"homepage": "http://quickblox.com/developers/Javascript",
66
"main": "js/qbMain.js",
77
"license": [

quickblox.min.js

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/chat/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ <h5 class="col-md-12 col-sm-12 col-xs-12" id="all_occupants"></h5>
147147
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.1/jquery.timeago.min.js" type="text/javascript"></script>
148148
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js" type="text/javascript"></script>
149149

150-
<script src="../../quickblox.js"></script>
150+
<script src="../../quickblox.min.js"></script>
151151
<script src="js/config.js"></script>
152152
<script src="js/connection.js"></script>
153153
<script src="js/messages.js"></script>

samples/chat/js/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ var QBUser1 = {
2727
pass: 'chatusr22'
2828
};
2929

30-
QB.init(QBApp.appId, QBApp.authKey, QBApp.authSecret, config);
30+
QB.init(QBApp.appId, QBApp.authKey, QBApp.authSecret, config);

samples/content/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
3+
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
66
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -19,7 +19,7 @@
1919
style="position:absolute;top:20px;right:7%;font-size:0.85em;color:grey;">View source on GitHub</a>
2020
</div>
2121
<h1 class="title">
22-
QuickBlox JavaScript content sample
22+
QuickBlox JavaScript content sample
2323
</h1>
2424
<hr>
2525
</div>
@@ -44,9 +44,9 @@ <h1 class="title">
4444

4545
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
4646
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
47-
<script src="../../quickblox.js"></script>
47+
<script src="../../quickblox.min.js"></script>
4848
<script src="js/config.js"></script>
49-
<script src="js/main.js"></script>
49+
<script src="js/main.js"></script>
5050
</body>
5151

52-
</html>
52+
</html>

0 commit comments

Comments
 (0)