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.

JitsiConference.js 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /* global Strophe, $, Promise */
  2. /* jshint -W101 */
  3. var logger = require("jitsi-meet-logger").getLogger(__filename);
  4. var RTC = require("./modules/RTC/RTC");
  5. var XMPPEvents = require("./service/xmpp/XMPPEvents");
  6. var AuthenticationEvents = require("./service/authentication/AuthenticationEvents");
  7. var RTCEvents = require("./service/RTC/RTCEvents");
  8. var EventEmitter = require("events");
  9. var JitsiConferenceEvents = require("./JitsiConferenceEvents");
  10. var JitsiConferenceErrors = require("./JitsiConferenceErrors");
  11. var JitsiParticipant = require("./JitsiParticipant");
  12. var Statistics = require("./modules/statistics/statistics");
  13. var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
  14. var JitsiTrackEvents = require("./JitsiTrackEvents");
  15. /**
  16. * Creates a JitsiConference object with the given name and properties.
  17. * Note: this constructor is not a part of the public API (objects should be
  18. * created using JitsiConnection.createConference).
  19. * @param options.config properties / settings related to the conference that will be created.
  20. * @param options.name the name of the conference
  21. * @param options.connection the JitsiConnection object for this JitsiConference.
  22. * @constructor
  23. */
  24. function JitsiConference(options) {
  25. if(!options.name || options.name.toLowerCase() !== options.name) {
  26. logger.error("Invalid conference name (no conference name passed or it"
  27. + "contains invalid characters like capital letters)!");
  28. return;
  29. }
  30. this.options = options;
  31. this.connection = this.options.connection;
  32. this.xmpp = this.connection.xmpp;
  33. this.eventEmitter = new EventEmitter();
  34. this.room = this.xmpp.createRoom(this.options.name, this.options.config);
  35. this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
  36. this.rtc = new RTC(this.room, options);
  37. if(!RTC.options.disableAudioLevels)
  38. this.statistics = new Statistics();
  39. setupListeners(this);
  40. this.participants = {};
  41. this.lastActiveSpeaker = null;
  42. this.dtmfManager = null;
  43. this.somebodySupportsDTMF = false;
  44. this.authEnabled = false;
  45. this.authIdentity;
  46. }
  47. /**
  48. * Joins the conference.
  49. * @param password {string} the password
  50. */
  51. JitsiConference.prototype.join = function (password) {
  52. if(this.room)
  53. this.room.join(password, this.connection.tokenPassword);
  54. };
  55. /**
  56. * Check if joined to the conference.
  57. */
  58. JitsiConference.prototype.isJoined = function () {
  59. return this.room && this.room.joined;
  60. };
  61. /**
  62. * Leaves the conference.
  63. */
  64. JitsiConference.prototype.leave = function () {
  65. if(this.xmpp && this.room)
  66. this.xmpp.leaveRoom(this.room.roomjid);
  67. this.room = null;
  68. };
  69. /**
  70. * Returns name of this conference.
  71. */
  72. JitsiConference.prototype.getName = function () {
  73. return this.options.name;
  74. };
  75. /**
  76. * Check if authentication is enabled for this conference.
  77. */
  78. JitsiConference.prototype.isAuthEnabled = function () {
  79. return this.authEnabled;
  80. };
  81. /**
  82. * Check if user is logged in.
  83. */
  84. JitsiConference.prototype.isLoggedIn = function () {
  85. return !!this.authIdentity;
  86. };
  87. /**
  88. * Get authorized login.
  89. */
  90. JitsiConference.prototype.getAuthLogin = function () {
  91. return this.authIdentity;
  92. };
  93. /**
  94. * Check if external authentication is enabled for this conference.
  95. */
  96. JitsiConference.prototype.isExternalAuthEnabled = function () {
  97. return this.room && this.room.moderator.isExternalAuthEnabled();
  98. };
  99. /**
  100. * Get url for external authentication.
  101. * @param {boolean} [urlForPopup] if true then return url for login popup,
  102. * else url of login page.
  103. * @returns {Promise}
  104. */
  105. JitsiConference.prototype.getExternalAuthUrl = function (urlForPopup) {
  106. return new Promise(function (resolve, reject) {
  107. if (!this.isExternalAuthEnabled()) {
  108. reject();
  109. return;
  110. }
  111. if (urlForPopup) {
  112. this.room.moderator.getPopupLoginUrl(resolve, reject);
  113. } else {
  114. this.room.moderator.getLoginUrl(resolve, reject);
  115. }
  116. }.bind(this));
  117. };
  118. /**
  119. * Returns the local tracks.
  120. */
  121. JitsiConference.prototype.getLocalTracks = function () {
  122. if (this.rtc) {
  123. return this.rtc.localStreams;
  124. } else {
  125. return [];
  126. }
  127. };
  128. /**
  129. * Attaches a handler for events(For example - "participant joined".) in the conference. All possible event are defined
  130. * in JitsiConferenceEvents.
  131. * @param eventId the event ID.
  132. * @param handler handler for the event.
  133. *
  134. * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
  135. */
  136. JitsiConference.prototype.on = function (eventId, handler) {
  137. if(this.eventEmitter)
  138. this.eventEmitter.on(eventId, handler);
  139. };
  140. /**
  141. * Removes event listener
  142. * @param eventId the event ID.
  143. * @param [handler] optional, the specific handler to unbind
  144. *
  145. * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
  146. */
  147. JitsiConference.prototype.off = function (eventId, handler) {
  148. if(this.eventEmitter)
  149. this.eventEmitter.removeListener(eventId, handler);
  150. };
  151. // Common aliases for event emitter
  152. JitsiConference.prototype.addEventListener = JitsiConference.prototype.on;
  153. JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
  154. /**
  155. * Receives notifications from another participants for commands / custom events
  156. * (send by sendPresenceCommand method).
  157. * @param command {String} the name of the command
  158. * @param handler {Function} handler for the command
  159. */
  160. JitsiConference.prototype.addCommandListener = function (command, handler) {
  161. if(this.room)
  162. this.room.addPresenceListener(command, handler);
  163. };
  164. /**
  165. * Removes command listener
  166. * @param command {String} the name of the command
  167. */
  168. JitsiConference.prototype.removeCommandListener = function (command) {
  169. if(this.room)
  170. this.room.removePresenceListener(command);
  171. };
  172. /**
  173. * Sends text message to the other participants in the conference
  174. * @param message the text message.
  175. */
  176. JitsiConference.prototype.sendTextMessage = function (message) {
  177. if(this.room)
  178. this.room.sendMessage(message);
  179. };
  180. /**
  181. * Send presence command.
  182. * @param name the name of the command.
  183. * @param values Object with keys and values that will be send.
  184. **/
  185. JitsiConference.prototype.sendCommand = function (name, values) {
  186. if(this.room) {
  187. this.room.addToPresence(name, values);
  188. this.room.sendPresence();
  189. }
  190. };
  191. /**
  192. * Send presence command one time.
  193. * @param name the name of the command.
  194. * @param values Object with keys and values that will be send.
  195. **/
  196. JitsiConference.prototype.sendCommandOnce = function (name, values) {
  197. this.sendCommand(name, values);
  198. this.removeCommand(name);
  199. };
  200. /**
  201. * Send presence command.
  202. * @param name the name of the command.
  203. * @param values Object with keys and values that will be send.
  204. * @param persistent if false the command will be sent only one time
  205. **/
  206. JitsiConference.prototype.removeCommand = function (name) {
  207. if(this.room)
  208. this.room.removeFromPresence(name);
  209. };
  210. /**
  211. * Sets the display name for this conference.
  212. * @param name the display name to set
  213. */
  214. JitsiConference.prototype.setDisplayName = function(name) {
  215. if(this.room){
  216. // remove previously set nickname
  217. this.room.removeFromPresence("nick");
  218. this.room.addToPresence("nick", {attributes: {xmlns: 'http://jabber.org/protocol/nick'}, value: name});
  219. this.room.sendPresence();
  220. }
  221. };
  222. /**
  223. * Adds JitsiLocalTrack object to the conference.
  224. * @param track the JitsiLocalTrack object.
  225. */
  226. JitsiConference.prototype.addTrack = function (track) {
  227. this.room.addStream(track.getOriginalStream(), function () {
  228. this.rtc.addLocalStream(track);
  229. var muteHandler = this._fireMuteChangeEvent.bind(this, track);
  230. var stopHandler = this.removeTrack.bind(this, track);
  231. var audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
  232. track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED, muteHandler);
  233. track.addEventListener(JitsiTrackEvents.TRACK_STOPPED, stopHandler);
  234. track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
  235. this.addEventListener(JitsiConferenceEvents.TRACK_REMOVED, function (someTrack) {
  236. if (someTrack !== track) {
  237. return;
  238. }
  239. track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED, muteHandler);
  240. track.removeEventListener(JitsiTrackEvents.TRACK_STOPPED, stopHandler);
  241. track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED, audioLevelHandler);
  242. });
  243. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  244. }.bind(this));
  245. };
  246. /**
  247. * Fires TRACK_AUDIO_LEVEL_CHANGED change conference event.
  248. * @param audioLevel the audio level
  249. */
  250. JitsiConference.prototype._fireAudioLevelChangeEvent = function (audioLevel) {
  251. this.eventEmitter.emit(
  252. JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  253. this.myUserId(), audioLevel);
  254. };
  255. /**
  256. * Fires TRACK_MUTE_CHANGED change conference event.
  257. * @param track the JitsiTrack object related to the event.
  258. */
  259. JitsiConference.prototype._fireMuteChangeEvent = function (track) {
  260. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  261. };
  262. /**
  263. * Removes JitsiLocalTrack object to the conference.
  264. * @param track the JitsiLocalTrack object.
  265. */
  266. JitsiConference.prototype.removeTrack = function (track) {
  267. if(!this.room){
  268. if(this.rtc)
  269. this.rtc.removeLocalStream(track);
  270. return;
  271. }
  272. this.room.removeStream(track.getOriginalStream(), function(){
  273. this.rtc.removeLocalStream(track);
  274. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  275. }.bind(this));
  276. };
  277. /**
  278. * Get role of the local user.
  279. * @returns {string} user role: 'moderator' or 'none'
  280. */
  281. JitsiConference.prototype.getRole = function () {
  282. return this.room.role;
  283. };
  284. /**
  285. * Check if local user is moderator.
  286. * @returns {boolean} true if local user is moderator, false otherwise.
  287. */
  288. JitsiConference.prototype.isModerator = function () {
  289. return this.room.isModerator();
  290. };
  291. /**
  292. * Set password for the room.
  293. * @param {string} password new password for the room.
  294. * @returns {Promise}
  295. */
  296. JitsiConference.prototype.lock = function (password) {
  297. if (!this.isModerator()) {
  298. return Promise.reject();
  299. }
  300. var conference = this;
  301. return new Promise(function (resolve, reject) {
  302. conference.xmpp.lockRoom(password, function () {
  303. resolve();
  304. }, function (err) {
  305. reject(err);
  306. }, function () {
  307. reject(JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED);
  308. });
  309. });
  310. };
  311. /**
  312. * Remove password from the room.
  313. * @returns {Promise}
  314. */
  315. JitsiConference.prototype.unlock = function () {
  316. return this.lock(undefined);
  317. };
  318. /**
  319. * Elects the participant with the given id to be the selected participant or the speaker.
  320. * @param id the identifier of the participant
  321. */
  322. JitsiConference.prototype.selectParticipant = function(participantId) {
  323. if (this.rtc) {
  324. this.rtc.selectedEndpoint(participantId);
  325. }
  326. };
  327. /**
  328. *
  329. * @param id the identifier of the participant
  330. */
  331. JitsiConference.prototype.pinParticipant = function(participantId) {
  332. if (this.rtc) {
  333. this.rtc.pinEndpoint(participantId);
  334. }
  335. };
  336. /**
  337. * Returns the list of participants for this conference.
  338. * @return Array<JitsiParticipant> a list of participant identifiers containing all conference participants.
  339. */
  340. JitsiConference.prototype.getParticipants = function() {
  341. return Object.keys(this.participants).map(function (key) {
  342. return this.participants[key];
  343. }, this);
  344. };
  345. /**
  346. * @returns {JitsiParticipant} the participant in this conference with the specified id (or
  347. * undefined if there isn't one).
  348. * @param id the id of the participant.
  349. */
  350. JitsiConference.prototype.getParticipantById = function(id) {
  351. return this.participants[id];
  352. };
  353. JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
  354. var id = Strophe.getResourceFromJid(jid);
  355. if (id === 'focus') {
  356. return;
  357. }
  358. var participant = new JitsiParticipant(id, this, nick);
  359. this.participants[id] = participant;
  360. this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
  361. this.xmpp.connection.disco.info(
  362. jid, "node", function(iq) {
  363. participant._supportsDTMF = $(iq).find(
  364. '>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
  365. this.updateDTMFSupport();
  366. }.bind(this)
  367. );
  368. };
  369. JitsiConference.prototype.onMemberLeft = function (jid) {
  370. var id = Strophe.getResourceFromJid(jid);
  371. if (id === 'focus') {
  372. return;
  373. }
  374. var participant = this.participants[id];
  375. delete this.participants[id];
  376. this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
  377. };
  378. JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
  379. var id = Strophe.getResourceFromJid(jid);
  380. var participant = this.getParticipantById(id);
  381. if (!participant) {
  382. return;
  383. }
  384. participant._role = role;
  385. this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
  386. };
  387. JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
  388. var id = Strophe.getResourceFromJid(jid);
  389. var participant = this.getParticipantById(id);
  390. if (!participant) {
  391. return;
  392. }
  393. participant._displayName = displayName;
  394. this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
  395. };
  396. JitsiConference.prototype.onTrackAdded = function (track) {
  397. var id = track.getParticipantId();
  398. var participant = this.getParticipantById(id);
  399. if (!participant) {
  400. return;
  401. }
  402. // add track to JitsiParticipant
  403. participant._tracks.push(track);
  404. var emitter = this.eventEmitter;
  405. track.addEventListener(
  406. JitsiTrackEvents.TRACK_STOPPED,
  407. function () {
  408. // remove track from JitsiParticipant
  409. var pos = participant._tracks.indexOf(track);
  410. if (pos > -1) {
  411. participant._tracks.splice(pos, 1);
  412. }
  413. emitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  414. }
  415. );
  416. track.addEventListener(
  417. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  418. function () {
  419. emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  420. }
  421. );
  422. track.addEventListener(
  423. JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  424. function (audioLevel) {
  425. emitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, id, audioLevel);
  426. }
  427. );
  428. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  429. };
  430. JitsiConference.prototype.updateDTMFSupport = function () {
  431. var somebodySupportsDTMF = false;
  432. var participants = this.getParticipants();
  433. // check if at least 1 participant supports DTMF
  434. for (var i = 0; i < participants.length; i += 1) {
  435. if (participants[i].supportsDTMF()) {
  436. somebodySupportsDTMF = true;
  437. break;
  438. }
  439. }
  440. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  441. this.somebodySupportsDTMF = somebodySupportsDTMF;
  442. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  443. }
  444. };
  445. /**
  446. * Allows to check if there is at least one user in the conference
  447. * that supports DTMF.
  448. * @returns {boolean} true if somebody supports DTMF, false otherwise
  449. */
  450. JitsiConference.prototype.isDTMFSupported = function () {
  451. return this.somebodySupportsDTMF;
  452. };
  453. /**
  454. * Returns the local user's ID
  455. * @return {string} local user's ID
  456. */
  457. JitsiConference.prototype.myUserId = function () {
  458. return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  459. };
  460. JitsiConference.prototype.sendTones = function (tones, duration, pause) {
  461. if (!this.dtmfManager) {
  462. var connection = this.xmpp.connection.jingle.activecall.peerconnection;
  463. if (!connection) {
  464. logger.warn("cannot sendTones: no conneciton");
  465. return;
  466. }
  467. var tracks = this.getLocalTracks().filter(function (track) {
  468. return track.isAudioTrack();
  469. });
  470. if (!tracks.length) {
  471. logger.warn("cannot sendTones: no local audio stream");
  472. return;
  473. }
  474. this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
  475. }
  476. this.dtmfManager.sendTones(tones, duration, pause);
  477. };
  478. /**
  479. * Setups the listeners needed for the conference.
  480. * @param conference the conference
  481. */
  482. function setupListeners(conference) {
  483. conference.xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
  484. conference.rtc.onIncommingCall(event);
  485. if(conference.statistics)
  486. conference.statistics.startRemoteStats(event.peerconnection);
  487. });
  488. conference.room.addListener(XMPPEvents.REMOTE_STREAM_RECEIVED,
  489. function (data, sid, thessrc) {
  490. var track = conference.rtc.createRemoteStream(data, sid, thessrc);
  491. if (track) {
  492. conference.onTrackAdded(track);
  493. }
  494. }
  495. );
  496. conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  497. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
  498. });
  499. conference.room.addListener(XMPPEvents.ROOM_JOIN_ERROR, function (pres) {
  500. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONNECTION_ERROR, pres);
  501. });
  502. conference.room.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function (pres) {
  503. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONNECTION_ERROR, pres);
  504. });
  505. conference.room.addListener(XMPPEvents.PASSWORD_REQUIRED, function (pres) {
  506. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.PASSWORD_REQUIRED, pres);
  507. });
  508. conference.room.addListener(XMPPEvents.AUTHENTICATION_REQUIRED, function () {
  509. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  510. });
  511. // FIXME
  512. // conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  513. // conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
  514. // });
  515. conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
  516. conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));
  517. conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
  518. conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
  519. conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
  520. });
  521. conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
  522. conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
  523. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
  524. });
  525. conference.room.addListener(XMPPEvents.CONNECTION_RESTORED, function () {
  526. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_RESTORED);
  527. });
  528. conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
  529. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.SETUP_FAILED);
  530. });
  531. conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
  532. conference.authEnabled = authEnabled;
  533. conference.authIdentity = authIdentity;
  534. });
  535. conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
  536. var id = Strophe.getResourceFromJid(jid);
  537. conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
  538. });
  539. conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
  540. if(conference.lastActiveSpeaker !== id && conference.room) {
  541. conference.lastActiveSpeaker = id;
  542. conference.eventEmitter.emit(JitsiConferenceEvents.ACTIVE_SPEAKER_CHANGED, id);
  543. }
  544. });
  545. conference.rtc.addListener(RTCEvents.LASTN_CHANGED, function (oldValue, newValue) {
  546. conference.eventEmitter.emit(JitsiConferenceEvents.IN_LAST_N_CHANGED, oldValue, newValue);
  547. });
  548. conference.rtc.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  549. function (lastNEndpoints, endpointsEnteringLastN) {
  550. conference.eventEmitter.emit(JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  551. lastNEndpoints, endpointsEnteringLastN);
  552. });
  553. conference.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, function () {
  554. conference.eventEmitter.emit(JitsiConferenceErrors.PASSWORD_REQUIRED);
  555. });
  556. if(conference.statistics) {
  557. //FIXME: Maybe remove event should not be associated with the conference.
  558. conference.statistics.addAudioLevelListener(function (ssrc, level) {
  559. var userId = null;
  560. var jid = conference.room.getJidBySSRC(ssrc);
  561. if (!jid)
  562. return;
  563. conference.rtc.setAudioLevel(jid, level);
  564. });
  565. conference.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,
  566. function () {
  567. conference.statistics.dispose();
  568. });
  569. // FIXME: Maybe we should move this.
  570. // RTC.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED, function (devices) {
  571. // conference.room.updateDeviceAvailability(devices);
  572. // });
  573. }
  574. }
  575. module.exports = JitsiConference;