You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiConference.js 43KB

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