您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

strophe.emuc.js 25KB

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