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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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. var JitsiTrackErrors = require("./JitsiTrackErrors");
  16. var Settings = require("./modules/settings/Settings");
  17. var ComponentsVersions = require("./modules/version/ComponentsVersions");
  18. /**
  19. * Creates a JitsiConference object with the given name and properties.
  20. * Note: this constructor is not a part of the public API (objects should be
  21. * created using JitsiConnection.createConference).
  22. * @param options.config properties / settings related to the conference that will be created.
  23. * @param options.name the name of the conference
  24. * @param options.connection the JitsiConnection object for this JitsiConference.
  25. * @constructor
  26. */
  27. function JitsiConference(options) {
  28. if(!options.name || options.name.toLowerCase() !== options.name) {
  29. logger.error("Invalid conference name (no conference name passed or it"
  30. + "contains invalid characters like capital letters)!");
  31. return;
  32. }
  33. this.options = options;
  34. this.connection = this.options.connection;
  35. this.xmpp = this.connection.xmpp;
  36. this.eventEmitter = new EventEmitter();
  37. var confID = this.options.name + '@' + this.xmpp.options.hosts.muc;
  38. this.settings = new Settings();
  39. this.room = this.xmpp.createRoom(this.options.name, this.options.config,
  40. this.settings);
  41. this.componentsVersions = new ComponentsVersions(this.room);
  42. this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
  43. this.rtc = new RTC(this.room, options);
  44. this.statistics = new Statistics(this.xmpp, {
  45. callStatsID: this.options.config.callStatsID,
  46. callStatsSecret: this.options.config.callStatsSecret,
  47. disableThirdPartyRequests: this.options.config.disableThirdPartyRequests
  48. });
  49. setupListeners(this);
  50. var JitsiMeetJS = this.connection.JitsiMeetJS;
  51. JitsiMeetJS._gumFailedHandler.push(function(error) {
  52. this.statistics.sendGetUserMediaFailed(error);
  53. }.bind(this));
  54. JitsiMeetJS._globalOnErrorHandler.push(function(error) {
  55. this.statistics.sendUnhandledError(error);
  56. }.bind(this));
  57. this.participants = {};
  58. this.lastDominantSpeaker = null;
  59. this.dtmfManager = null;
  60. this.somebodySupportsDTMF = false;
  61. this.authEnabled = false;
  62. this.authIdentity;
  63. this.startAudioMuted = false;
  64. this.startVideoMuted = false;
  65. this.startMutedPolicy = {audio: false, video: false};
  66. this.availableDevices = {
  67. audio: undefined,
  68. video: undefined
  69. };
  70. this.isMutedByFocus = false;
  71. }
  72. /**
  73. * Joins the conference.
  74. * @param password {string} the password
  75. */
  76. JitsiConference.prototype.join = function (password) {
  77. if(this.room)
  78. this.room.join(password);
  79. };
  80. /**
  81. * Check if joined to the conference.
  82. */
  83. JitsiConference.prototype.isJoined = function () {
  84. return this.room && this.room.joined;
  85. };
  86. /**
  87. * Leaves the conference.
  88. * @returns {Promise}
  89. */
  90. JitsiConference.prototype.leave = function () {
  91. var conference = this;
  92. return Promise.all(
  93. conference.getLocalTracks().map(function (track) {
  94. return conference.removeTrack(track);
  95. })
  96. ).then(function () {
  97. // leave the conference
  98. if (conference.room) {
  99. conference.room.leave();
  100. }
  101. conference.room = null;
  102. // remove all participants
  103. conference.getParticipants().forEach(function (participant) {
  104. conference.onMemberLeft(participant.getJid());
  105. });
  106. });
  107. };
  108. /**
  109. * Returns name of this conference.
  110. */
  111. JitsiConference.prototype.getName = function () {
  112. return this.options.name;
  113. };
  114. /**
  115. * Check if authentication is enabled for this conference.
  116. */
  117. JitsiConference.prototype.isAuthEnabled = function () {
  118. return this.authEnabled;
  119. };
  120. /**
  121. * Check if user is logged in.
  122. */
  123. JitsiConference.prototype.isLoggedIn = function () {
  124. return !!this.authIdentity;
  125. };
  126. /**
  127. * Get authorized login.
  128. */
  129. JitsiConference.prototype.getAuthLogin = function () {
  130. return this.authIdentity;
  131. };
  132. /**
  133. * Check if external authentication is enabled for this conference.
  134. */
  135. JitsiConference.prototype.isExternalAuthEnabled = function () {
  136. return this.room && this.room.moderator.isExternalAuthEnabled();
  137. };
  138. /**
  139. * Get url for external authentication.
  140. * @param {boolean} [urlForPopup] if true then return url for login popup,
  141. * else url of login page.
  142. * @returns {Promise}
  143. */
  144. JitsiConference.prototype.getExternalAuthUrl = function (urlForPopup) {
  145. return new Promise(function (resolve, reject) {
  146. if (!this.isExternalAuthEnabled()) {
  147. reject();
  148. return;
  149. }
  150. if (urlForPopup) {
  151. this.room.moderator.getPopupLoginUrl(resolve, reject);
  152. } else {
  153. this.room.moderator.getLoginUrl(resolve, reject);
  154. }
  155. }.bind(this));
  156. };
  157. /**
  158. * Returns the local tracks.
  159. */
  160. JitsiConference.prototype.getLocalTracks = function () {
  161. if (this.rtc) {
  162. return this.rtc.localTracks.slice();
  163. } else {
  164. return [];
  165. }
  166. };
  167. /**
  168. * Attaches a handler for events(For example - "participant joined".) in the conference. All possible event are defined
  169. * in JitsiConferenceEvents.
  170. * @param eventId the event ID.
  171. * @param handler handler for the event.
  172. *
  173. * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
  174. */
  175. JitsiConference.prototype.on = function (eventId, handler) {
  176. if(this.eventEmitter)
  177. this.eventEmitter.on(eventId, handler);
  178. };
  179. /**
  180. * Removes event listener
  181. * @param eventId the event ID.
  182. * @param [handler] optional, the specific handler to unbind
  183. *
  184. * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
  185. */
  186. JitsiConference.prototype.off = function (eventId, handler) {
  187. if(this.eventEmitter)
  188. this.eventEmitter.removeListener(eventId, handler);
  189. };
  190. // Common aliases for event emitter
  191. JitsiConference.prototype.addEventListener = JitsiConference.prototype.on;
  192. JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
  193. /**
  194. * Receives notifications from other participants about commands / custom events
  195. * (sent by sendCommand or sendCommandOnce methods).
  196. * @param command {String} the name of the command
  197. * @param handler {Function} handler for the command
  198. */
  199. JitsiConference.prototype.addCommandListener = function (command, handler) {
  200. if(this.room)
  201. this.room.addPresenceListener(command, handler);
  202. };
  203. /**
  204. * Removes command listener
  205. * @param command {String} the name of the command
  206. */
  207. JitsiConference.prototype.removeCommandListener = function (command) {
  208. if(this.room)
  209. this.room.removePresenceListener(command);
  210. };
  211. /**
  212. * Sends text message to the other participants in the conference
  213. * @param message the text message.
  214. */
  215. JitsiConference.prototype.sendTextMessage = function (message) {
  216. if(this.room)
  217. this.room.sendMessage(message);
  218. };
  219. /**
  220. * Send presence command.
  221. * @param name {String} the name of the command.
  222. * @param values {Object} with keys and values that will be sent.
  223. **/
  224. JitsiConference.prototype.sendCommand = function (name, values) {
  225. if(this.room) {
  226. this.room.addToPresence(name, values);
  227. this.room.sendPresence();
  228. }
  229. };
  230. /**
  231. * Send presence command one time.
  232. * @param name {String} the name of the command.
  233. * @param values {Object} with keys and values that will be sent.
  234. **/
  235. JitsiConference.prototype.sendCommandOnce = function (name, values) {
  236. this.sendCommand(name, values);
  237. this.removeCommand(name);
  238. };
  239. /**
  240. * Removes presence command.
  241. * @param name {String} the name of the command.
  242. **/
  243. JitsiConference.prototype.removeCommand = function (name) {
  244. if(this.room)
  245. this.room.removeFromPresence(name);
  246. };
  247. /**
  248. * Sets the display name for this conference.
  249. * @param name the display name to set
  250. */
  251. JitsiConference.prototype.setDisplayName = function(name) {
  252. if(this.room){
  253. // remove previously set nickname
  254. this.room.removeFromPresence("nick");
  255. this.room.addToPresence("nick", {attributes: {xmlns: 'http://jabber.org/protocol/nick'}, value: name});
  256. this.room.sendPresence();
  257. }
  258. };
  259. /**
  260. * Set new subject for this conference. (available only for moderator)
  261. * @param {string} subject new subject
  262. */
  263. JitsiConference.prototype.setSubject = function (subject) {
  264. if (this.room && this.isModerator()) {
  265. this.room.setSubject(subject);
  266. }
  267. };
  268. /**
  269. * Adds JitsiLocalTrack object to the conference.
  270. * @param track the JitsiLocalTrack object.
  271. * @returns {Promise<JitsiLocalTrack>}
  272. * @throws will throw and error if track is video track
  273. * and there is already another video track in the conference.
  274. */
  275. JitsiConference.prototype.addTrack = function (track) {
  276. if(track.disposed)
  277. {
  278. throw new Error(JitsiTrackErrors.TRACK_IS_DISPOSED);
  279. }
  280. if (track.isVideoTrack()) {
  281. if (this.rtc.getLocalVideoTrack()) {
  282. throw new Error("cannot add second video track to the conference");
  283. }
  284. this.removeCommand("videoType");
  285. this.sendCommand("videoType", {
  286. value: track.videoType,
  287. attributes: {
  288. xmlns: 'http://jitsi.org/jitmeet/video'
  289. }
  290. });
  291. }
  292. track.ssrcHandler = function (conference, ssrcMap) {
  293. if(ssrcMap[this.getMSID()]){
  294. this._setSSRC(ssrcMap[this.getMSID()]);
  295. conference.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
  296. this.ssrcHandler);
  297. }
  298. }.bind(track, this);
  299. this.room.addListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
  300. track.ssrcHandler);
  301. return new Promise(function (resolve) {
  302. this.room.addStream(track.getOriginalStream(), function () {
  303. this.rtc.addLocalTrack(track);
  304. if (track.startMuted) {
  305. track.mute();
  306. }
  307. // ensure that we're sharing proper "is muted" state
  308. if (track.isAudioTrack()) {
  309. this.room.setAudioMute(track.isMuted());
  310. } else {
  311. this.room.setVideoMute(track.isMuted());
  312. }
  313. track.muteHandler = this._fireMuteChangeEvent.bind(this, track);
  314. track.audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
  315. track.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
  316. track.muteHandler);
  317. track.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  318. track.audioLevelHandler);
  319. //FIXME: This dependacy is not necessary. This is quick fix.
  320. track._setConference(this);
  321. // send event for starting screen sharing
  322. // FIXME: we assume we have only one screen sharing track
  323. // if we change this we need to fix this check
  324. if (track.isVideoTrack() && track.videoType === "desktop")
  325. this.statistics.sendScreenSharingEvent(true);
  326. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  327. resolve(track);
  328. }.bind(this));
  329. }.bind(this));
  330. };
  331. /**
  332. * Fires TRACK_AUDIO_LEVEL_CHANGED change conference event.
  333. * @param audioLevel the audio level
  334. */
  335. JitsiConference.prototype._fireAudioLevelChangeEvent = function (audioLevel) {
  336. this.eventEmitter.emit(
  337. JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  338. this.myUserId(), audioLevel);
  339. };
  340. /**
  341. * Fires TRACK_MUTE_CHANGED change conference event.
  342. * @param track the JitsiTrack object related to the event.
  343. */
  344. JitsiConference.prototype._fireMuteChangeEvent = function (track) {
  345. // check if track was muted by focus and now is unmuted by user
  346. if (this.isMutedByFocus && track.isAudioTrack() && !track.isMuted()) {
  347. this.isMutedByFocus = false;
  348. // unmute local user on server
  349. this.room.muteParticipant(this.room.myroomjid, false);
  350. }
  351. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  352. };
  353. /**
  354. * Removes JitsiLocalTrack object to the conference.
  355. * @param track the JitsiLocalTrack object.
  356. * @returns {Promise}
  357. */
  358. JitsiConference.prototype.removeTrack = function (track) {
  359. if(track.disposed)
  360. {
  361. throw new Error(JitsiTrackErrors.TRACK_IS_DISPOSED);
  362. }
  363. if(!this.room){
  364. if(this.rtc) {
  365. this.rtc.removeLocalTrack(track);
  366. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  367. }
  368. return Promise.resolve();
  369. }
  370. return new Promise(function (resolve) {
  371. this.room.removeStream(track.getOriginalStream(), function(){
  372. track._setSSRC(null);
  373. //FIXME: This dependacy is not necessary. This is quick fix.
  374. track._setConference(this);
  375. this.rtc.removeLocalTrack(track);
  376. track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
  377. track.muteHandler);
  378. track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  379. track.audioLevelHandler);
  380. this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
  381. track.ssrcHandler);
  382. // send event for stopping screen sharing
  383. // FIXME: we assume we have only one screen sharing track
  384. // if we change this we need to fix this check
  385. if (track.isVideoTrack() && track.videoType === "desktop")
  386. this.statistics.sendScreenSharingEvent(false);
  387. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  388. resolve();
  389. }.bind(this), {
  390. mtype: track.getType(),
  391. type: "remove",
  392. ssrc: track.ssrc});
  393. }.bind(this));
  394. };
  395. /**
  396. * Get role of the local user.
  397. * @returns {string} user role: 'moderator' or 'none'
  398. */
  399. JitsiConference.prototype.getRole = function () {
  400. return this.room.role;
  401. };
  402. /**
  403. * Check if local user is moderator.
  404. * @returns {boolean} true if local user is moderator, false otherwise.
  405. */
  406. JitsiConference.prototype.isModerator = function () {
  407. return this.room.isModerator();
  408. };
  409. /**
  410. * Set password for the room.
  411. * @param {string} password new password for the room.
  412. * @returns {Promise}
  413. */
  414. JitsiConference.prototype.lock = function (password) {
  415. if (!this.isModerator()) {
  416. return Promise.reject();
  417. }
  418. var conference = this;
  419. return new Promise(function (resolve, reject) {
  420. conference.room.lockRoom(password || "", function () {
  421. resolve();
  422. }, function (err) {
  423. reject(err);
  424. }, function () {
  425. reject(JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED);
  426. });
  427. });
  428. };
  429. /**
  430. * Remove password from the room.
  431. * @returns {Promise}
  432. */
  433. JitsiConference.prototype.unlock = function () {
  434. return this.lock();
  435. };
  436. /**
  437. * Elects the participant with the given id to be the selected participant or the speaker.
  438. * @param id the identifier of the participant
  439. */
  440. JitsiConference.prototype.selectParticipant = function(participantId) {
  441. if (this.rtc) {
  442. this.rtc.selectedEndpoint(participantId);
  443. }
  444. };
  445. /**
  446. *
  447. * @param id the identifier of the participant
  448. */
  449. JitsiConference.prototype.pinParticipant = function(participantId) {
  450. if (this.rtc) {
  451. this.rtc.pinEndpoint(participantId);
  452. }
  453. };
  454. /**
  455. * Returns the list of participants for this conference.
  456. * @return Array<JitsiParticipant> a list of participant identifiers containing all conference participants.
  457. */
  458. JitsiConference.prototype.getParticipants = function() {
  459. return Object.keys(this.participants).map(function (key) {
  460. return this.participants[key];
  461. }, this);
  462. };
  463. /**
  464. * @returns {JitsiParticipant} the participant in this conference with the specified id (or
  465. * undefined if there isn't one).
  466. * @param id the id of the participant.
  467. */
  468. JitsiConference.prototype.getParticipantById = function(id) {
  469. return this.participants[id];
  470. };
  471. /**
  472. * Kick participant from this conference.
  473. * @param {string} id id of the participant to kick
  474. */
  475. JitsiConference.prototype.kickParticipant = function (id) {
  476. var participant = this.getParticipantById(id);
  477. if (!participant) {
  478. return;
  479. }
  480. this.room.kick(participant.getJid());
  481. };
  482. /**
  483. * Kick participant from this conference.
  484. * @param {string} id id of the participant to kick
  485. */
  486. JitsiConference.prototype.muteParticipant = function (id) {
  487. var participant = this.getParticipantById(id);
  488. if (!participant) {
  489. return;
  490. }
  491. this.room.muteParticipant(participant.getJid(), true);
  492. };
  493. /**
  494. * Indicates that a participant has joined the conference.
  495. *
  496. * @param jid the jid of the participant in the MUC
  497. * @param nick the display name of the participant
  498. * @param role the role of the participant in the MUC
  499. * @param isHidden indicates if this is a hidden participant (sysem participant,
  500. * for example a recorder).
  501. */
  502. JitsiConference.prototype.onMemberJoined
  503. = function (jid, nick, role, isHidden) {
  504. var id = Strophe.getResourceFromJid(jid);
  505. if (id === 'focus' || this.myUserId() === id) {
  506. return;
  507. }
  508. var participant = new JitsiParticipant(jid, this, nick, isHidden);
  509. participant._role = role;
  510. this.participants[id] = participant;
  511. this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
  512. // XXX Since disco is checked in multiple places (e.g.
  513. // modules/xmpp/strophe.jingle.js, modules/xmpp/strophe.rayo.js), check it
  514. // here as well.
  515. var disco = this.xmpp.connection.disco;
  516. if (disco) {
  517. disco.info(
  518. jid, "node", function(iq) {
  519. participant._supportsDTMF = $(iq).find(
  520. '>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
  521. this.updateDTMFSupport();
  522. }.bind(this)
  523. );
  524. } else {
  525. // FIXME Should participant._supportsDTMF be assigned false here (and
  526. // this.updateDTMFSupport invoked)?
  527. }
  528. };
  529. JitsiConference.prototype.onMemberLeft = function (jid) {
  530. var id = Strophe.getResourceFromJid(jid);
  531. if (id === 'focus' || this.myUserId() === id) {
  532. return;
  533. }
  534. var participant = this.participants[id];
  535. delete this.participants[id];
  536. this.rtc.removeRemoteTracks(id);
  537. this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
  538. };
  539. JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
  540. var id = Strophe.getResourceFromJid(jid);
  541. var participant = this.getParticipantById(id);
  542. if (!participant) {
  543. return;
  544. }
  545. participant._role = role;
  546. this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
  547. };
  548. JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
  549. var id = Strophe.getResourceFromJid(jid);
  550. var participant = this.getParticipantById(id);
  551. if (!participant) {
  552. return;
  553. }
  554. if (participant._displayName === displayName)
  555. return;
  556. participant._displayName = displayName;
  557. this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
  558. };
  559. JitsiConference.prototype.onTrackAdded = function (track) {
  560. var id = track.getParticipantId();
  561. var participant = this.getParticipantById(id);
  562. if (!participant) {
  563. return;
  564. }
  565. // add track to JitsiParticipant
  566. participant._tracks.push(track);
  567. var emitter = this.eventEmitter;
  568. track.addEventListener(
  569. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  570. function () {
  571. emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  572. }
  573. );
  574. track.addEventListener(
  575. JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  576. function (audioLevel) {
  577. emitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, id, audioLevel);
  578. }
  579. );
  580. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  581. };
  582. JitsiConference.prototype.updateDTMFSupport = function () {
  583. var somebodySupportsDTMF = false;
  584. var participants = this.getParticipants();
  585. // check if at least 1 participant supports DTMF
  586. for (var i = 0; i < participants.length; i += 1) {
  587. if (participants[i].supportsDTMF()) {
  588. somebodySupportsDTMF = true;
  589. break;
  590. }
  591. }
  592. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  593. this.somebodySupportsDTMF = somebodySupportsDTMF;
  594. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  595. }
  596. };
  597. /**
  598. * Allows to check if there is at least one user in the conference
  599. * that supports DTMF.
  600. * @returns {boolean} true if somebody supports DTMF, false otherwise
  601. */
  602. JitsiConference.prototype.isDTMFSupported = function () {
  603. return this.somebodySupportsDTMF;
  604. };
  605. /**
  606. * Returns the local user's ID
  607. * @return {string} local user's ID
  608. */
  609. JitsiConference.prototype.myUserId = function () {
  610. return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  611. };
  612. JitsiConference.prototype.sendTones = function (tones, duration, pause) {
  613. if (!this.dtmfManager) {
  614. var connection = this.xmpp.connection.jingle.activecall.peerconnection;
  615. if (!connection) {
  616. logger.warn("cannot sendTones: no conneciton");
  617. return;
  618. }
  619. var tracks = this.getLocalTracks().filter(function (track) {
  620. return track.isAudioTrack();
  621. });
  622. if (!tracks.length) {
  623. logger.warn("cannot sendTones: no local audio stream");
  624. return;
  625. }
  626. this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
  627. }
  628. this.dtmfManager.sendTones(tones, duration, pause);
  629. };
  630. /**
  631. * Returns true if the recording is supproted and false if not.
  632. */
  633. JitsiConference.prototype.isRecordingSupported = function () {
  634. if(this.room)
  635. return this.room.isRecordingSupported();
  636. return false;
  637. };
  638. /**
  639. * Returns null if the recording is not supported, "on" if the recording started
  640. * and "off" if the recording is not started.
  641. */
  642. JitsiConference.prototype.getRecordingState = function () {
  643. return (this.room) ? this.room.getRecordingState() : undefined;
  644. }
  645. /**
  646. * Returns the url of the recorded video.
  647. */
  648. JitsiConference.prototype.getRecordingURL = function () {
  649. return (this.room) ? this.room.getRecordingURL() : null;
  650. }
  651. /**
  652. * Starts/stops the recording
  653. */
  654. JitsiConference.prototype.toggleRecording = function (options) {
  655. if(this.room)
  656. return this.room.toggleRecording(options, function (status, error) {
  657. this.eventEmitter.emit(
  658. JitsiConferenceEvents.RECORDER_STATE_CHANGED, status, error);
  659. }.bind(this));
  660. this.eventEmitter.emit(
  661. JitsiConferenceEvents.RECORDER_STATE_CHANGED, "error",
  662. new Error("The conference is not created yet!"));
  663. }
  664. /**
  665. * Returns true if the SIP calls are supported and false otherwise
  666. */
  667. JitsiConference.prototype.isSIPCallingSupported = function () {
  668. if(this.room)
  669. return this.room.isSIPCallingSupported();
  670. return false;
  671. }
  672. /**
  673. * Dials a number.
  674. * @param number the number
  675. */
  676. JitsiConference.prototype.dial = function (number) {
  677. if(this.room)
  678. return this.room.dial(number);
  679. return new Promise(function(resolve, reject){
  680. reject(new Error("The conference is not created yet!"))});
  681. }
  682. /**
  683. * Hangup an existing call
  684. */
  685. JitsiConference.prototype.hangup = function () {
  686. if(this.room)
  687. return this.room.hangup();
  688. return new Promise(function(resolve, reject){
  689. reject(new Error("The conference is not created yet!"))});
  690. }
  691. /**
  692. * Returns the phone number for joining the conference.
  693. */
  694. JitsiConference.prototype.getPhoneNumber = function () {
  695. if(this.room)
  696. return this.room.getPhoneNumber();
  697. return null;
  698. }
  699. /**
  700. * Returns the pin for joining the conference with phone.
  701. */
  702. JitsiConference.prototype.getPhonePin = function () {
  703. if(this.room)
  704. return this.room.getPhonePin();
  705. return null;
  706. }
  707. /**
  708. * Returns the connection state for the current room. Its ice connection state
  709. * for its session.
  710. */
  711. JitsiConference.prototype.getConnectionState = function () {
  712. if(this.room)
  713. return this.room.getConnectionState();
  714. return null;
  715. }
  716. /**
  717. * Make all new participants mute their audio/video on join.
  718. * @param policy {Object} object with 2 boolean properties for video and audio:
  719. * @param {boolean} audio if audio should be muted.
  720. * @param {boolean} video if video should be muted.
  721. */
  722. JitsiConference.prototype.setStartMutedPolicy = function (policy) {
  723. if (!this.isModerator()) {
  724. return;
  725. }
  726. this.startMutedPolicy = policy;
  727. this.room.removeFromPresence("startmuted");
  728. this.room.addToPresence("startmuted", {
  729. attributes: {
  730. audio: policy.audio,
  731. video: policy.video,
  732. xmlns: 'http://jitsi.org/jitmeet/start-muted'
  733. }
  734. });
  735. this.room.sendPresence();
  736. };
  737. /**
  738. * Returns current start muted policy
  739. * @returns {Object} with 2 proprties - audio and video.
  740. */
  741. JitsiConference.prototype.getStartMutedPolicy = function () {
  742. return this.startMutedPolicy;
  743. };
  744. /**
  745. * Check if audio is muted on join.
  746. */
  747. JitsiConference.prototype.isStartAudioMuted = function () {
  748. return this.startAudioMuted;
  749. };
  750. /**
  751. * Check if video is muted on join.
  752. */
  753. JitsiConference.prototype.isStartVideoMuted = function () {
  754. return this.startVideoMuted;
  755. };
  756. /**
  757. * Get object with internal logs.
  758. */
  759. JitsiConference.prototype.getLogs = function () {
  760. var data = this.xmpp.getJingleLog();
  761. var metadata = {};
  762. metadata.time = new Date();
  763. metadata.url = window.location.href;
  764. metadata.ua = navigator.userAgent;
  765. var log = this.xmpp.getXmppLog();
  766. if (log) {
  767. metadata.xmpp = log;
  768. }
  769. data.metadata = metadata;
  770. return data;
  771. };
  772. /**
  773. * Returns measured connectionTimes.
  774. */
  775. JitsiConference.prototype.getConnectionTimes = function () {
  776. return this.room.connectionTimes;
  777. };
  778. /**
  779. * Sends the given feedback through CallStats if enabled.
  780. *
  781. * @param overallFeedback an integer between 1 and 5 indicating the
  782. * user feedback
  783. * @param detailedFeedback detailed feedback from the user. Not yet used
  784. */
  785. JitsiConference.prototype.sendFeedback =
  786. function(overallFeedback, detailedFeedback){
  787. this.statistics.sendFeedback(overallFeedback, detailedFeedback);
  788. }
  789. /**
  790. * Returns true if the callstats integration is enabled, otherwise returns
  791. * false.
  792. *
  793. * @returns true if the callstats integration is enabled, otherwise returns
  794. * false.
  795. */
  796. JitsiConference.prototype.isCallstatsEnabled = function () {
  797. return this.statistics.isCallstatsEnabled();
  798. }
  799. /**
  800. * Setups the listeners needed for the conference.
  801. * @param conference the conference
  802. */
  803. function setupListeners(conference) {
  804. conference.xmpp.addListener(
  805. XMPPEvents.CALL_INCOMING, function (jingleSession, jingleOffer, now) {
  806. if (conference.room.isFocus(jingleSession.peerjid)) {
  807. // Accept incoming call
  808. conference.room.setJingleSession(jingleSession);
  809. conference.room.connectionTimes["session.initiate"] = now;
  810. jingleSession.initialize(false /* initiator */, conference.room);
  811. conference.rtc.onIncommingCall(jingleSession);
  812. jingleSession.acceptOffer(jingleOffer, null,
  813. function (error) {
  814. console.error(
  815. "Failed to accept incoming Jingle session", error);
  816. }
  817. );
  818. conference.statistics.startRemoteStats(
  819. jingleSession.peerconnection);
  820. } else {
  821. // Error cause this should never happen unless something is wrong !
  822. logger.error(
  823. "Rejecting session-initiate from non focus user: "
  824. + jingleSession.peerjid);
  825. }
  826. });
  827. conference.room.addListener(XMPPEvents.REMOTE_TRACK_ADDED,
  828. function (data) {
  829. var track = conference.rtc.createRemoteTrack(data);
  830. if (track) {
  831. conference.onTrackAdded(track);
  832. }
  833. }
  834. );
  835. conference.room.addListener(XMPPEvents.REMOTE_TRACK_REMOVED,
  836. function (streamId, trackId) {
  837. conference.getParticipants().forEach(function(participant) {
  838. var tracks = participant.getTracks();
  839. for(var i = 0; i < tracks.length; i++) {
  840. if(tracks[i]
  841. && tracks[i].getStreamId() == streamId
  842. && tracks[i].getTrackId() == trackId) {
  843. var track = participant._tracks.splice(i, 1)[0];
  844. conference.eventEmitter.emit(
  845. JitsiConferenceEvents.TRACK_REMOVED, track);
  846. return;
  847. }
  848. }
  849. });
  850. }
  851. );
  852. conference.rtc.addListener(RTCEvents.FAKE_VIDEO_TRACK_CREATED,
  853. function (track) {
  854. conference.onTrackAdded(track);
  855. }
  856. );
  857. conference.room.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
  858. function (value) {
  859. // set isMutedByFocus when setAudioMute Promise ends
  860. conference.rtc.setAudioMute(value).then(
  861. function() {
  862. conference.isMutedByFocus = true;
  863. },
  864. function() {
  865. logger.warn(
  866. "Error while audio muting due to focus request");
  867. });
  868. }
  869. );
  870. conference.room.addListener(XMPPEvents.SUBJECT_CHANGED, function (subject) {
  871. conference.eventEmitter.emit(JitsiConferenceEvents.SUBJECT_CHANGED,
  872. subject);
  873. });
  874. conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  875. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
  876. });
  877. conference.room.addListener(XMPPEvents.ROOM_JOIN_ERROR, function (pres) {
  878. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  879. JitsiConferenceErrors.CONNECTION_ERROR, pres);
  880. });
  881. conference.room.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function (pres) {
  882. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  883. JitsiConferenceErrors.CONNECTION_ERROR, pres);
  884. });
  885. conference.room.addListener(XMPPEvents.ROOM_MAX_USERS_ERROR,
  886. function (pres) {
  887. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  888. JitsiConferenceErrors.CONFERENCE_MAX_USERS, pres);
  889. });
  890. conference.room.addListener(XMPPEvents.PASSWORD_REQUIRED, function (pres) {
  891. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.PASSWORD_REQUIRED, pres);
  892. });
  893. conference.room.addListener(XMPPEvents.AUTHENTICATION_REQUIRED, function () {
  894. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  895. });
  896. conference.room.addListener(XMPPEvents.BRIDGE_DOWN, function () {
  897. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  898. });
  899. conference.room.addListener(XMPPEvents.RESERVATION_ERROR, function (code, msg) {
  900. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.RESERVATION_ERROR, code, msg);
  901. });
  902. conference.room.addListener(XMPPEvents.GRACEFUL_SHUTDOWN, function () {
  903. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.GRACEFUL_SHUTDOWN);
  904. });
  905. conference.room.addListener(XMPPEvents.JINGLE_FATAL_ERROR, function () {
  906. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.JINGLE_FATAL_ERROR);
  907. });
  908. conference.room.addListener(XMPPEvents.MUC_DESTROYED, function (reason) {
  909. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONFERENCE_DESTROYED, reason);
  910. });
  911. conference.room.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, function (err, msg) {
  912. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_ERROR, JitsiConferenceErrors.CHAT_ERROR, err, msg);
  913. });
  914. conference.room.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focus, retrySec) {
  915. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.FOCUS_DISCONNECTED, focus, retrySec);
  916. });
  917. conference.room.addListener(XMPPEvents.FOCUS_LEFT, function () {
  918. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.FOCUS_LEFT);
  919. });
  920. // FIXME
  921. // conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  922. // conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
  923. // });
  924. conference.room.addListener(XMPPEvents.KICKED, function () {
  925. conference.eventEmitter.emit(JitsiConferenceEvents.KICKED);
  926. });
  927. conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
  928. conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));
  929. conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
  930. conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
  931. conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
  932. });
  933. conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
  934. conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
  935. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
  936. });
  937. conference.room.addListener(XMPPEvents.RECORDER_STATE_CHANGED,
  938. function (state) {
  939. conference.eventEmitter.emit(
  940. JitsiConferenceEvents.RECORDER_STATE_CHANGED, state);
  941. });
  942. conference.room.addListener(XMPPEvents.PHONE_NUMBER_CHANGED, function () {
  943. conference.eventEmitter.emit(
  944. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  945. });
  946. conference.room.addListener(XMPPEvents.CONNECTION_RESTORED, function () {
  947. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_RESTORED);
  948. });
  949. conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
  950. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.SETUP_FAILED);
  951. });
  952. conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
  953. conference.authEnabled = authEnabled;
  954. conference.authIdentity = authIdentity;
  955. conference.eventEmitter.emit(JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled, authIdentity);
  956. });
  957. conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
  958. var id = Strophe.getResourceFromJid(jid);
  959. conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
  960. });
  961. conference.room.addListener(XMPPEvents.PRESENCE_STATUS, function (jid, status) {
  962. var id = Strophe.getResourceFromJid(jid);
  963. var participant = conference.getParticipantById(id);
  964. if (!participant || participant._status === status) {
  965. return;
  966. }
  967. participant._status = status;
  968. conference.eventEmitter.emit(JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  969. });
  970. conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
  971. if(conference.lastDominantSpeaker !== id && conference.room) {
  972. conference.lastDominantSpeaker = id;
  973. conference.eventEmitter.emit(JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  974. }
  975. if (conference.statistics && conference.myUserId() === id) {
  976. // We are the new dominant speaker.
  977. conference.statistics.sendDominantSpeakerEvent();
  978. }
  979. });
  980. conference.rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, function () {
  981. var now = window.performance.now();
  982. logger.log("(TIME) data channel opened ", now);
  983. conference.room.connectionTimes["data.channel.opened"] = now;
  984. });
  985. conference.rtc.addListener(RTCEvents.LASTN_CHANGED, function (oldValue, newValue) {
  986. conference.eventEmitter.emit(JitsiConferenceEvents.IN_LAST_N_CHANGED, oldValue, newValue);
  987. });
  988. conference.rtc.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  989. function (lastNEndpoints, endpointsEnteringLastN) {
  990. conference.eventEmitter.emit(JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  991. lastNEndpoints, endpointsEnteringLastN);
  992. });
  993. conference.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  994. function (audioMuted, videoMuted) {
  995. conference.startAudioMuted = audioMuted;
  996. conference.startVideoMuted = videoMuted;
  997. // mute existing local tracks because this is initial mute from
  998. // Jicofo
  999. conference.getLocalTracks().forEach(function (track) {
  1000. if (conference.startAudioMuted && track.isAudioTrack()) {
  1001. track.mute();
  1002. }
  1003. if (conference.startVideoMuted && track.isVideoTrack()) {
  1004. track.mute();
  1005. }
  1006. });
  1007. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  1008. });
  1009. conference.room.addPresenceListener("startmuted", function (data, from) {
  1010. var isModerator = false;
  1011. if (conference.myUserId() === from && conference.isModerator()) {
  1012. isModerator = true;
  1013. } else {
  1014. var participant = conference.getParticipantById(from);
  1015. if (participant && participant.isModerator()) {
  1016. isModerator = true;
  1017. }
  1018. }
  1019. if (!isModerator) {
  1020. return;
  1021. }
  1022. var startAudioMuted = data.attributes.audio === 'true';
  1023. var startVideoMuted = data.attributes.video === 'true';
  1024. var updated = false;
  1025. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  1026. conference.startMutedPolicy.audio = startAudioMuted;
  1027. updated = true;
  1028. }
  1029. if (startVideoMuted !== conference.startMutedPolicy.video) {
  1030. conference.startMutedPolicy.video = startVideoMuted;
  1031. updated = true;
  1032. }
  1033. if (updated) {
  1034. conference.eventEmitter.emit(
  1035. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  1036. conference.startMutedPolicy
  1037. );
  1038. }
  1039. });
  1040. conference.rtc.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED, function (devices) {
  1041. conference.room.updateDeviceAvailability(devices);
  1042. });
  1043. conference.room.addPresenceListener("devices", function (data, from) {
  1044. var isAudioAvailable = false;
  1045. var isVideoAvailable = false;
  1046. data.children.forEach(function (config) {
  1047. if (config.tagName === 'audio') {
  1048. isAudioAvailable = config.value === 'true';
  1049. }
  1050. if (config.tagName === 'video') {
  1051. isVideoAvailable = config.value === 'true';
  1052. }
  1053. });
  1054. var availableDevices;
  1055. if (conference.myUserId() === from) {
  1056. availableDevices = conference.availableDevices;
  1057. } else {
  1058. var participant = conference.getParticipantById(from);
  1059. if (!participant) {
  1060. return;
  1061. }
  1062. availableDevices = participant._availableDevices;
  1063. }
  1064. var updated = false;
  1065. if (availableDevices.audio !== isAudioAvailable) {
  1066. updated = true;
  1067. availableDevices.audio = isAudioAvailable;
  1068. }
  1069. if (availableDevices.video !== isVideoAvailable) {
  1070. updated = true;
  1071. availableDevices.video = isVideoAvailable;
  1072. }
  1073. if (updated) {
  1074. conference.eventEmitter.emit(
  1075. JitsiConferenceEvents.AVAILABLE_DEVICES_CHANGED,
  1076. from, availableDevices);
  1077. }
  1078. });
  1079. if(conference.statistics) {
  1080. //FIXME: Maybe remove event should not be associated with the conference.
  1081. conference.statistics.addAudioLevelListener(function (ssrc, level) {
  1082. var userId = null;
  1083. var resource = conference.rtc.getResourceBySSRC(ssrc);
  1084. if (!resource)
  1085. return;
  1086. conference.rtc.setAudioLevel(resource, level);
  1087. });
  1088. conference.statistics.addConnectionStatsListener(function (stats) {
  1089. var ssrc2resolution = stats.resolution;
  1090. var id2resolution = {};
  1091. // preprocess resolutions: group by user id, skip incorrect
  1092. // resolutions etc.
  1093. Object.keys(ssrc2resolution).forEach(function (ssrc) {
  1094. var resolution = ssrc2resolution[ssrc];
  1095. if (!resolution.width || !resolution.height ||
  1096. resolution.width == -1 || resolution.height == -1) {
  1097. return;
  1098. }
  1099. var id = conference.rtc.getResourceBySSRC(ssrc);
  1100. if (!id) {
  1101. return;
  1102. }
  1103. // ssrc to resolution map for user id
  1104. var idResolutions = id2resolution[id] || {};
  1105. idResolutions[ssrc] = resolution;
  1106. id2resolution[id] = idResolutions;
  1107. });
  1108. stats.resolution = id2resolution;
  1109. conference.eventEmitter.emit(
  1110. JitsiConferenceEvents.CONNECTION_STATS, stats);
  1111. });
  1112. conference.room.addListener(XMPPEvents.DISPOSE_CONFERENCE,
  1113. function () {
  1114. conference.statistics.dispose();
  1115. });
  1116. conference.room.addListener(XMPPEvents.PEERCONNECTION_READY,
  1117. function (session) {
  1118. conference.statistics.startCallStats(
  1119. session, conference.settings);
  1120. });
  1121. conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED,
  1122. function () {
  1123. conference.statistics.sendSetupFailedEvent();
  1124. });
  1125. conference.rtc.addListener(RTCEvents.TRACK_ATTACHED,
  1126. function(track, container) {
  1127. var ssrc = track.getSSRC();
  1128. if (!container.id || !ssrc) {
  1129. return;
  1130. }
  1131. conference.statistics.associateStreamWithVideoTag(
  1132. ssrc, track.isLocal(), track.getUsageLabel(), container.id);
  1133. });
  1134. conference.on(JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  1135. function (track) {
  1136. if(!track.isLocal())
  1137. return;
  1138. var type = (track.getType() === "audio")? "audio" : "video";
  1139. conference.statistics.sendMuteEvent(track.isMuted(), type);
  1140. });
  1141. conference.room.addListener(XMPPEvents.CREATE_OFFER_FAILED, function (e, pc) {
  1142. conference.statistics.sendCreateOfferFailed(e, pc);
  1143. });
  1144. conference.room.addListener(XMPPEvents.CREATE_ANSWER_FAILED, function (e, pc) {
  1145. conference.statistics.sendCreateAnswerFailed(e, pc);
  1146. });
  1147. conference.room.addListener(XMPPEvents.SET_LOCAL_DESCRIPTION_FAILED,
  1148. function (e, pc) {
  1149. conference.statistics.sendSetLocalDescFailed(e, pc);
  1150. }
  1151. );
  1152. conference.room.addListener(XMPPEvents.SET_REMOTE_DESCRIPTION_FAILED,
  1153. function (e, pc) {
  1154. conference.statistics.sendSetRemoteDescFailed(e, pc);
  1155. }
  1156. );
  1157. conference.room.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  1158. function (e, pc) {
  1159. conference.statistics.sendAddIceCandidateFailed(e, pc);
  1160. }
  1161. );
  1162. }
  1163. }
  1164. module.exports = JitsiConference;