Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

JitsiConference.js 43KB

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