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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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. // enter the room by replying with 'not-authorized'. This would
  233. // result in reconnection from authorized domain.
  234. // We're either missing Jicofo/Prosody config for anonymous
  235. // domains or something is wrong.
  236. // XMPP.promptLogin();
  237. UI.messageHandler.openReportDialog(null,
  238. 'Oops ! We couldn`t join the conference.' +
  239. ' There might be some problem with security' +
  240. ' configuration. Please contact service' +
  241. ' administrator.', pres);
  242. } else {
  243. console.warn('onPresError ', pres);
  244. UI.messageHandler.openReportDialog(null,
  245. 'Oops! Something went wrong and we couldn`t connect to the conference.',
  246. pres);
  247. }
  248. } else {
  249. console.warn('onPresError ', pres);
  250. UI.messageHandler.openReportDialog(null,
  251. 'Oops! Something went wrong and we couldn`t connect to the conference.',
  252. pres);
  253. }
  254. return true;
  255. },
  256. sendMessage: function (body, nickname) {
  257. var msg = $msg({to: this.roomjid, type: 'groupchat'});
  258. msg.c('body', body).up();
  259. if (nickname) {
  260. msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
  261. }
  262. this.connection.send(msg);
  263. API.triggerEvent("outgoingMessage", {"message": body});
  264. },
  265. setSubject: function (subject) {
  266. var msg = $msg({to: this.roomjid, type: 'groupchat'});
  267. msg.c('subject', subject);
  268. this.connection.send(msg);
  269. console.log("topic changed to " + subject);
  270. },
  271. onMessage: function (msg) {
  272. // FIXME: this is a hack. but jingle on muc makes nickchanges hard
  273. var from = msg.getAttribute('from');
  274. var nick = $(msg).find('>nick[xmlns="http://jabber.org/protocol/nick"]').text() || Strophe.getResourceFromJid(from);
  275. var txt = $(msg).find('>body').text();
  276. var type = msg.getAttribute("type");
  277. if (type == "error") {
  278. UI.chatAddError($(msg).find('>text').text(), txt);
  279. return true;
  280. }
  281. var subject = $(msg).find('>subject');
  282. if (subject.length) {
  283. var subjectText = subject.text();
  284. if (subjectText || subjectText == "") {
  285. UI.chatSetSubject(subjectText);
  286. console.log("Subject is changed to " + subjectText);
  287. }
  288. }
  289. if (txt) {
  290. console.log('chat', nick, txt);
  291. UI.updateChatConversation(from, nick, txt);
  292. if (from != this.myroomjid)
  293. API.triggerEvent("incomingMessage",
  294. {"from": from, "nick": nick, "message": txt});
  295. }
  296. return true;
  297. },
  298. lockRoom: function (key, onSuccess, onError, onNotSupported) {
  299. //http://xmpp.org/extensions/xep-0045.html#roomconfig
  300. var ob = this;
  301. this.connection.sendIQ($iq({to: this.roomjid, type: 'get'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'}),
  302. function (res) {
  303. if ($(res).find('>query>x[xmlns="jabber:x:data"]>field[var="muc#roomconfig_roomsecret"]').length) {
  304. var formsubmit = $iq({to: ob.roomjid, type: 'set'}).c('query', {xmlns: 'http://jabber.org/protocol/muc#owner'});
  305. formsubmit.c('x', {xmlns: 'jabber:x:data', type: 'submit'});
  306. formsubmit.c('field', {'var': 'FORM_TYPE'}).c('value').t('http://jabber.org/protocol/muc#roomconfig').up().up();
  307. formsubmit.c('field', {'var': 'muc#roomconfig_roomsecret'}).c('value').t(key).up().up();
  308. // Fixes a bug in prosody 0.9.+ https://code.google.com/p/lxmppd/issues/detail?id=373
  309. formsubmit.c('field', {'var': 'muc#roomconfig_whois'}).c('value').t('anyone').up().up();
  310. // FIXME: is muc#roomconfig_passwordprotectedroom required?
  311. this.connection.sendIQ(formsubmit,
  312. onSuccess,
  313. onError);
  314. } else {
  315. onNotSupported();
  316. }
  317. }, onError);
  318. },
  319. kick: function (jid) {
  320. var kickIQ = $iq({to: this.roomjid, type: 'set'})
  321. .c('query', {xmlns: 'http://jabber.org/protocol/muc#admin'})
  322. .c('item', {nick: Strophe.getResourceFromJid(jid), role: 'none'})
  323. .c('reason').t('You have been kicked.').up().up().up();
  324. this.connection.sendIQ(
  325. kickIQ,
  326. function (result) {
  327. console.log('Kick participant with jid: ', jid, result);
  328. },
  329. function (error) {
  330. console.log('Kick participant error: ', error);
  331. });
  332. },
  333. sendPresence: function () {
  334. var pres = $pres({to: this.presMap['to'] });
  335. pres.c('x', {xmlns: this.presMap['xns']});
  336. if (this.presMap['password']) {
  337. pres.c('password').t(this.presMap['password']).up();
  338. }
  339. pres.up();
  340. // Send XEP-0115 'c' stanza that contains our capabilities info
  341. if (this.connection.caps) {
  342. this.connection.caps.node = config.clientNode;
  343. pres.c('c', this.connection.caps.generateCapsAttrs()).up();
  344. }
  345. pres.c('user-agent', {xmlns: 'http://jitsi.org/jitmeet/user-agent'})
  346. .t(navigator.userAgent).up();
  347. if (this.presMap['bridgeIsDown']) {
  348. pres.c('bridgeIsDown').up();
  349. }
  350. if (this.presMap['email']) {
  351. pres.c('email').t(this.presMap['email']).up();
  352. }
  353. if (this.presMap['userId']) {
  354. pres.c('userId').t(this.presMap['userId']).up();
  355. }
  356. if (this.presMap['displayName']) {
  357. // XEP-0172
  358. pres.c('nick', {xmlns: 'http://jabber.org/protocol/nick'})
  359. .t(this.presMap['displayName']).up();
  360. }
  361. if (this.presMap['audions']) {
  362. pres.c('audiomuted', {xmlns: this.presMap['audions']})
  363. .t(this.presMap['audiomuted']).up();
  364. }
  365. if (this.presMap['videons']) {
  366. pres.c('videomuted', {xmlns: this.presMap['videons']})
  367. .t(this.presMap['videomuted']).up();
  368. }
  369. if (this.presMap['statsns']) {
  370. var stats = pres.c('stats', {xmlns: this.presMap['statsns']});
  371. for (var stat in this.presMap["stats"])
  372. if (this.presMap["stats"][stat] != null)
  373. stats.c("stat", {name: stat, value: this.presMap["stats"][stat]}).up();
  374. pres.up();
  375. }
  376. if (this.presMap['prezins']) {
  377. pres.c('prezi',
  378. {xmlns: this.presMap['prezins'],
  379. 'url': this.presMap['preziurl']})
  380. .c('current').t(this.presMap['prezicurrent']).up().up();
  381. }
  382. if (this.presMap['etherpadns']) {
  383. pres.c('etherpad', {xmlns: this.presMap['etherpadns']})
  384. .t(this.presMap['etherpadname']).up();
  385. }
  386. if (this.presMap['medians']) {
  387. pres.c('media', {xmlns: this.presMap['medians']});
  388. var sourceNumber = 0;
  389. Object.keys(this.presMap).forEach(function (key) {
  390. if (key.indexOf('source') >= 0) {
  391. sourceNumber++;
  392. }
  393. });
  394. if (sourceNumber > 0)
  395. for (var i = 1; i <= sourceNumber / 3; i++) {
  396. pres.c('source',
  397. {type: this.presMap['source' + i + '_type'],
  398. ssrc: this.presMap['source' + i + '_ssrc'],
  399. direction: this.presMap['source' + i + '_direction']
  400. || 'sendrecv' }
  401. ).up();
  402. }
  403. }
  404. pres.up();
  405. // console.debug(pres.toString());
  406. this.connection.send(pres);
  407. },
  408. addDisplayNameToPresence: function (displayName) {
  409. this.presMap['displayName'] = displayName;
  410. },
  411. addMediaToPresence: function (sourceNumber, mtype, ssrcs, direction) {
  412. if (!this.presMap['medians'])
  413. this.presMap['medians'] = 'http://estos.de/ns/mjs';
  414. this.presMap['source' + sourceNumber + '_type'] = mtype;
  415. this.presMap['source' + sourceNumber + '_ssrc'] = ssrcs;
  416. this.presMap['source' + sourceNumber + '_direction'] = direction;
  417. },
  418. clearPresenceMedia: function () {
  419. var self = this;
  420. Object.keys(this.presMap).forEach(function (key) {
  421. if (key.indexOf('source') != -1) {
  422. delete self.presMap[key];
  423. }
  424. });
  425. },
  426. addPreziToPresence: function (url, currentSlide) {
  427. this.presMap['prezins'] = 'http://jitsi.org/jitmeet/prezi';
  428. this.presMap['preziurl'] = url;
  429. this.presMap['prezicurrent'] = currentSlide;
  430. },
  431. removePreziFromPresence: function () {
  432. delete this.presMap['prezins'];
  433. delete this.presMap['preziurl'];
  434. delete this.presMap['prezicurrent'];
  435. },
  436. addCurrentSlideToPresence: function (currentSlide) {
  437. this.presMap['prezicurrent'] = currentSlide;
  438. },
  439. getPrezi: function (roomjid) {
  440. return this.preziMap[roomjid];
  441. },
  442. addEtherpadToPresence: function (etherpadName) {
  443. this.presMap['etherpadns'] = 'http://jitsi.org/jitmeet/etherpad';
  444. this.presMap['etherpadname'] = etherpadName;
  445. },
  446. addAudioInfoToPresence: function (isMuted) {
  447. this.presMap['audions'] = 'http://jitsi.org/jitmeet/audio';
  448. this.presMap['audiomuted'] = isMuted.toString();
  449. },
  450. addVideoInfoToPresence: function (isMuted) {
  451. this.presMap['videons'] = 'http://jitsi.org/jitmeet/video';
  452. this.presMap['videomuted'] = isMuted.toString();
  453. },
  454. addConnectionInfoToPresence: function (stats) {
  455. this.presMap['statsns'] = 'http://jitsi.org/jitmeet/stats';
  456. this.presMap['stats'] = stats;
  457. },
  458. findJidFromResource: function (resourceJid) {
  459. if (resourceJid &&
  460. resourceJid === Strophe.getResourceFromJid(this.myroomjid)) {
  461. return this.myroomjid;
  462. }
  463. var peerJid = null;
  464. Object.keys(this.members).some(function (jid) {
  465. peerJid = jid;
  466. return Strophe.getResourceFromJid(jid) === resourceJid;
  467. });
  468. return peerJid;
  469. },
  470. addBridgeIsDownToPresence: function () {
  471. this.presMap['bridgeIsDown'] = true;
  472. },
  473. addEmailToPresence: function (email) {
  474. this.presMap['email'] = email;
  475. },
  476. addUserIdToPresence: function (userId) {
  477. this.presMap['userId'] = userId;
  478. },
  479. isModerator: function () {
  480. return this.role === 'moderator';
  481. },
  482. getMemberRole: function (peerJid) {
  483. if (this.members[peerJid]) {
  484. return this.members[peerJid].role;
  485. }
  486. return null;
  487. },
  488. onParticipantLeft: function (jid) {
  489. UI.onMucLeft(jid);
  490. API.triggerEvent("participantLeft", {jid: jid});
  491. delete jid2Ssrc[jid];
  492. this.connection.jingle.terminateByJid(jid);
  493. if (this.getPrezi(jid)) {
  494. $(document).trigger('presentationremoved.muc',
  495. [jid, this.getPrezi(jid)]);
  496. }
  497. Moderator.onMucLeft(jid);
  498. },
  499. parsePresence: function (from, memeber, pres) {
  500. if($(pres).find(">bridgeIsDown").length > 0 && !bridgeIsDown) {
  501. bridgeIsDown = true;
  502. eventEmitter.emit(XMPPEvents.BRIDGE_DOWN);
  503. }
  504. if(memeber.isFocus)
  505. return;
  506. // Remove old ssrcs coming from the jid
  507. Object.keys(ssrc2jid).forEach(function (ssrc) {
  508. if (ssrc2jid[ssrc] == jid) {
  509. delete ssrc2jid[ssrc];
  510. delete ssrc2videoType[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. notReceivedSSRCs.push(ssrcV);
  519. var type = ssrc.getAttribute('type');
  520. ssrc2videoType[ssrcV] = type;
  521. var direction = ssrc.getAttribute('direction');
  522. changedStreams.push({type: type, direction: direction});
  523. });
  524. eventEmitter.emit(XMPPEvents.CHANGED_STREAMS, from, changedStreams);
  525. var displayName = !config.displayJids
  526. ? memeber.displayName : Strophe.getResourceFromJid(from);
  527. if (displayName && displayName.length > 0)
  528. {
  529. // $(document).trigger('displaynamechanged',
  530. // [jid, displayName]);
  531. eventEmitter.emit(XMPPEvents.DISPLAY_NAME_CHANGED, from, displayName);
  532. }
  533. var id = $(pres).find('>userID').text();
  534. var email = $(pres).find('>email');
  535. if(email.length > 0) {
  536. id = email.text();
  537. }
  538. eventEmitter.emit(XMPPEvents.USER_ID_CHANGED, from, id);
  539. }
  540. });
  541. };