Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

JitsiConference.js 44KB

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