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

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