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

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