Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

JitsiConference.js 42KB

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