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 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  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);
  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. /**
  354. * Kick participant from this conference.
  355. * @param {string} id id of the participant to kick
  356. */
  357. JitsiConference.prototype.kickParticipant = function (id) {
  358. var participant = this.getParticipantById(id);
  359. if (!participant) {
  360. return;
  361. }
  362. this.room.kick(participant.getJid());
  363. };
  364. JitsiConference.prototype.onMemberJoined = function (jid, email, nick) {
  365. var id = Strophe.getResourceFromJid(jid);
  366. if (id === 'focus') {
  367. return;
  368. }
  369. var participant = new JitsiParticipant(jid, this, nick);
  370. this.participants[id] = participant;
  371. this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
  372. this.xmpp.connection.disco.info(
  373. jid, "node", function(iq) {
  374. participant._supportsDTMF = $(iq).find(
  375. '>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
  376. this.updateDTMFSupport();
  377. }.bind(this)
  378. );
  379. };
  380. JitsiConference.prototype.onMemberLeft = function (jid) {
  381. var id = Strophe.getResourceFromJid(jid);
  382. if (id === 'focus' || this.myUserId() === id) {
  383. return;
  384. }
  385. var participant = this.participants[id];
  386. delete this.participants[id];
  387. this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
  388. };
  389. JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
  390. var id = Strophe.getResourceFromJid(jid);
  391. var participant = this.getParticipantById(id);
  392. if (!participant) {
  393. return;
  394. }
  395. participant._role = role;
  396. this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
  397. };
  398. JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
  399. var id = Strophe.getResourceFromJid(jid);
  400. var participant = this.getParticipantById(id);
  401. if (!participant) {
  402. return;
  403. }
  404. participant._displayName = displayName;
  405. this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
  406. };
  407. JitsiConference.prototype.onTrackAdded = function (track) {
  408. var id = track.getParticipantId();
  409. var participant = this.getParticipantById(id);
  410. if (!participant) {
  411. return;
  412. }
  413. // add track to JitsiParticipant
  414. participant._tracks.push(track);
  415. var emitter = this.eventEmitter;
  416. track.addEventListener(
  417. JitsiTrackEvents.TRACK_STOPPED,
  418. function () {
  419. // remove track from JitsiParticipant
  420. var pos = participant._tracks.indexOf(track);
  421. if (pos > -1) {
  422. participant._tracks.splice(pos, 1);
  423. }
  424. emitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  425. }
  426. );
  427. track.addEventListener(
  428. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  429. function () {
  430. emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  431. }
  432. );
  433. track.addEventListener(
  434. JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  435. function (audioLevel) {
  436. emitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, id, audioLevel);
  437. }
  438. );
  439. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  440. };
  441. JitsiConference.prototype.updateDTMFSupport = function () {
  442. var somebodySupportsDTMF = false;
  443. var participants = this.getParticipants();
  444. // check if at least 1 participant supports DTMF
  445. for (var i = 0; i < participants.length; i += 1) {
  446. if (participants[i].supportsDTMF()) {
  447. somebodySupportsDTMF = true;
  448. break;
  449. }
  450. }
  451. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  452. this.somebodySupportsDTMF = somebodySupportsDTMF;
  453. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  454. }
  455. };
  456. /**
  457. * Allows to check if there is at least one user in the conference
  458. * that supports DTMF.
  459. * @returns {boolean} true if somebody supports DTMF, false otherwise
  460. */
  461. JitsiConference.prototype.isDTMFSupported = function () {
  462. return this.somebodySupportsDTMF;
  463. };
  464. /**
  465. * Returns the local user's ID
  466. * @return {string} local user's ID
  467. */
  468. JitsiConference.prototype.myUserId = function () {
  469. return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  470. };
  471. JitsiConference.prototype.sendTones = function (tones, duration, pause) {
  472. if (!this.dtmfManager) {
  473. var connection = this.xmpp.connection.jingle.activecall.peerconnection;
  474. if (!connection) {
  475. logger.warn("cannot sendTones: no conneciton");
  476. return;
  477. }
  478. var tracks = this.getLocalTracks().filter(function (track) {
  479. return track.isAudioTrack();
  480. });
  481. if (!tracks.length) {
  482. logger.warn("cannot sendTones: no local audio stream");
  483. return;
  484. }
  485. this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
  486. }
  487. this.dtmfManager.sendTones(tones, duration, pause);
  488. };
  489. /**
  490. * Returns true if the recording is supproted and false if not.
  491. */
  492. JitsiConference.prototype.isRecordingSupported = function () {
  493. if(this.room)
  494. return this.room.isRecordingSupported();
  495. return false;
  496. };
  497. /**
  498. * Returns null if the recording is not supported, "on" if the recording started
  499. * and "off" if the recording is not started.
  500. */
  501. JitsiConference.prototype.getRecordingState = function () {
  502. if(this.room)
  503. return this.room.getRecordingState();
  504. return "off";
  505. }
  506. /**
  507. * Returns the url of the recorded video.
  508. */
  509. JitsiConference.prototype.getRecordingURL = function () {
  510. if(this.room)
  511. return this.room.getRecordingURL();
  512. return null;
  513. }
  514. /**
  515. * Starts/stops the recording
  516. * @param token a token for authentication.
  517. */
  518. JitsiConference.prototype.toggleRecording = function (token, followEntity) {
  519. if(this.room)
  520. return this.room.toggleRecording(token, followEntity);
  521. return new Promise(function(resolve, reject){
  522. reject(new Error("The conference is not created yet!"))});
  523. }
  524. /**
  525. * Returns true if the SIP calls are supported and false otherwise
  526. */
  527. JitsiConference.prototype.isSIPCallingSupported = function () {
  528. if(this.room)
  529. return this.room.isSIPCallingSupported();
  530. return false;
  531. }
  532. /**
  533. * Dials a number.
  534. * @param number the number
  535. */
  536. JitsiConference.prototype.dial = function (number) {
  537. if(this.room)
  538. return this.room.dial(number);
  539. return new Promise(function(resolve, reject){
  540. reject(new Error("The conference is not created yet!"))});
  541. }
  542. /**
  543. * Hangup an existing call
  544. */
  545. JitsiConference.prototype.hangup = function () {
  546. if(this.room)
  547. return this.room.hangup();
  548. return new Promise(function(resolve, reject){
  549. reject(new Error("The conference is not created yet!"))});
  550. }
  551. /**
  552. * Returns the phone number for joining the conference.
  553. */
  554. JitsiConference.prototype.getPhoneNumber = function () {
  555. if(this.room)
  556. return this.room.getPhoneNumber();
  557. return null;
  558. }
  559. /**
  560. * Returns the pin for joining the conference with phone.
  561. */
  562. JitsiConference.prototype.getPhonePin = function () {
  563. if(this.room)
  564. return this.room.getPhonePin();
  565. return null;
  566. }
  567. /**
  568. * Returns the connection state for the current room. Its ice connection state
  569. * for its session.
  570. */
  571. JitsiConference.prototype.getConnectionState = function () {
  572. if(this.room)
  573. return this.room.getConnectionState();
  574. return null;
  575. }
  576. /**
  577. * Setups the listeners needed for the conference.
  578. * @param conference the conference
  579. */
  580. function setupListeners(conference) {
  581. conference.xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
  582. conference.rtc.onIncommingCall(event);
  583. if(conference.statistics)
  584. conference.statistics.startRemoteStats(event.peerconnection);
  585. });
  586. conference.room.addListener(XMPPEvents.REMOTE_STREAM_RECEIVED,
  587. function (data, sid, thessrc) {
  588. var track = conference.rtc.createRemoteStream(data, sid, thessrc);
  589. if (track) {
  590. conference.onTrackAdded(track);
  591. }
  592. }
  593. );
  594. conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  595. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
  596. });
  597. conference.room.addListener(XMPPEvents.ROOM_JOIN_ERROR, function (pres) {
  598. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONNECTION_ERROR, pres);
  599. });
  600. conference.room.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function (pres) {
  601. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONNECTION_ERROR, pres);
  602. });
  603. conference.room.addListener(XMPPEvents.PASSWORD_REQUIRED, function (pres) {
  604. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.PASSWORD_REQUIRED, pres);
  605. });
  606. conference.room.addListener(XMPPEvents.AUTHENTICATION_REQUIRED, function () {
  607. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  608. });
  609. // FIXME
  610. // conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  611. // conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
  612. // });
  613. conference.room.addListener(XMPPEvents.KICKED, function () {
  614. conference.eventEmitter.emit(JitsiConferenceEvents.KICKED);
  615. });
  616. conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
  617. conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));
  618. conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
  619. conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
  620. conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
  621. });
  622. conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
  623. conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
  624. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
  625. });
  626. conference.room.addListener(XMPPEvents.RECORDING_STATE_CHANGED,
  627. function () {
  628. conference.eventEmitter.emit(
  629. JitsiConferenceEvents.RECORDING_STATE_CHANGED);
  630. });
  631. conference.room.addListener(XMPPEvents.PHONE_NUMBER_CHANGED, function () {
  632. conference.eventEmitter.emit(
  633. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  634. });
  635. conference.room.addListener(XMPPEvents.CONNECTION_RESTORED, function () {
  636. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_RESTORED);
  637. });
  638. conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
  639. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.SETUP_FAILED);
  640. });
  641. conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
  642. conference.authEnabled = authEnabled;
  643. conference.authIdentity = authIdentity;
  644. });
  645. conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
  646. var id = Strophe.getResourceFromJid(jid);
  647. conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
  648. });
  649. conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
  650. if(conference.lastActiveSpeaker !== id && conference.room) {
  651. conference.lastActiveSpeaker = id;
  652. conference.eventEmitter.emit(JitsiConferenceEvents.ACTIVE_SPEAKER_CHANGED, id);
  653. }
  654. });
  655. conference.rtc.addListener(RTCEvents.LASTN_CHANGED, function (oldValue, newValue) {
  656. conference.eventEmitter.emit(JitsiConferenceEvents.IN_LAST_N_CHANGED, oldValue, newValue);
  657. });
  658. conference.rtc.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  659. function (lastNEndpoints, endpointsEnteringLastN) {
  660. conference.eventEmitter.emit(JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  661. lastNEndpoints, endpointsEnteringLastN);
  662. });
  663. conference.xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, function () {
  664. conference.eventEmitter.emit(JitsiConferenceErrors.PASSWORD_REQUIRED);
  665. });
  666. if(conference.statistics) {
  667. //FIXME: Maybe remove event should not be associated with the conference.
  668. conference.statistics.addAudioLevelListener(function (ssrc, level) {
  669. var userId = null;
  670. var jid = conference.room.getJidBySSRC(ssrc);
  671. if (!jid)
  672. return;
  673. conference.rtc.setAudioLevel(jid, level);
  674. });
  675. conference.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,
  676. function () {
  677. conference.statistics.dispose();
  678. });
  679. // FIXME: Maybe we should move this.
  680. // RTC.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED, function (devices) {
  681. // conference.room.updateDeviceAvailability(devices);
  682. // });
  683. }
  684. }
  685. module.exports = JitsiConference;