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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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. this.xmpp.connection.disco.info(
  513. jid, "node", function(iq) {
  514. participant._supportsDTMF = $(iq).find(
  515. '>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
  516. this.updateDTMFSupport();
  517. }.bind(this)
  518. );
  519. };
  520. JitsiConference.prototype.onMemberLeft = function (jid) {
  521. var id = Strophe.getResourceFromJid(jid);
  522. if (id === 'focus' || this.myUserId() === id) {
  523. return;
  524. }
  525. var participant = this.participants[id];
  526. delete this.participants[id];
  527. this.rtc.removeRemoteTracks(id);
  528. this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
  529. };
  530. JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
  531. var id = Strophe.getResourceFromJid(jid);
  532. var participant = this.getParticipantById(id);
  533. if (!participant) {
  534. return;
  535. }
  536. participant._role = role;
  537. this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
  538. };
  539. JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
  540. var id = Strophe.getResourceFromJid(jid);
  541. var participant = this.getParticipantById(id);
  542. if (!participant) {
  543. return;
  544. }
  545. if (participant._displayName === displayName)
  546. return;
  547. participant._displayName = displayName;
  548. this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
  549. };
  550. JitsiConference.prototype.onTrackAdded = function (track) {
  551. var id = track.getParticipantId();
  552. var participant = this.getParticipantById(id);
  553. if (!participant) {
  554. return;
  555. }
  556. // add track to JitsiParticipant
  557. participant._tracks.push(track);
  558. var emitter = this.eventEmitter;
  559. track.addEventListener(
  560. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  561. function () {
  562. emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  563. }
  564. );
  565. track.addEventListener(
  566. JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  567. function (audioLevel) {
  568. emitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, id, audioLevel);
  569. }
  570. );
  571. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  572. };
  573. JitsiConference.prototype.updateDTMFSupport = function () {
  574. var somebodySupportsDTMF = false;
  575. var participants = this.getParticipants();
  576. // check if at least 1 participant supports DTMF
  577. for (var i = 0; i < participants.length; i += 1) {
  578. if (participants[i].supportsDTMF()) {
  579. somebodySupportsDTMF = true;
  580. break;
  581. }
  582. }
  583. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  584. this.somebodySupportsDTMF = somebodySupportsDTMF;
  585. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  586. }
  587. };
  588. /**
  589. * Allows to check if there is at least one user in the conference
  590. * that supports DTMF.
  591. * @returns {boolean} true if somebody supports DTMF, false otherwise
  592. */
  593. JitsiConference.prototype.isDTMFSupported = function () {
  594. return this.somebodySupportsDTMF;
  595. };
  596. /**
  597. * Returns the local user's ID
  598. * @return {string} local user's ID
  599. */
  600. JitsiConference.prototype.myUserId = function () {
  601. return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  602. };
  603. JitsiConference.prototype.sendTones = function (tones, duration, pause) {
  604. if (!this.dtmfManager) {
  605. var connection = this.xmpp.connection.jingle.activecall.peerconnection;
  606. if (!connection) {
  607. logger.warn("cannot sendTones: no conneciton");
  608. return;
  609. }
  610. var tracks = this.getLocalTracks().filter(function (track) {
  611. return track.isAudioTrack();
  612. });
  613. if (!tracks.length) {
  614. logger.warn("cannot sendTones: no local audio stream");
  615. return;
  616. }
  617. this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
  618. }
  619. this.dtmfManager.sendTones(tones, duration, pause);
  620. };
  621. /**
  622. * Returns true if the recording is supproted and false if not.
  623. */
  624. JitsiConference.prototype.isRecordingSupported = function () {
  625. if(this.room)
  626. return this.room.isRecordingSupported();
  627. return false;
  628. };
  629. /**
  630. * Returns null if the recording is not supported, "on" if the recording started
  631. * and "off" if the recording is not started.
  632. */
  633. JitsiConference.prototype.getRecordingState = function () {
  634. if(this.room)
  635. return this.room.getRecordingState();
  636. return Recording.status.OFF;
  637. }
  638. /**
  639. * Returns the url of the recorded video.
  640. */
  641. JitsiConference.prototype.getRecordingURL = function () {
  642. if(this.room)
  643. return this.room.getRecordingURL();
  644. return null;
  645. }
  646. /**
  647. * Starts/stops the recording
  648. */
  649. JitsiConference.prototype.toggleRecording = function (options) {
  650. if(this.room)
  651. return this.room.toggleRecording(options, function (status, error) {
  652. this.eventEmitter.emit(
  653. JitsiConferenceEvents.RECORDER_STATE_CHANGED, status, error);
  654. }.bind(this));
  655. this.eventEmitter.emit(
  656. JitsiConferenceEvents.RECORDER_STATE_CHANGED, "error",
  657. new Error("The conference is not created yet!"));
  658. }
  659. /**
  660. * Returns true if the SIP calls are supported and false otherwise
  661. */
  662. JitsiConference.prototype.isSIPCallingSupported = function () {
  663. if(this.room)
  664. return this.room.isSIPCallingSupported();
  665. return false;
  666. }
  667. /**
  668. * Dials a number.
  669. * @param number the number
  670. */
  671. JitsiConference.prototype.dial = function (number) {
  672. if(this.room)
  673. return this.room.dial(number);
  674. return new Promise(function(resolve, reject){
  675. reject(new Error("The conference is not created yet!"))});
  676. }
  677. /**
  678. * Hangup an existing call
  679. */
  680. JitsiConference.prototype.hangup = function () {
  681. if(this.room)
  682. return this.room.hangup();
  683. return new Promise(function(resolve, reject){
  684. reject(new Error("The conference is not created yet!"))});
  685. }
  686. /**
  687. * Returns the phone number for joining the conference.
  688. */
  689. JitsiConference.prototype.getPhoneNumber = function () {
  690. if(this.room)
  691. return this.room.getPhoneNumber();
  692. return null;
  693. }
  694. /**
  695. * Returns the pin for joining the conference with phone.
  696. */
  697. JitsiConference.prototype.getPhonePin = function () {
  698. if(this.room)
  699. return this.room.getPhonePin();
  700. return null;
  701. }
  702. /**
  703. * Returns the connection state for the current room. Its ice connection state
  704. * for its session.
  705. */
  706. JitsiConference.prototype.getConnectionState = function () {
  707. if(this.room)
  708. return this.room.getConnectionState();
  709. return null;
  710. }
  711. /**
  712. * Make all new participants mute their audio/video on join.
  713. * @param policy {Object} object with 2 boolean properties for video and audio:
  714. * @param {boolean} audio if audio should be muted.
  715. * @param {boolean} video if video should be muted.
  716. */
  717. JitsiConference.prototype.setStartMutedPolicy = function (policy) {
  718. if (!this.isModerator()) {
  719. return;
  720. }
  721. this.startMutedPolicy = policy;
  722. this.room.removeFromPresence("startmuted");
  723. this.room.addToPresence("startmuted", {
  724. attributes: {
  725. audio: policy.audio,
  726. video: policy.video,
  727. xmlns: 'http://jitsi.org/jitmeet/start-muted'
  728. }
  729. });
  730. this.room.sendPresence();
  731. };
  732. /**
  733. * Returns current start muted policy
  734. * @returns {Object} with 2 proprties - audio and video.
  735. */
  736. JitsiConference.prototype.getStartMutedPolicy = function () {
  737. return this.startMutedPolicy;
  738. };
  739. /**
  740. * Check if audio is muted on join.
  741. */
  742. JitsiConference.prototype.isStartAudioMuted = function () {
  743. return this.startAudioMuted;
  744. };
  745. /**
  746. * Check if video is muted on join.
  747. */
  748. JitsiConference.prototype.isStartVideoMuted = function () {
  749. return this.startVideoMuted;
  750. };
  751. /**
  752. * Get object with internal logs.
  753. */
  754. JitsiConference.prototype.getLogs = function () {
  755. var data = this.xmpp.getJingleLog();
  756. var metadata = {};
  757. metadata.time = new Date();
  758. metadata.url = window.location.href;
  759. metadata.ua = navigator.userAgent;
  760. var log = this.xmpp.getXmppLog();
  761. if (log) {
  762. metadata.xmpp = log;
  763. }
  764. data.metadata = metadata;
  765. return data;
  766. };
  767. /**
  768. * Returns measured connectionTimes.
  769. */
  770. JitsiConference.prototype.getConnectionTimes = function () {
  771. return this.room.connectionTimes;
  772. };
  773. /**
  774. * Sends the given feedback through CallStats if enabled.
  775. *
  776. * @param overallFeedback an integer between 1 and 5 indicating the
  777. * user feedback
  778. * @param detailedFeedback detailed feedback from the user. Not yet used
  779. */
  780. JitsiConference.prototype.sendFeedback =
  781. function(overallFeedback, detailedFeedback){
  782. this.statistics.sendFeedback(overallFeedback, detailedFeedback);
  783. }
  784. /**
  785. * Returns true if the callstats integration is enabled, otherwise returns
  786. * false.
  787. *
  788. * @returns true if the callstats integration is enabled, otherwise returns
  789. * false.
  790. */
  791. JitsiConference.prototype.isCallstatsEnabled = function () {
  792. return this.statistics.isCallstatsEnabled();
  793. }
  794. /**
  795. * Setups the listeners needed for the conference.
  796. * @param conference the conference
  797. */
  798. function setupListeners(conference) {
  799. conference.xmpp.addListener(
  800. XMPPEvents.CALL_INCOMING, function (jingleSession, jingleOffer, now) {
  801. if (conference.room.isFocus(jingleSession.peerjid)) {
  802. // Accept incoming call
  803. conference.room.setJingleSession(jingleSession);
  804. conference.room.connectionTimes["session.initiate"] = now;
  805. jingleSession.initialize(false /* initiator */, conference.room);
  806. conference.rtc.onIncommingCall(jingleSession);
  807. jingleSession.acceptOffer(jingleOffer, null,
  808. function (error) {
  809. console.error(
  810. "Failed to accept incoming Jingle session", error);
  811. }
  812. );
  813. conference.statistics.startRemoteStats(
  814. jingleSession.peerconnection);
  815. } else {
  816. // Error cause this should never happen unless something is wrong !
  817. logger.error(
  818. "Rejecting session-initiate from non focus user: "
  819. + jingleSession.peerjid);
  820. }
  821. });
  822. conference.room.addListener(XMPPEvents.REMOTE_TRACK_ADDED,
  823. function (data) {
  824. var track = conference.rtc.createRemoteTrack(data);
  825. if (track) {
  826. conference.onTrackAdded(track);
  827. }
  828. }
  829. );
  830. conference.room.addListener(XMPPEvents.REMOTE_TRACK_REMOVED,
  831. function (streamId, trackId) {
  832. conference.getParticipants().forEach(function(participant) {
  833. var tracks = participant.getTracks();
  834. for(var i = 0; i < tracks.length; i++) {
  835. if(tracks[i]
  836. && tracks[i].getStreamId() == streamId
  837. && tracks[i].getTrackId() == trackId) {
  838. var track = participant._tracks.splice(i, 1)[0];
  839. conference.eventEmitter.emit(
  840. JitsiConferenceEvents.TRACK_REMOVED, track);
  841. return;
  842. }
  843. }
  844. });
  845. }
  846. );
  847. conference.rtc.addListener(RTCEvents.FAKE_VIDEO_TRACK_CREATED,
  848. function (track) {
  849. conference.onTrackAdded(track);
  850. }
  851. );
  852. conference.room.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
  853. function (value) {
  854. // set isMutedByFocus when setAudioMute Promise ends
  855. conference.rtc.setAudioMute(value).then(
  856. function() {
  857. conference.isMutedByFocus = true;
  858. },
  859. function() {
  860. logger.warn(
  861. "Error while audio muting due to focus request");
  862. });
  863. }
  864. );
  865. conference.room.addListener(XMPPEvents.SUBJECT_CHANGED, function (subject) {
  866. conference.eventEmitter.emit(JitsiConferenceEvents.SUBJECT_CHANGED,
  867. subject);
  868. });
  869. conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  870. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
  871. });
  872. conference.room.addListener(XMPPEvents.ROOM_JOIN_ERROR, function (pres) {
  873. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  874. JitsiConferenceErrors.CONNECTION_ERROR, pres);
  875. });
  876. conference.room.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function (pres) {
  877. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  878. JitsiConferenceErrors.CONNECTION_ERROR, pres);
  879. });
  880. conference.room.addListener(XMPPEvents.ROOM_MAX_USERS_ERROR,
  881. function (pres) {
  882. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  883. JitsiConferenceErrors.CONFERENCE_MAX_USERS, pres);
  884. });
  885. conference.room.addListener(XMPPEvents.PASSWORD_REQUIRED, function (pres) {
  886. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.PASSWORD_REQUIRED, pres);
  887. });
  888. conference.room.addListener(XMPPEvents.AUTHENTICATION_REQUIRED, function () {
  889. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  890. });
  891. conference.room.addListener(XMPPEvents.BRIDGE_DOWN, function () {
  892. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  893. });
  894. conference.room.addListener(XMPPEvents.RESERVATION_ERROR, function (code, msg) {
  895. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.RESERVATION_ERROR, code, msg);
  896. });
  897. conference.room.addListener(XMPPEvents.GRACEFUL_SHUTDOWN, function () {
  898. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.GRACEFUL_SHUTDOWN);
  899. });
  900. conference.room.addListener(XMPPEvents.JINGLE_FATAL_ERROR, function () {
  901. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.JINGLE_FATAL_ERROR);
  902. });
  903. conference.room.addListener(XMPPEvents.MUC_DESTROYED, function (reason) {
  904. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONFERENCE_DESTROYED, reason);
  905. });
  906. conference.room.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, function (err, msg) {
  907. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_ERROR, JitsiConferenceErrors.CHAT_ERROR, err, msg);
  908. });
  909. conference.room.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focus, retrySec) {
  910. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.FOCUS_DISCONNECTED, focus, retrySec);
  911. });
  912. conference.room.addListener(XMPPEvents.FOCUS_LEFT, function () {
  913. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.FOCUS_LEFT);
  914. });
  915. // FIXME
  916. // conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  917. // conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
  918. // });
  919. conference.room.addListener(XMPPEvents.KICKED, function () {
  920. conference.eventEmitter.emit(JitsiConferenceEvents.KICKED);
  921. });
  922. conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
  923. conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));
  924. conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
  925. conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
  926. conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
  927. });
  928. conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
  929. conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
  930. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
  931. });
  932. conference.room.addListener(XMPPEvents.RECORDER_STATE_CHANGED,
  933. function (state) {
  934. conference.eventEmitter.emit(
  935. JitsiConferenceEvents.RECORDER_STATE_CHANGED, state);
  936. });
  937. conference.room.addListener(XMPPEvents.PHONE_NUMBER_CHANGED, function () {
  938. conference.eventEmitter.emit(
  939. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  940. });
  941. conference.room.addListener(XMPPEvents.CONNECTION_RESTORED, function () {
  942. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_RESTORED);
  943. });
  944. conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
  945. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.SETUP_FAILED);
  946. });
  947. conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
  948. conference.authEnabled = authEnabled;
  949. conference.authIdentity = authIdentity;
  950. conference.eventEmitter.emit(JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled, authIdentity);
  951. });
  952. conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
  953. var id = Strophe.getResourceFromJid(jid);
  954. conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
  955. });
  956. conference.room.addListener(XMPPEvents.PRESENCE_STATUS, function (jid, status) {
  957. var id = Strophe.getResourceFromJid(jid);
  958. var participant = conference.getParticipantById(id);
  959. if (!participant || participant._status === status) {
  960. return;
  961. }
  962. participant._status = status;
  963. conference.eventEmitter.emit(JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  964. });
  965. conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
  966. if(conference.lastDominantSpeaker !== id && conference.room) {
  967. conference.lastDominantSpeaker = id;
  968. conference.eventEmitter.emit(JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  969. }
  970. if (conference.statistics && conference.myUserId() === id) {
  971. // We are the new dominant speaker.
  972. conference.statistics.sendDominantSpeakerEvent();
  973. }
  974. });
  975. conference.rtc.addListener(RTCEvents.DATA_CHANNEL_OPEN, function () {
  976. var now = window.performance.now();
  977. logger.log("(TIME) data channel opened ", now);
  978. conference.room.connectionTimes["data.channel.opened"] = now;
  979. });
  980. conference.rtc.addListener(RTCEvents.LASTN_CHANGED, function (oldValue, newValue) {
  981. conference.eventEmitter.emit(JitsiConferenceEvents.IN_LAST_N_CHANGED, oldValue, newValue);
  982. });
  983. conference.rtc.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  984. function (lastNEndpoints, endpointsEnteringLastN) {
  985. conference.eventEmitter.emit(JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  986. lastNEndpoints, endpointsEnteringLastN);
  987. });
  988. conference.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  989. function (audioMuted, videoMuted) {
  990. conference.startAudioMuted = audioMuted;
  991. conference.startVideoMuted = videoMuted;
  992. // mute existing local tracks because this is initial mute from
  993. // Jicofo
  994. conference.getLocalTracks().forEach(function (track) {
  995. if (conference.startAudioMuted && track.isAudioTrack()) {
  996. track.mute();
  997. }
  998. if (conference.startVideoMuted && track.isVideoTrack()) {
  999. track.mute();
  1000. }
  1001. });
  1002. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  1003. });
  1004. conference.room.addPresenceListener("startmuted", function (data, from) {
  1005. var isModerator = false;
  1006. if (conference.myUserId() === from && conference.isModerator()) {
  1007. isModerator = true;
  1008. } else {
  1009. var participant = conference.getParticipantById(from);
  1010. if (participant && participant.isModerator()) {
  1011. isModerator = true;
  1012. }
  1013. }
  1014. if (!isModerator) {
  1015. return;
  1016. }
  1017. var startAudioMuted = data.attributes.audio === 'true';
  1018. var startVideoMuted = data.attributes.video === 'true';
  1019. var updated = false;
  1020. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  1021. conference.startMutedPolicy.audio = startAudioMuted;
  1022. updated = true;
  1023. }
  1024. if (startVideoMuted !== conference.startMutedPolicy.video) {
  1025. conference.startMutedPolicy.video = startVideoMuted;
  1026. updated = true;
  1027. }
  1028. if (updated) {
  1029. conference.eventEmitter.emit(
  1030. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  1031. conference.startMutedPolicy
  1032. );
  1033. }
  1034. });
  1035. conference.rtc.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED, function (devices) {
  1036. conference.room.updateDeviceAvailability(devices);
  1037. });
  1038. conference.room.addPresenceListener("devices", function (data, from) {
  1039. var isAudioAvailable = false;
  1040. var isVideoAvailable = false;
  1041. data.children.forEach(function (config) {
  1042. if (config.tagName === 'audio') {
  1043. isAudioAvailable = config.value === 'true';
  1044. }
  1045. if (config.tagName === 'video') {
  1046. isVideoAvailable = config.value === 'true';
  1047. }
  1048. });
  1049. var availableDevices;
  1050. if (conference.myUserId() === from) {
  1051. availableDevices = conference.availableDevices;
  1052. } else {
  1053. var participant = conference.getParticipantById(from);
  1054. if (!participant) {
  1055. return;
  1056. }
  1057. availableDevices = participant._availableDevices;
  1058. }
  1059. var updated = false;
  1060. if (availableDevices.audio !== isAudioAvailable) {
  1061. updated = true;
  1062. availableDevices.audio = isAudioAvailable;
  1063. }
  1064. if (availableDevices.video !== isVideoAvailable) {
  1065. updated = true;
  1066. availableDevices.video = isVideoAvailable;
  1067. }
  1068. if (updated) {
  1069. conference.eventEmitter.emit(
  1070. JitsiConferenceEvents.AVAILABLE_DEVICES_CHANGED,
  1071. from, availableDevices);
  1072. }
  1073. });
  1074. if(conference.statistics) {
  1075. //FIXME: Maybe remove event should not be associated with the conference.
  1076. conference.statistics.addAudioLevelListener(function (ssrc, level) {
  1077. var userId = null;
  1078. var resource = conference.rtc.getResourceBySSRC(ssrc);
  1079. if (!resource)
  1080. return;
  1081. conference.rtc.setAudioLevel(resource, level);
  1082. });
  1083. conference.statistics.addConnectionStatsListener(function (stats) {
  1084. var ssrc2resolution = stats.resolution;
  1085. var id2resolution = {};
  1086. // preprocess resolutions: group by user id, skip incorrect
  1087. // resolutions etc.
  1088. Object.keys(ssrc2resolution).forEach(function (ssrc) {
  1089. var resolution = ssrc2resolution[ssrc];
  1090. if (!resolution.width || !resolution.height ||
  1091. resolution.width == -1 || resolution.height == -1) {
  1092. return;
  1093. }
  1094. var id = conference.rtc.getResourceBySSRC(ssrc);
  1095. if (!id) {
  1096. return;
  1097. }
  1098. // ssrc to resolution map for user id
  1099. var idResolutions = id2resolution[id] || {};
  1100. idResolutions[ssrc] = resolution;
  1101. id2resolution[id] = idResolutions;
  1102. });
  1103. stats.resolution = id2resolution;
  1104. conference.eventEmitter.emit(
  1105. JitsiConferenceEvents.CONNECTION_STATS, stats);
  1106. });
  1107. conference.room.addListener(XMPPEvents.DISPOSE_CONFERENCE,
  1108. function () {
  1109. conference.statistics.dispose();
  1110. });
  1111. conference.room.addListener(XMPPEvents.PEERCONNECTION_READY,
  1112. function (session) {
  1113. conference.statistics.startCallStats(
  1114. session, conference.settings);
  1115. });
  1116. conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED,
  1117. function () {
  1118. conference.statistics.sendSetupFailedEvent();
  1119. });
  1120. conference.rtc.addListener(RTCEvents.TRACK_ATTACHED,
  1121. function(track, container) {
  1122. var ssrc = track.getSSRC();
  1123. if (!container.id || !ssrc) {
  1124. return;
  1125. }
  1126. conference.statistics.associateStreamWithVideoTag(
  1127. ssrc, track.isLocal(), track.getUsageLabel(), container.id);
  1128. });
  1129. conference.on(JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  1130. function (track) {
  1131. if(!track.isLocal())
  1132. return;
  1133. var type = (track.getType() === "audio")? "audio" : "video";
  1134. conference.statistics.sendMuteEvent(track.isMuted(), type);
  1135. });
  1136. conference.room.addListener(XMPPEvents.CREATE_OFFER_FAILED, function (e, pc) {
  1137. conference.statistics.sendCreateOfferFailed(e, pc);
  1138. });
  1139. conference.room.addListener(XMPPEvents.CREATE_ANSWER_FAILED, function (e, pc) {
  1140. conference.statistics.sendCreateAnswerFailed(e, pc);
  1141. });
  1142. conference.room.addListener(XMPPEvents.SET_LOCAL_DESCRIPTION_FAILED,
  1143. function (e, pc) {
  1144. conference.statistics.sendSetLocalDescFailed(e, pc);
  1145. }
  1146. );
  1147. conference.room.addListener(XMPPEvents.SET_REMOTE_DESCRIPTION_FAILED,
  1148. function (e, pc) {
  1149. conference.statistics.sendSetRemoteDescFailed(e, pc);
  1150. }
  1151. );
  1152. conference.room.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  1153. function (e, pc) {
  1154. conference.statistics.sendAddIceCandidateFailed(e, pc);
  1155. }
  1156. );
  1157. }
  1158. }
  1159. module.exports = JitsiConference;