Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

JitsiConference.js 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  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. // leave the conference
  92. if (conference.xmpp && conference.room) {
  93. conference.xmpp.leaveRoom(conference.room.roomjid);
  94. }
  95. conference.room = null;
  96. // remove local tracks
  97. return Promise.all(
  98. conference.getLocalTracks().map(function (track) {
  99. return conference.removeTrack(track);
  100. })
  101. ).then(function () {
  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.localStreams;
  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.getLocalVideoStream()) {
  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.addLocalStream(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. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  322. resolve(track);
  323. }.bind(this));
  324. }.bind(this));
  325. };
  326. /**
  327. * Fires TRACK_AUDIO_LEVEL_CHANGED change conference event.
  328. * @param audioLevel the audio level
  329. */
  330. JitsiConference.prototype._fireAudioLevelChangeEvent = function (audioLevel) {
  331. this.eventEmitter.emit(
  332. JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  333. this.myUserId(), audioLevel);
  334. };
  335. /**
  336. * Fires TRACK_MUTE_CHANGED change conference event.
  337. * @param track the JitsiTrack object related to the event.
  338. */
  339. JitsiConference.prototype._fireMuteChangeEvent = function (track) {
  340. // check if track was muted by focus and now is unmuted by user
  341. if (this.isMutedByFocus && track.isAudioTrack() && !track.isMuted()) {
  342. this.isMutedByFocus = false;
  343. // unmute local user on server
  344. this.room.muteParticipant(this.room.myroomjid, false);
  345. }
  346. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  347. };
  348. /**
  349. * Removes JitsiLocalTrack object to the conference.
  350. * @param track the JitsiLocalTrack object.
  351. * @returns {Promise}
  352. */
  353. JitsiConference.prototype.removeTrack = function (track) {
  354. if(track.disposed)
  355. {
  356. throw new Error(JitsiTrackErrors.TRACK_IS_DISPOSED);
  357. }
  358. if(!this.room){
  359. if(this.rtc) {
  360. this.rtc.removeLocalStream(track);
  361. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  362. }
  363. return Promise.resolve();
  364. }
  365. return new Promise(function (resolve) {
  366. this.room.removeStream(track.getOriginalStream(), function(){
  367. track._setSSRC(null);
  368. //FIXME: This dependacy is not necessary. This is quick fix.
  369. track._setConference(this);
  370. this.rtc.removeLocalStream(track);
  371. track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
  372. track.muteHandler);
  373. track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  374. track.audioLevelHandler);
  375. this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
  376. track.ssrcHandler);
  377. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  378. resolve();
  379. }.bind(this), {
  380. mtype: track.getType(),
  381. type: "remove",
  382. ssrc: track.ssrc});
  383. }.bind(this));
  384. };
  385. /**
  386. * Get role of the local user.
  387. * @returns {string} user role: 'moderator' or 'none'
  388. */
  389. JitsiConference.prototype.getRole = function () {
  390. return this.room.role;
  391. };
  392. /**
  393. * Check if local user is moderator.
  394. * @returns {boolean} true if local user is moderator, false otherwise.
  395. */
  396. JitsiConference.prototype.isModerator = function () {
  397. return this.room.isModerator();
  398. };
  399. /**
  400. * Set password for the room.
  401. * @param {string} password new password for the room.
  402. * @returns {Promise}
  403. */
  404. JitsiConference.prototype.lock = function (password) {
  405. if (!this.isModerator()) {
  406. return Promise.reject();
  407. }
  408. var conference = this;
  409. return new Promise(function (resolve, reject) {
  410. conference.room.lockRoom(password || "", function () {
  411. resolve();
  412. }, function (err) {
  413. reject(err);
  414. }, function () {
  415. reject(JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED);
  416. });
  417. });
  418. };
  419. /**
  420. * Remove password from the room.
  421. * @returns {Promise}
  422. */
  423. JitsiConference.prototype.unlock = function () {
  424. return this.lock();
  425. };
  426. /**
  427. * Elects the participant with the given id to be the selected participant or the speaker.
  428. * @param id the identifier of the participant
  429. */
  430. JitsiConference.prototype.selectParticipant = function(participantId) {
  431. if (this.rtc) {
  432. this.rtc.selectedEndpoint(participantId);
  433. }
  434. };
  435. /**
  436. *
  437. * @param id the identifier of the participant
  438. */
  439. JitsiConference.prototype.pinParticipant = function(participantId) {
  440. if (this.rtc) {
  441. this.rtc.pinEndpoint(participantId);
  442. }
  443. };
  444. /**
  445. * Returns the list of participants for this conference.
  446. * @return Array<JitsiParticipant> a list of participant identifiers containing all conference participants.
  447. */
  448. JitsiConference.prototype.getParticipants = function() {
  449. return Object.keys(this.participants).map(function (key) {
  450. return this.participants[key];
  451. }, this);
  452. };
  453. /**
  454. * @returns {JitsiParticipant} the participant in this conference with the specified id (or
  455. * undefined if there isn't one).
  456. * @param id the id of the participant.
  457. */
  458. JitsiConference.prototype.getParticipantById = function(id) {
  459. return this.participants[id];
  460. };
  461. /**
  462. * Kick participant from this conference.
  463. * @param {string} id id of the participant to kick
  464. */
  465. JitsiConference.prototype.kickParticipant = function (id) {
  466. var participant = this.getParticipantById(id);
  467. if (!participant) {
  468. return;
  469. }
  470. this.room.kick(participant.getJid());
  471. };
  472. /**
  473. * Kick participant from this conference.
  474. * @param {string} id id of the participant to kick
  475. */
  476. JitsiConference.prototype.muteParticipant = function (id) {
  477. var participant = this.getParticipantById(id);
  478. if (!participant) {
  479. return;
  480. }
  481. this.room.muteParticipant(participant.getJid(), true);
  482. };
  483. JitsiConference.prototype.onMemberJoined = function (jid, nick, role) {
  484. var id = Strophe.getResourceFromJid(jid);
  485. if (id === 'focus' || this.myUserId() === id) {
  486. return;
  487. }
  488. var participant = new JitsiParticipant(jid, this, nick);
  489. participant._role = role;
  490. this.participants[id] = participant;
  491. this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
  492. this.xmpp.connection.disco.info(
  493. jid, "node", function(iq) {
  494. participant._supportsDTMF = $(iq).find(
  495. '>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
  496. this.updateDTMFSupport();
  497. }.bind(this)
  498. );
  499. };
  500. JitsiConference.prototype.onMemberLeft = function (jid) {
  501. var id = Strophe.getResourceFromJid(jid);
  502. if (id === 'focus' || this.myUserId() === id) {
  503. return;
  504. }
  505. var participant = this.participants[id];
  506. delete this.participants[id];
  507. this.rtc.removeRemoteStream(id);
  508. this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
  509. };
  510. JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
  511. var id = Strophe.getResourceFromJid(jid);
  512. var participant = this.getParticipantById(id);
  513. if (!participant) {
  514. return;
  515. }
  516. participant._role = role;
  517. this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
  518. };
  519. JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
  520. var id = Strophe.getResourceFromJid(jid);
  521. var participant = this.getParticipantById(id);
  522. if (!participant) {
  523. return;
  524. }
  525. if (participant._displayName === displayName)
  526. return;
  527. participant._displayName = displayName;
  528. this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
  529. };
  530. JitsiConference.prototype.onTrackAdded = function (track) {
  531. var id = track.getParticipantId();
  532. var participant = this.getParticipantById(id);
  533. if (!participant) {
  534. return;
  535. }
  536. // add track to JitsiParticipant
  537. participant._tracks.push(track);
  538. var emitter = this.eventEmitter;
  539. track.addEventListener(
  540. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  541. function () {
  542. emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  543. }
  544. );
  545. track.addEventListener(
  546. JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  547. function (audioLevel) {
  548. emitter.emit(JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, id, audioLevel);
  549. }
  550. );
  551. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  552. };
  553. JitsiConference.prototype.updateDTMFSupport = function () {
  554. var somebodySupportsDTMF = false;
  555. var participants = this.getParticipants();
  556. // check if at least 1 participant supports DTMF
  557. for (var i = 0; i < participants.length; i += 1) {
  558. if (participants[i].supportsDTMF()) {
  559. somebodySupportsDTMF = true;
  560. break;
  561. }
  562. }
  563. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  564. this.somebodySupportsDTMF = somebodySupportsDTMF;
  565. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  566. }
  567. };
  568. /**
  569. * Allows to check if there is at least one user in the conference
  570. * that supports DTMF.
  571. * @returns {boolean} true if somebody supports DTMF, false otherwise
  572. */
  573. JitsiConference.prototype.isDTMFSupported = function () {
  574. return this.somebodySupportsDTMF;
  575. };
  576. /**
  577. * Returns the local user's ID
  578. * @return {string} local user's ID
  579. */
  580. JitsiConference.prototype.myUserId = function () {
  581. return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  582. };
  583. JitsiConference.prototype.sendTones = function (tones, duration, pause) {
  584. if (!this.dtmfManager) {
  585. var connection = this.xmpp.connection.jingle.activecall.peerconnection;
  586. if (!connection) {
  587. logger.warn("cannot sendTones: no conneciton");
  588. return;
  589. }
  590. var tracks = this.getLocalTracks().filter(function (track) {
  591. return track.isAudioTrack();
  592. });
  593. if (!tracks.length) {
  594. logger.warn("cannot sendTones: no local audio stream");
  595. return;
  596. }
  597. this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
  598. }
  599. this.dtmfManager.sendTones(tones, duration, pause);
  600. };
  601. /**
  602. * Returns true if the recording is supproted and false if not.
  603. */
  604. JitsiConference.prototype.isRecordingSupported = function () {
  605. if(this.room)
  606. return this.room.isRecordingSupported();
  607. return false;
  608. };
  609. /**
  610. * Returns null if the recording is not supported, "on" if the recording started
  611. * and "off" if the recording is not started.
  612. */
  613. JitsiConference.prototype.getRecordingState = function () {
  614. if(this.room)
  615. return this.room.getRecordingState();
  616. return Recording.status.OFF;
  617. }
  618. /**
  619. * Returns the url of the recorded video.
  620. */
  621. JitsiConference.prototype.getRecordingURL = function () {
  622. if(this.room)
  623. return this.room.getRecordingURL();
  624. return null;
  625. }
  626. /**
  627. * Starts/stops the recording
  628. */
  629. JitsiConference.prototype.toggleRecording = function (options) {
  630. if(this.room)
  631. return this.room.toggleRecording(options, function (status, error) {
  632. this.eventEmitter.emit(
  633. JitsiConferenceEvents.RECORDER_STATE_CHANGED, status, error);
  634. }.bind(this));
  635. this.eventEmitter.emit(
  636. JitsiConferenceEvents.RECORDER_STATE_CHANGED, "error",
  637. new Error("The conference is not created yet!"));
  638. }
  639. /**
  640. * Returns true if the SIP calls are supported and false otherwise
  641. */
  642. JitsiConference.prototype.isSIPCallingSupported = function () {
  643. if(this.room)
  644. return this.room.isSIPCallingSupported();
  645. return false;
  646. }
  647. /**
  648. * Dials a number.
  649. * @param number the number
  650. */
  651. JitsiConference.prototype.dial = function (number) {
  652. if(this.room)
  653. return this.room.dial(number);
  654. return new Promise(function(resolve, reject){
  655. reject(new Error("The conference is not created yet!"))});
  656. }
  657. /**
  658. * Hangup an existing call
  659. */
  660. JitsiConference.prototype.hangup = function () {
  661. if(this.room)
  662. return this.room.hangup();
  663. return new Promise(function(resolve, reject){
  664. reject(new Error("The conference is not created yet!"))});
  665. }
  666. /**
  667. * Returns the phone number for joining the conference.
  668. */
  669. JitsiConference.prototype.getPhoneNumber = function () {
  670. if(this.room)
  671. return this.room.getPhoneNumber();
  672. return null;
  673. }
  674. /**
  675. * Returns the pin for joining the conference with phone.
  676. */
  677. JitsiConference.prototype.getPhonePin = function () {
  678. if(this.room)
  679. return this.room.getPhonePin();
  680. return null;
  681. }
  682. /**
  683. * Returns the connection state for the current room. Its ice connection state
  684. * for its session.
  685. */
  686. JitsiConference.prototype.getConnectionState = function () {
  687. if(this.room)
  688. return this.room.getConnectionState();
  689. return null;
  690. }
  691. /**
  692. * Make all new participants mute their audio/video on join.
  693. * @param policy {Object} object with 2 boolean properties for video and audio:
  694. * @param {boolean} audio if audio should be muted.
  695. * @param {boolean} video if video should be muted.
  696. */
  697. JitsiConference.prototype.setStartMutedPolicy = function (policy) {
  698. if (!this.isModerator()) {
  699. return;
  700. }
  701. this.startMutedPolicy = policy;
  702. this.room.removeFromPresence("startmuted");
  703. this.room.addToPresence("startmuted", {
  704. attributes: {
  705. audio: policy.audio,
  706. video: policy.video,
  707. xmlns: 'http://jitsi.org/jitmeet/start-muted'
  708. }
  709. });
  710. this.room.sendPresence();
  711. };
  712. /**
  713. * Returns current start muted policy
  714. * @returns {Object} with 2 proprties - audio and video.
  715. */
  716. JitsiConference.prototype.getStartMutedPolicy = function () {
  717. return this.startMutedPolicy;
  718. };
  719. /**
  720. * Check if audio is muted on join.
  721. */
  722. JitsiConference.prototype.isStartAudioMuted = function () {
  723. return this.startAudioMuted;
  724. };
  725. /**
  726. * Check if video is muted on join.
  727. */
  728. JitsiConference.prototype.isStartVideoMuted = function () {
  729. return this.startVideoMuted;
  730. };
  731. /**
  732. * Get object with internal logs.
  733. */
  734. JitsiConference.prototype.getLogs = function () {
  735. var data = this.xmpp.getJingleLog();
  736. var metadata = {};
  737. metadata.time = new Date();
  738. metadata.url = window.location.href;
  739. metadata.ua = navigator.userAgent;
  740. var log = this.xmpp.getXmppLog();
  741. if (log) {
  742. metadata.xmpp = log;
  743. }
  744. data.metadata = metadata;
  745. return data;
  746. };
  747. /**
  748. * Returns measured performanceTimes.
  749. */
  750. JitsiConference.prototype.getPerformanceTimes = function () {
  751. return this.room.performanceTimes;
  752. };
  753. /**
  754. * Sends the given feedback through CallStats if enabled.
  755. *
  756. * @param overallFeedback an integer between 1 and 5 indicating the
  757. * user feedback
  758. * @param detailedFeedback detailed feedback from the user. Not yet used
  759. */
  760. JitsiConference.prototype.sendFeedback =
  761. function(overallFeedback, detailedFeedback){
  762. this.statistics.sendFeedback(overallFeedback, detailedFeedback);
  763. }
  764. /**
  765. * Returns true if the callstats integration is enabled, otherwise returns
  766. * false.
  767. *
  768. * @returns true if the callstats integration is enabled, otherwise returns
  769. * false.
  770. */
  771. JitsiConference.prototype.isCallstatsEnabled = function () {
  772. return this.statistics.isCallstatsEnabled();
  773. }
  774. /**
  775. * Setups the listeners needed for the conference.
  776. * @param conference the conference
  777. */
  778. function setupListeners(conference) {
  779. conference.xmpp.addListener(
  780. XMPPEvents.CALL_INCOMING, function (jingleSession, jingleOffer, now) {
  781. if (conference.room.isFocus(jingleSession.peerjid)) {
  782. // Accept incoming call
  783. conference.room.setJingleSession(jingleSession);
  784. conference.room.performanceTimes["session.initiate"] = now;
  785. jingleSession.initialize(false /* initiator */, conference.room);
  786. conference.rtc.onIncommingCall(jingleSession);
  787. jingleSession.acceptOffer(jingleOffer, null,
  788. function (error) {
  789. console.error(
  790. "Failed to accept incoming Jingle session", error);
  791. }
  792. );
  793. conference.statistics.startRemoteStats(
  794. jingleSession.peerconnection);
  795. } else {
  796. // Error cause this should never happen unless something is wrong !
  797. logger.error(
  798. "Rejecting session-initiate from non focus user: "
  799. + jingleSession.peerjid);
  800. }
  801. });
  802. conference.room.addListener(XMPPEvents.REMOTE_STREAM_RECEIVED,
  803. function (data, sid, thessrc) {
  804. var track = conference.rtc.createRemoteStream(data, sid, thessrc);
  805. if (track) {
  806. conference.onTrackAdded(track);
  807. }
  808. }
  809. );
  810. conference.room.addListener(XMPPEvents.REMOTE_STREAM_REMOVED,
  811. function (streamId) {
  812. var participants = conference.getParticipants();
  813. for(var j = 0; j < participants.length; j++) {
  814. var participant = participants[j];
  815. var tracks = participant.getTracks();
  816. for(var i = 0; i < tracks.length; i++) {
  817. if(tracks[i] && tracks[i].stream &&
  818. RTC.getStreamID(tracks[i].stream) == streamId){
  819. var track = participant._tracks.splice(i, 1)[0];
  820. conference.eventEmitter.emit(
  821. JitsiConferenceEvents.TRACK_REMOVED, track);
  822. return;
  823. }
  824. }
  825. }
  826. }
  827. );
  828. conference.rtc.addListener(RTCEvents.FAKE_VIDEO_TRACK_CREATED,
  829. function (track) {
  830. conference.onTrackAdded(track);
  831. }
  832. );
  833. conference.room.addListener(XMPPEvents.AUDIO_MUTED_BY_FOCUS,
  834. function (value) {
  835. // set isMutedByFocus when setAudioMute Promise ends
  836. conference.rtc.setAudioMute(value).then(
  837. function() {
  838. conference.isMutedByFocus = true;
  839. },
  840. function() {
  841. logger.warn(
  842. "Error while audio muting due to focus request");
  843. });
  844. }
  845. );
  846. conference.room.addListener(XMPPEvents.SUBJECT_CHANGED, function (subject) {
  847. conference.eventEmitter.emit(JitsiConferenceEvents.SUBJECT_CHANGED,
  848. subject);
  849. });
  850. conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  851. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_JOINED);
  852. });
  853. conference.room.addListener(XMPPEvents.ROOM_JOIN_ERROR, function (pres) {
  854. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  855. JitsiConferenceErrors.CONNECTION_ERROR, pres);
  856. });
  857. conference.room.addListener(XMPPEvents.ROOM_CONNECT_ERROR, function (pres) {
  858. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  859. JitsiConferenceErrors.CONNECTION_ERROR, pres);
  860. });
  861. conference.room.addListener(XMPPEvents.ROOM_MAX_USERS_ERROR,
  862. function (pres) {
  863. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  864. JitsiConferenceErrors.CONFERENCE_MAX_USERS, pres);
  865. });
  866. conference.room.addListener(XMPPEvents.PASSWORD_REQUIRED, function (pres) {
  867. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.PASSWORD_REQUIRED, pres);
  868. });
  869. conference.room.addListener(XMPPEvents.AUTHENTICATION_REQUIRED, function () {
  870. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.AUTHENTICATION_REQUIRED);
  871. });
  872. conference.room.addListener(XMPPEvents.BRIDGE_DOWN, function () {
  873. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
  874. });
  875. conference.room.addListener(XMPPEvents.RESERVATION_ERROR, function (code, msg) {
  876. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.RESERVATION_ERROR, code, msg);
  877. });
  878. conference.room.addListener(XMPPEvents.GRACEFUL_SHUTDOWN, function () {
  879. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.GRACEFUL_SHUTDOWN);
  880. });
  881. conference.room.addListener(XMPPEvents.JINGLE_FATAL_ERROR, function () {
  882. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.JINGLE_FATAL_ERROR);
  883. });
  884. conference.room.addListener(XMPPEvents.MUC_DESTROYED, function (reason) {
  885. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.CONFERENCE_DESTROYED, reason);
  886. });
  887. conference.room.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, function (err, msg) {
  888. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_ERROR, JitsiConferenceErrors.CHAT_ERROR, err, msg);
  889. });
  890. conference.room.addListener(XMPPEvents.FOCUS_DISCONNECTED, function (focus, retrySec) {
  891. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.FOCUS_DISCONNECTED, focus, retrySec);
  892. });
  893. conference.room.addListener(XMPPEvents.FOCUS_LEFT, function () {
  894. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.FOCUS_LEFT);
  895. });
  896. // FIXME
  897. // conference.room.addListener(XMPPEvents.MUC_JOINED, function () {
  898. // conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_LEFT);
  899. // });
  900. conference.room.addListener(XMPPEvents.KICKED, function () {
  901. conference.eventEmitter.emit(JitsiConferenceEvents.KICKED);
  902. });
  903. conference.room.addListener(XMPPEvents.MUC_MEMBER_JOINED, conference.onMemberJoined.bind(conference));
  904. conference.room.addListener(XMPPEvents.MUC_MEMBER_LEFT, conference.onMemberLeft.bind(conference));
  905. conference.room.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, conference.onDisplayNameChanged.bind(conference));
  906. conference.room.addListener(XMPPEvents.LOCAL_ROLE_CHANGED, function (role) {
  907. conference.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, conference.myUserId(), role);
  908. });
  909. conference.room.addListener(XMPPEvents.MUC_ROLE_CHANGED, conference.onUserRoleChanged.bind(conference));
  910. conference.room.addListener(XMPPEvents.CONNECTION_INTERRUPTED, function () {
  911. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_INTERRUPTED);
  912. });
  913. conference.room.addListener(XMPPEvents.RECORDER_STATE_CHANGED,
  914. function (state) {
  915. conference.eventEmitter.emit(
  916. JitsiConferenceEvents.RECORDER_STATE_CHANGED, state);
  917. });
  918. conference.room.addListener(XMPPEvents.PHONE_NUMBER_CHANGED, function () {
  919. conference.eventEmitter.emit(
  920. JitsiConferenceEvents.PHONE_NUMBER_CHANGED);
  921. });
  922. conference.room.addListener(XMPPEvents.CONNECTION_RESTORED, function () {
  923. conference.eventEmitter.emit(JitsiConferenceEvents.CONNECTION_RESTORED);
  924. });
  925. conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED, function () {
  926. conference.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED, JitsiConferenceErrors.SETUP_FAILED);
  927. });
  928. conference.room.addListener(AuthenticationEvents.IDENTITY_UPDATED, function (authEnabled, authIdentity) {
  929. conference.authEnabled = authEnabled;
  930. conference.authIdentity = authIdentity;
  931. conference.eventEmitter.emit(JitsiConferenceEvents.AUTH_STATUS_CHANGED, authEnabled, authIdentity);
  932. });
  933. conference.room.addListener(XMPPEvents.MESSAGE_RECEIVED, function (jid, displayName, txt, myJid, ts) {
  934. var id = Strophe.getResourceFromJid(jid);
  935. conference.eventEmitter.emit(JitsiConferenceEvents.MESSAGE_RECEIVED, id, txt, ts);
  936. });
  937. conference.room.addListener(XMPPEvents.PRESENCE_STATUS, function (jid, status) {
  938. var id = Strophe.getResourceFromJid(jid);
  939. var participant = conference.getParticipantById(id);
  940. if (!participant || participant._status === status) {
  941. return;
  942. }
  943. participant._status = status;
  944. conference.eventEmitter.emit(JitsiConferenceEvents.USER_STATUS_CHANGED, id, status);
  945. });
  946. conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED, function (id) {
  947. if(conference.lastDominantSpeaker !== id && conference.room) {
  948. conference.lastDominantSpeaker = id;
  949. conference.eventEmitter.emit(JitsiConferenceEvents.DOMINANT_SPEAKER_CHANGED, id);
  950. }
  951. });
  952. conference.rtc.addListener(RTCEvents.LASTN_CHANGED, function (oldValue, newValue) {
  953. conference.eventEmitter.emit(JitsiConferenceEvents.IN_LAST_N_CHANGED, oldValue, newValue);
  954. });
  955. conference.rtc.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
  956. function (lastNEndpoints, endpointsEnteringLastN) {
  957. conference.eventEmitter.emit(JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
  958. lastNEndpoints, endpointsEnteringLastN);
  959. });
  960. conference.xmpp.addListener(XMPPEvents.START_MUTED_FROM_FOCUS,
  961. function (audioMuted, videoMuted) {
  962. conference.startAudioMuted = audioMuted;
  963. conference.startVideoMuted = videoMuted;
  964. // mute existing local tracks because this is initial mute from
  965. // Jicofo
  966. conference.getLocalTracks().forEach(function (track) {
  967. if (conference.startAudioMuted && track.isAudioTrack()) {
  968. track.mute();
  969. }
  970. if (conference.startVideoMuted && track.isVideoTrack()) {
  971. track.mute();
  972. }
  973. });
  974. conference.eventEmitter.emit(JitsiConferenceEvents.STARTED_MUTED);
  975. });
  976. conference.room.addPresenceListener("startmuted", function (data, from) {
  977. var isModerator = false;
  978. if (conference.myUserId() === from && conference.isModerator()) {
  979. isModerator = true;
  980. } else {
  981. var participant = conference.getParticipantById(from);
  982. if (participant && participant.isModerator()) {
  983. isModerator = true;
  984. }
  985. }
  986. if (!isModerator) {
  987. return;
  988. }
  989. var startAudioMuted = data.attributes.audio === 'true';
  990. var startVideoMuted = data.attributes.video === 'true';
  991. var updated = false;
  992. if (startAudioMuted !== conference.startMutedPolicy.audio) {
  993. conference.startMutedPolicy.audio = startAudioMuted;
  994. updated = true;
  995. }
  996. if (startVideoMuted !== conference.startMutedPolicy.video) {
  997. conference.startMutedPolicy.video = startVideoMuted;
  998. updated = true;
  999. }
  1000. if (updated) {
  1001. conference.eventEmitter.emit(
  1002. JitsiConferenceEvents.START_MUTED_POLICY_CHANGED,
  1003. conference.startMutedPolicy
  1004. );
  1005. }
  1006. });
  1007. conference.rtc.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED, function (devices) {
  1008. conference.room.updateDeviceAvailability(devices);
  1009. });
  1010. conference.room.addPresenceListener("devices", function (data, from) {
  1011. var isAudioAvailable = false;
  1012. var isVideoAvailable = false;
  1013. data.children.forEach(function (config) {
  1014. if (config.tagName === 'audio') {
  1015. isAudioAvailable = config.value === 'true';
  1016. }
  1017. if (config.tagName === 'video') {
  1018. isVideoAvailable = config.value === 'true';
  1019. }
  1020. });
  1021. var availableDevices;
  1022. if (conference.myUserId() === from) {
  1023. availableDevices = conference.availableDevices;
  1024. } else {
  1025. var participant = conference.getParticipantById(from);
  1026. if (!participant) {
  1027. return;
  1028. }
  1029. availableDevices = participant._availableDevices;
  1030. }
  1031. var updated = false;
  1032. if (availableDevices.audio !== isAudioAvailable) {
  1033. updated = true;
  1034. availableDevices.audio = isAudioAvailable;
  1035. }
  1036. if (availableDevices.video !== isVideoAvailable) {
  1037. updated = true;
  1038. availableDevices.video = isVideoAvailable;
  1039. }
  1040. if (updated) {
  1041. conference.eventEmitter.emit(
  1042. JitsiConferenceEvents.AVAILABLE_DEVICES_CHANGED,
  1043. from, availableDevices);
  1044. }
  1045. });
  1046. if(conference.statistics) {
  1047. //FIXME: Maybe remove event should not be associated with the conference.
  1048. conference.statistics.addAudioLevelListener(function (ssrc, level) {
  1049. var userId = null;
  1050. var resource = conference.rtc.getResourceBySSRC(ssrc);
  1051. if (!resource)
  1052. return;
  1053. conference.rtc.setAudioLevel(resource, level);
  1054. });
  1055. conference.statistics.addConnectionStatsListener(function (stats) {
  1056. var ssrc2resolution = stats.resolution;
  1057. var id2resolution = {};
  1058. // preprocess resolutions: group by user id, skip incorrect
  1059. // resolutions etc.
  1060. Object.keys(ssrc2resolution).forEach(function (ssrc) {
  1061. var resolution = ssrc2resolution[ssrc];
  1062. if (!resolution.width || !resolution.height ||
  1063. resolution.width == -1 || resolution.height == -1) {
  1064. return;
  1065. }
  1066. var id = conference.rtc.getResourceBySSRC(ssrc);
  1067. if (!id) {
  1068. return;
  1069. }
  1070. // ssrc to resolution map for user id
  1071. var idResolutions = id2resolution[id] || {};
  1072. idResolutions[ssrc] = resolution;
  1073. id2resolution[id] = idResolutions;
  1074. });
  1075. stats.resolution = id2resolution;
  1076. conference.eventEmitter.emit(
  1077. JitsiConferenceEvents.CONNECTION_STATS, stats);
  1078. });
  1079. conference.xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE,
  1080. function () {
  1081. conference.statistics.dispose();
  1082. });
  1083. conference.room.addListener(XMPPEvents.PEERCONNECTION_READY,
  1084. function (session) {
  1085. conference.statistics.startCallStats(
  1086. session, conference.settings);
  1087. });
  1088. conference.room.addListener(XMPPEvents.CONFERENCE_SETUP_FAILED,
  1089. function () {
  1090. conference.statistics.sendSetupFailedEvent();
  1091. });
  1092. conference.rtc.addListener(RTCEvents.TRACK_ATTACHED,
  1093. function(track, container) {
  1094. var ssrc = track.getSSRC();
  1095. if (!container.id || !ssrc) {
  1096. return;
  1097. }
  1098. conference.statistics.associateStreamWithVideoTag(
  1099. ssrc, track.isLocal(), track.getUsageLabel(), container.id);
  1100. });
  1101. conference.on(JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  1102. function (track) {
  1103. if(!track.isLocal())
  1104. return;
  1105. var type = (track.getType() === "audio")? "audio" : "video";
  1106. conference.statistics.sendMuteEvent(track.isMuted(), type);
  1107. });
  1108. conference.room.addListener(XMPPEvents.CREATE_OFFER_FAILED, function (e, pc) {
  1109. conference.statistics.sendCreateOfferFailed(e, pc);
  1110. });
  1111. conference.room.addListener(XMPPEvents.CREATE_ANSWER_FAILED, function (e, pc) {
  1112. conference.statistics.sendCreateAnswerFailed(e, pc);
  1113. });
  1114. conference.room.addListener(XMPPEvents.SET_LOCAL_DESCRIPTION_FAILED,
  1115. function (e, pc) {
  1116. conference.statistics.sendSetLocalDescFailed(e, pc);
  1117. }
  1118. );
  1119. conference.room.addListener(XMPPEvents.SET_REMOTE_DESCRIPTION_FAILED,
  1120. function (e, pc) {
  1121. conference.statistics.sendSetRemoteDescFailed(e, pc);
  1122. }
  1123. );
  1124. conference.room.addListener(XMPPEvents.ADD_ICE_CANDIDATE_FAILED,
  1125. function (e, pc) {
  1126. conference.statistics.sendAddIceCandidateFailed(e, pc);
  1127. }
  1128. );
  1129. }
  1130. }
  1131. module.exports = JitsiConference;