You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /* jshint -W117 */
  2. /* a simple MUC connection plugin
  3. * can only handle a single MUC room
  4. */
  5. var bridgeIsDown = false;
  6. var Moderator = require("./moderator");
  7. var JingleSession = require("./JingleSession");
  8. module.exports = function(XMPP, eventEmitter) {
  9. Strophe.addConnectionPlugin('emuc', {
  10. connection: null,
  11. roomjid: null,
  12. myroomjid: null,
  13. members: {},
  14. list_members: [], // so we can elect a new focus
  15. presMap: {},
  16. preziMap: {},
  17. joined: false,
  18. isOwner: false,
  19. role: null,
  20. focusMucJid: null,
  21. init: function (conn) {
  22. this.connection = conn;
  23. },
  24. initPresenceMap: function (myroomjid) {
  25. this.presMap['to'] = myroomjid;
  26. this.presMap['xns'] = 'http://jabber.org/protocol/muc';
  27. },
  28. doJoin: function (jid, password) {
  29. this.myroomjid = jid;
  30. console.info("Joined MUC as " + this.myroomjid);
  31. this.initPresenceMap(this.myroomjid);
  32. if (!this.roomjid) {
  33. this.roomjid = Strophe.getBareJidFromJid(jid);
  34. // add handlers (just once)
  35. this.connection.addHandler(this.onPresence.bind(this), null, 'presence', null, null, this.roomjid, {matchBare: true});
  36. this.connection.addHandler(this.onPresenceUnavailable.bind(this), null, 'presence', 'unavailable', null, this.roomjid, {matchBare: true});
  37. this.connection.addHandler(this.onPresenceError.bind(this), null, 'presence', 'error', null, this.roomjid, {matchBare: true});
  38. this.connection.addHandler(this.onMessage.bind(this), null, 'message', null, null, this.roomjid, {matchBare: true});
  39. }
  40. if (password !== undefined) {
  41. this.presMap['password'] = password;
  42. }
  43. this.sendPresence();
  44. },
  45. doLeave: function () {
  46. console.log("do leave", this.myroomjid);
  47. var pres = $pres({to: this.myroomjid, type: 'unavailable' });
  48. this.presMap.length = 0;
  49. this.connection.send(pres);
  50. },
  51. createNonAnonymousRoom: function () {
  52. // http://xmpp.org/extensions/xep-0045.html#createroom-reserved
  53. var getForm = $iq({type: 'get', to: this.roomjid})
  54. .c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'})
  55. .c('x', {xmlns: 'jabber:x:data', type: 'submit'});
  56. this.connection.sendIQ(getForm, function (form) {
  57. if (!$(form).find(
  58. '>query>x[xmlns="jabber:x:data"]' +
  59. '>field[var="muc#roomconfig_whois"]').length) {
  60. console.error('non-anonymous rooms not supported');
  61. return;
  62. }
  63. var formSubmit = $iq({to: this.roomjid, type: 'set'})
  64. .c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'});
  65. formSubmit.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
  66. formSubmit.c('field', {'var': 'FORM_TYPE'})
  67. .c('value')
  68. .t('http://jabber.org/protocol/muc#roomconfig').up().up();
  69. formSubmit.c('field', {'var': 'muc#roomconfig_whois'})
  70. .c('value').t('anyone').up().up();
  71. this.connection.sendIQ(formSubmit);
  72. }, function (error) {
  73. console.error("Error getting room configuration form");
  74. });
  75. },
  76. onPresence: function (pres) {
  77. var from = pres.getAttribute('from');
  78. // What is this for? A workaround for something?
  79. if (pres.getAttribute('type')) {
  80. return true;
  81. }
  82. // Parse etherpad tag.
  83. var etherpad = $(pres).find('>etherpad');
  84. if (etherpad.length) {
  85. if (config.etherpad_base && !Moderator.isModerator()) {
  86. UI.initEtherpad(etherpad.text());
  87. }
  88. }
  89. // Parse prezi tag.
  90. var presentation = $(pres).find('>prezi');
  91. if (presentation.length) {
  92. var url = presentation.attr('url');
  93. var current = presentation.find('>current').text();
  94. console.log('presentation info received from', from, url);
  95. if (this.preziMap[from] == null) {
  96. this.preziMap[from] = url;
  97. $(document).trigger('presentationadded.muc', [from, url, current]);
  98. }
  99. else {
  100. $(document).trigger('gotoslide.muc', [from, url, current]);
  101. }
  102. }
  103. else if (this.preziMap[from] != null) {
  104. var url = this.preziMap[from];
  105. delete this.preziMap[from];
  106. $(document).trigger('presentationremoved.muc', [from, url]);
  107. }
  108. // Parse audio info tag.
  109. var audioMuted = $(pres).find('>audiomuted');
  110. if (audioMuted.length) {
  111. $(document).trigger('audiomuted.muc', [from, audioMuted.text()]);
  112. }
  113. // Parse video info tag.
  114. var videoMuted = $(pres).find('>videomuted');
  115. if (videoMuted.length) {
  116. $(document).trigger('videomuted.muc', [from, videoMuted.text()]);
  117. }
  118. var stats = $(pres).find('>stats');
  119. if (stats.length) {
  120. var statsObj = {};
  121. Strophe.forEachChild(stats[0], "stat", function (el) {
  122. statsObj[el.getAttribute("name")] = el.getAttribute("value");
  123. });
  124. connectionquality.updateRemoteStats(from, statsObj);
  125. }
  126. // Parse status.
  127. if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="201"]').length) {
  128. this.isOwner = true;
  129. this.createNonAnonymousRoom();
  130. }
  131. // Parse roles.
  132. var member = {};
  133. member.show = $(pres).find('>show').text();
  134. member.status = $(pres).find('>status').text();
  135. var tmp = $(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>item');
  136. member.affiliation = tmp.attr('affiliation');
  137. member.role = tmp.attr('role');
  138. // Focus recognition
  139. member.jid = tmp.attr('jid');
  140. member.isFocus = false;
  141. if (member.jid
  142. && member.jid.indexOf(Moderator.getFocusUserJid() + "/") == 0) {
  143. member.isFocus = true;
  144. }
  145. var nicktag = $(pres).find('>nick[xmlns="http://jabber.org/protocol/nick"]');
  146. member.displayName = (nicktag.length > 0 ? nicktag.html() : null);
  147. if (from == this.myroomjid) {
  148. if (member.affiliation == 'owner') this.isOwner = true;
  149. if (this.role !== member.role) {
  150. this.role = member.role;
  151. if (Moderator.onLocalRoleChange)
  152. Moderator.onLocalRoleChange(from, member, pres);
  153. UI.onLocalRoleChange(from, member, pres);
  154. }
  155. if (!this.joined) {
  156. this.joined = true;
  157. eventEmitter.emit(XMPPEvents.MUC_JOINED, from, member);
  158. this.list_members.push(from);
  159. }
  160. } else if (this.members[from] === undefined) {
  161. // new participant
  162. this.members[from] = member;
  163. this.list_members.push(from);
  164. console.log('entered', from, member);
  165. if (member.isFocus) {
  166. this.focusMucJid = from;
  167. console.info("Ignore focus: " + from + ", real JID: " + member.jid);
  168. }
  169. else {
  170. var id = $(pres).find('>userID').text();
  171. var email = $(pres).find('>email');
  172. if (email.length > 0) {
  173. id = email.text();
  174. }
  175. UI.onMucEntered(from, id, member.displayName);
  176. API.triggerEvent("participantJoined", {jid: from});
  177. }
  178. } else {
  179. // Presence update for existing participant
  180. // Watch role change:
  181. if (this.members[from].role != member.role) {
  182. this.members[from].role = member.role;
  183. UI.onMucRoleChanged(member.role, member.displayName);
  184. }
  185. }
  186. // Always trigger presence to update bindings
  187. $(document).trigger('presence.muc', [from, member, pres]);
  188. this.parsePresence(from, member, pres);
  189. // Trigger status message update
  190. if (member.status) {
  191. UI.onMucPresenceStatus(from, member);
  192. }
  193. return true;
  194. },
  195. onPresenceUnavailable: function (pres) {
  196. var from = pres.getAttribute('from');
  197. // Status code 110 indicates that this notification is "self-presence".
  198. if (!$(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="110"]').length) {
  199. delete this.members[from];
  200. this.list_members.splice(this.list_members.indexOf(from), 1);
  201. this.onParticipantLeft(from);
  202. }
  203. // If the status code is 110 this means we're leaving and we would like
  204. // to remove everyone else from our view, so we trigger the event.
  205. else if (this.list_members.length > 1) {
  206. for (var i = 0; i < this.list_members.length; i++) {
  207. var member = this.list_members[i];
  208. delete this.members[i];
  209. this.list_members.splice(i, 1);
  210. this.onParticipantLeft(member);
  211. }
  212. }
  213. if ($(pres).find('>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]').length) {
  214. $(document).trigger('kicked.muc', [from]);
  215. if (this.myroomjid === from) {
  216. XMPP.disposeConference(false);
  217. eventEmitter.emit(XMPPEvents.KICKED);
  218. }
  219. }
  220. return true;
  221. },
  222. onPresenceError: function (pres) {
  223. var from = pres.getAttribute('from');
  224. if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
  225. console.log('on password required', from);
  226. var self = this;
  227. UI.onPasswordReqiured(function (value) {
  228. self.doJoin(from, value);
  229. });
  230. } else if ($(pres).find(
  231. '>error[type="cancel"]>not-allowed[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) {
  232. var toDomain = Strophe.getDomainFromJid(pres.getAttribute('to'));
  233. if (toDomain === config.hosts.anonymousdomain) {
  234. // enter the room by replying with 'not-authorized'. This would
  235. // result in reconnection from authorized domain.
  236. // We're either missing Jicofo/Prosody config for anonymous
  237. // domains or something is wrong.
  238. // XMPP.promptLogin();
  239. UI.messageHandler.openReportDialog(null,
  240. 'Oops ! We couldn`t join the conference.' +
  241. ' There might be some problem with security' +
  242. ' configuration. Please contact service' +
  243. ' administrator.', pres);
  244. } else {
  245. console.warn('onPresError ', pres);
  246. UI.messageHandler.openReportDialog(null,
  247. 'Oops! Something went wrong and we couldn`t connect to the conference.',
  248. pres);
  249. }
  250. } else {
  251. console.warn('onPresError ', pres);
  252. UI.messageHandler.openReportDialog(null,
  253. 'Oops! Something went wrong and we couldn`t connect to the conference.',
  254. pres);
  255. }
  256. return true;
  257. },
  258. sendMessage: function (body, nickname) {
  259. var msg = $msg({to: this.roomjid, type: 'groupchat'});
  260. msg.c('body', body).up();
  261. if (nickname) {
  262. msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
  263. }
  264. this.connection.send(msg);
  265. API.triggerEvent("outgoingMessage", {"message": body});
  266. },
  267. setSubject: function (subject) {
  268. var msg = $msg({to: this.roomjid, type: 'groupchat'});
  269. msg.c('subject', subject);
  270. this.connection.send(msg);
  271. console.log("topic changed to " + subject);
  272. },
  273. onMessage: function (msg) {
  274. // FIXME: this is a hack. but jingle on muc makes nickchanges hard
  275. var from = msg.getAttribute('from');
  276. var nick = $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]').text() || Strophe.getResourceFromJid(from);
  277. var txt = $(msg).find('>body').text();
  278. var type = msg.getAttribute("type");
  279. if (type == "error") {
  280. UI.chatAddError($(msg).find('>text').text(), txt);
  281. return true;
  282. }
  283. var subject = $(msg).find('>subject');
  284. if (subject.length) {
  285. var subjectText = subject.text();
  286. if (subjectText || subjectText == "") {
  287. UI.chatSetSubject(subjectText);
  288. console.log("Subject is changed to " + subjectText);
  289. }
  290. }
  291. if (txt) {
  292. console.log('chat', nick, txt);
  293. UI.updateChatConversation(from, nick, txt);
  294. if (from != this.myroomjid)
  295. API.triggerEvent("incomingMessage",
  296. {"from": from, "nick": nick, "message": txt});
  297. }
  298. return true;
  299. },
  300. lockRoom: function (key, onSuccess, onError, onNotSupported) {
  301. //http://xmpp.org/extensions/xep-0045.html#roomconfig
  302. var ob = this;
  303. this.connection.sendIQ($iq({to: this.roomjid, type: 'get'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'}),
  304. function (res) {
  305. if ($(res).find('>query>x[xmlns="jabber:x:data"]>field[var="muc#roomconfig_roomsecret"]').length) {
  306. var formsubmit = $iq({to: ob.roomjid, type: 'set'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'});
  307. formsubmit.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
  308. formsubmit.c('field', {'var': 'FORM_TYPE'}).c('value').t('http://jabber.org/protocol/muc#roomconfig').up().up();
  309. formsubmit.c('field', {'var': 'muc#roomconfig_roomsecret'}).c('value').t(key).up().up();
  310. // Fixes a bug in prosody 0.9.+ https://code.google.com/p/lxmppd/issues/detail?id=373
  311. formsubmit.c('field', {'var': 'muc#roomconfig_whois'}).c('value').t('anyone').up().up();
  312. // FIXME: is muc#roomconfig_passwordprotectedroom required?
  313. this.connection.sendIQ(formsubmit,
  314. onSuccess,
  315. onError);
  316. } else {
  317. onNotSupported();
  318. }
  319. }, onError);
  320. },
  321. kick: function (jid) {
  322. var kickIQ = $iq({to: this.roomjid, type: 'set'})
  323. .c('query', {xmlns: 'http://jabber.org/protocol/muc#admin'})
  324. .c('item', {nick: Strophe.getResourceFromJid(jid), role: 'none'})
  325. .c('reason').t('You have been kicked.').up().up().up();
  326. this.connection.sendIQ(
  327. kickIQ,
  328. function (result) {
  329. console.log('Kick participant with jid: ', jid, result);
  330. },
  331. function (error) {
  332. console.log('Kick participant error: ', error);
  333. });
  334. },
  335. sendPresence: function () {
  336. var pres = $pres({to: this.presMap['to'] });
  337. pres.c('x', {xmlns: this.presMap['xns']});
  338. if (this.presMap['password']) {
  339. pres.c('password').t(this.presMap['password']).up();
  340. }
  341. pres.up();
  342. // Send XEP-0115 'c' stanza that contains our capabilities info
  343. if (this.connection.caps) {
  344. this.connection.caps.node = config.clientNode;
  345. pres.c('c', this.connection.caps.generateCapsAttrs()).up();
  346. }
  347. pres.c('user-agent', {xmlns: 'http://jitsi.org/jitmeet/user-agent'})
  348. .t(navigator.userAgent).up();
  349. if (this.presMap['bridgeIsDown']) {
  350. pres.c('bridgeIsDown').up();
  351. }
  352. if (this.presMap['email']) {
  353. pres.c('email').t(this.presMap['email']).up();
  354. }
  355. if (this.presMap['userId']) {
  356. pres.c('userId').t(this.presMap['userId']).up();
  357. }
  358. if (this.presMap['displayName']) {
  359. // XEP-0172
  360. pres.c('nick', {xmlns: 'http://jabber.org/protocol/nick'})
  361. .t(this.presMap['displayName']).up();
  362. }
  363. if (this.presMap['audions']) {
  364. pres.c('audiomuted', {xmlns: this.presMap['audions']})
  365. .t(this.presMap['audiomuted']).up();
  366. }
  367. if (this.presMap['videons']) {
  368. pres.c('videomuted', {xmlns: this.presMap['videons']})
  369. .t(this.presMap['videomuted']).up();
  370. }
  371. if (this.presMap['statsns']) {
  372. var stats = pres.c('stats', {xmlns: this.presMap['statsns']});
  373. for (var stat in this.presMap["stats"])
  374. if (this.presMap["stats"][stat] != null)
  375. stats.c("stat", {name: stat, value: this.presMap["stats"][stat]}).up();
  376. pres.up();
  377. }
  378. if (this.presMap['prezins']) {
  379. pres.c('prezi',
  380. {xmlns: this.presMap['prezins'],
  381. 'url': this.presMap['preziurl']})
  382. .c('current').t(this.presMap['prezicurrent']).up().up();
  383. }
  384. if (this.presMap['etherpadns']) {
  385. pres.c('etherpad', {xmlns: this.presMap['etherpadns']})
  386. .t(this.presMap['etherpadname']).up();
  387. }
  388. if (this.presMap['medians']) {
  389. pres.c('media', {xmlns: this.presMap['medians']});
  390. var sourceNumber = 0;
  391. Object.keys(this.presMap).forEach(function (key) {
  392. if (key.indexOf('source') >= 0) {
  393. sourceNumber++;
  394. }
  395. });
  396. if (sourceNumber > 0)
  397. for (var i = 1; i <= sourceNumber / 3; i++) {
  398. pres.c('source',
  399. {type: this.presMap['source' + i + '_type'],
  400. ssrc: this.presMap['source' + i + '_ssrc'],
  401. direction: this.presMap['source' + i + '_direction']
  402. || 'sendrecv' }
  403. ).up();
  404. }
  405. }
  406. pres.up();
  407. // console.debug(pres.toString());
  408. this.connection.send(pres);
  409. },
  410. addDisplayNameToPresence: function (displayName) {
  411. this.presMap['displayName'] = displayName;
  412. },
  413. addMediaToPresence: function (sourceNumber, mtype, ssrcs, direction) {
  414. if (!this.presMap['medians'])
  415. this.presMap['medians'] = 'http://estos.de/ns/mjs';
  416. this.presMap['source' + sourceNumber + '_type'] = mtype;
  417. this.presMap['source' + sourceNumber + '_ssrc'] = ssrcs;
  418. this.presMap['source' + sourceNumber + '_direction'] = direction;
  419. },
  420. clearPresenceMedia: function () {
  421. var self = this;
  422. Object.keys(this.presMap).forEach(function (key) {
  423. if (key.indexOf('source') != -1) {
  424. delete self.presMap[key];
  425. }
  426. });
  427. },
  428. addPreziToPresence: function (url, currentSlide) {
  429. this.presMap['prezins'] = 'http://jitsi.org/jitmeet/prezi';
  430. this.presMap['preziurl'] = url;
  431. this.presMap['prezicurrent'] = currentSlide;
  432. },
  433. removePreziFromPresence: function () {
  434. delete this.presMap['prezins'];
  435. delete this.presMap['preziurl'];
  436. delete this.presMap['prezicurrent'];
  437. },
  438. addCurrentSlideToPresence: function (currentSlide) {
  439. this.presMap['prezicurrent'] = currentSlide;
  440. },
  441. getPrezi: function (roomjid) {
  442. return this.preziMap[roomjid];
  443. },
  444. addEtherpadToPresence: function (etherpadName) {
  445. this.presMap['etherpadns'] = 'http://jitsi.org/jitmeet/etherpad';
  446. this.presMap['etherpadname'] = etherpadName;
  447. },
  448. addAudioInfoToPresence: function (isMuted) {
  449. this.presMap['audions'] = 'http://jitsi.org/jitmeet/audio';
  450. this.presMap['audiomuted'] = isMuted.toString();
  451. },
  452. addVideoInfoToPresence: function (isMuted) {
  453. this.presMap['videons'] = 'http://jitsi.org/jitmeet/video';
  454. this.presMap['videomuted'] = isMuted.toString();
  455. },
  456. addConnectionInfoToPresence: function (stats) {
  457. this.presMap['statsns'] = 'http://jitsi.org/jitmeet/stats';
  458. this.presMap['stats'] = stats;
  459. },
  460. findJidFromResource: function (resourceJid) {
  461. if (resourceJid &&
  462. resourceJid === Strophe.getResourceFromJid(this.myroomjid)) {
  463. return this.myroomjid;
  464. }
  465. var peerJid = null;
  466. Object.keys(this.members).some(function (jid) {
  467. peerJid = jid;
  468. return Strophe.getResourceFromJid(jid) === resourceJid;
  469. });
  470. return peerJid;
  471. },
  472. addBridgeIsDownToPresence: function () {
  473. this.presMap['bridgeIsDown'] = true;
  474. },
  475. addEmailToPresence: function (email) {
  476. this.presMap['email'] = email;
  477. },
  478. addUserIdToPresence: function (userId) {
  479. this.presMap['userId'] = userId;
  480. },
  481. isModerator: function () {
  482. return this.role === 'moderator';
  483. },
  484. getMemberRole: function (peerJid) {
  485. if (this.members[peerJid]) {
  486. return this.members[peerJid].role;
  487. }
  488. return null;
  489. },
  490. onParticipantLeft: function (jid) {
  491. UI.onMucLeft(jid);
  492. API.triggerEvent("participantLeft", {jid: jid});
  493. this.connection.jingle.terminateByJid(jid);
  494. if (this.getPrezi(jid)) {
  495. $(document).trigger('presentationremoved.muc',
  496. [jid, this.getPrezi(jid)]);
  497. }
  498. Moderator.onMucLeft(jid);
  499. },
  500. parsePresence: function (from, memeber, pres) {
  501. if($(pres).find(">bridgeIsDown").length > 0 && !bridgeIsDown) {
  502. bridgeIsDown = true;
  503. eventEmitter.emit(XMPPEvents.BRIDGE_DOWN);
  504. }
  505. if(memeber.isFocus)
  506. return;
  507. // Remove old ssrcs coming from the jid
  508. Object.keys(ssrc2jid).forEach(function (ssrc) {
  509. if (ssrc2jid[ssrc] == jid) {
  510. delete ssrc2jid[ssrc];
  511. }
  512. });
  513. var changedStreams = [];
  514. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  515. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  516. var ssrcV = ssrc.getAttribute('ssrc');
  517. ssrc2jid[ssrcV] = from;
  518. JingleSession.notReceivedSSRCs.push(ssrcV);
  519. var type = ssrc.getAttribute('type');
  520. var direction = ssrc.getAttribute('direction');
  521. changedStreams.push({type: type, direction: direction});
  522. });
  523. eventEmitter.emit(XMPPEvents.CHANGED_STREAMS, from, changedStreams);
  524. var displayName = !config.displayJids
  525. ? memeber.displayName : Strophe.getResourceFromJid(from);
  526. if (displayName && displayName.length > 0)
  527. {
  528. // $(document).trigger('displaynamechanged',
  529. // [jid, displayName]);
  530. eventEmitter.emit(XMPPEvents.DISPLAY_NAME_CHANGED, from, displayName);
  531. }
  532. var id = $(pres).find('>userID').text();
  533. var email = $(pres).find('>email');
  534. if(email.length > 0) {
  535. id = email.text();
  536. }
  537. eventEmitter.emit(XMPPEvents.USER_ID_CHANGED, from, id);
  538. }
  539. });
  540. };