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.

strophe.emuc.js 25KB

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