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

JitsiConference.js 47KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. /* global Strophe, Promise */
  2. var logger = require("jitsi-meet-logger").getLogger(__filename);
  3. import RTC from "./modules/RTC/RTC";
  4. import * as MediaType from "./service/RTC/MediaType";
  5. var XMPPEvents = require("./service/xmpp/XMPPEvents");
  6. var EventEmitter = require("events");
  7. import * as JitsiConferenceErrors from "./JitsiConferenceErrors";
  8. import * as JitsiConferenceEvents from "./JitsiConferenceEvents";
  9. import JitsiParticipant from "./JitsiParticipant";
  10. var Statistics = require("./modules/statistics/statistics");
  11. var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
  12. import JitsiTrackError from "./JitsiTrackError";
  13. import * as JitsiTrackErrors from "./JitsiTrackErrors";
  14. import * as JitsiTrackEvents from "./JitsiTrackEvents";
  15. var ComponentsVersions = require("./modules/version/ComponentsVersions");
  16. var GlobalOnErrorHandler = require("./modules/util/GlobalOnErrorHandler");
  17. var JitsiConferenceEventManager = require("./JitsiConferenceEventManager");
  18. var VideoType = require('./service/RTC/VideoType');
  19. var RTCBrowserType = require("./modules/RTC/RTCBrowserType.js");
  20. var Transcriber = require("./modules/transcription/transcriber");
  21. import ParticipantConnectionStatus
  22. from "./modules/connectivity/ParticipantConnectionStatus";
  23. import TalkMutedDetection from "./modules/TalkMutedDetection";
  24. import ConnectionQuality from "./modules/connectivity/ConnectionQuality";
  25. /**
  26. * Creates a JitsiConference object with the given name and properties.
  27. * Note: this constructor is not a part of the public API (objects should be
  28. * created using JitsiConnection.createConference).
  29. * @param options.config properties / settings related to the conference that will be created.
  30. * @param options.name the name of the conference
  31. * @param options.connection the JitsiConnection object for this JitsiConference.
  32. * @constructor
  33. */
  34. function JitsiConference(options) {
  35. if(!options.name || options.name.toLowerCase() !== options.name) {
  36. var errmsg
  37. = "Invalid conference name (no conference name passed or it "
  38. + "contains invalid characters like capital letters)!";
  39. logger.error(errmsg);
  40. throw new Error(errmsg);
  41. }
  42. this.eventEmitter = new EventEmitter();
  43. this.options = options;
  44. this.eventManager = new JitsiConferenceEventManager(this);
  45. this._init(options);
  46. this.componentsVersions = new ComponentsVersions(this);
  47. this.participants = {};
  48. /**
  49. * Jingle Session instance
  50. * @type {JingleSessionPC}
  51. */
  52. this.jingleSession = null;
  53. this.lastDominantSpeaker = null;
  54. this.dtmfManager = null;
  55. this.somebodySupportsDTMF = false;
  56. this.authEnabled = false;
  57. this.authIdentity;
  58. this.startAudioMuted = false;
  59. this.startVideoMuted = false;
  60. this.startMutedPolicy = {audio: false, video: false};
  61. this.availableDevices = {
  62. audio: undefined,
  63. video: undefined
  64. };
  65. this.isMutedByFocus = false;
  66. // Flag indicates if the 'onCallEnded' method was ever called on this
  67. // instance. Used to log extra analytics event for debugging purpose.
  68. // We need to know if the potential issue happened before or after
  69. // the restart.
  70. this.wasStopped = false;
  71. /**
  72. * The object which monitors local and remote connection statistics (e.g.
  73. * sending bitrate) and calculates a number which represents the connection
  74. * quality.
  75. */
  76. this.connectionQuality
  77. = new ConnectionQuality(this, this.eventEmitter, options);
  78. /**
  79. * Indicates whether the connection is interrupted or not.
  80. */
  81. this.connectionIsInterrupted = false;
  82. }
  83. /**
  84. * Initializes the conference object properties
  85. * @param options {object}
  86. * @param connection {JitsiConnection} overrides this.connection
  87. */
  88. JitsiConference.prototype._init = function (options) {
  89. if(!options)
  90. options = {};
  91. // Override connection and xmpp properties (Usefull if the connection
  92. // reloaded)
  93. if(options.connection) {
  94. this.connection = options.connection;
  95. this.xmpp = this.connection.xmpp;
  96. // Setup XMPP events only if we have new connection object.
  97. this.eventManager.setupXMPPListeners();
  98. }
  99. this.room = this.xmpp.createRoom(this.options.name, this.options.config);
  100. this.room.updateDeviceAvailability(RTC.getDeviceAvailability());
  101. if(!this.rtc) {
  102. this.rtc = new RTC(this, options);
  103. this.eventManager.setupRTCListeners();
  104. }
  105. this.participantConnectionStatus
  106. = new ParticipantConnectionStatus(
  107. this.rtc, this,
  108. options.config.peerDisconnectedThroughRtcTimeout);
  109. this.participantConnectionStatus.init();
  110. if(!this.statistics) {
  111. this.statistics = new Statistics(this.xmpp, {
  112. callStatsID: this.options.config.callStatsID,
  113. callStatsSecret: this.options.config.callStatsSecret,
  114. callStatsConfIDNamespace:
  115. this.options.config.callStatsConfIDNamespace || window.location.hostname,
  116. callStatsCustomScriptUrl:
  117. this.options.config.callStatsCustomScriptUrl,
  118. roomName: this.options.name
  119. });
  120. }
  121. this.eventManager.setupChatRoomListeners();
  122. // Always add listeners because on reload we are executing leave and the
  123. // listeners are removed from statistics module.
  124. this.eventManager.setupStatisticsListeners();
  125. if (this.options.config.enableTalkWhileMuted) {
  126. new TalkMutedDetection(this, () => {
  127. this.eventEmitter.emit(JitsiConferenceEvents.TALK_WHILE_MUTED);
  128. });
  129. }
  130. };
  131. /**
  132. * Joins the conference.
  133. * @param password {string} the password
  134. */
  135. JitsiConference.prototype.join = function (password) {
  136. if(this.room)
  137. this.room.join(password);
  138. };
  139. /**
  140. * Check if joined to the conference.
  141. */
  142. JitsiConference.prototype.isJoined = function () {
  143. return this.room && this.room.joined;
  144. };
  145. /**
  146. * Leaves the conference.
  147. * @returns {Promise}
  148. */
  149. JitsiConference.prototype.leave = function () {
  150. if (this.participantConnectionStatus) {
  151. this.participantConnectionStatus.dispose();
  152. this.participantConnectionStatus = null;
  153. }
  154. this.getLocalTracks().forEach(track => this.onTrackRemoved(track));
  155. this.rtc.closeAllDataChannels();
  156. if(this.statistics)
  157. this.statistics.dispose();
  158. // leave the conference
  159. if (this.room) {
  160. let room = this.room;
  161. this.room = null;
  162. return room.leave().catch(() => {
  163. // remove all participants because currently the conference won't
  164. // be usable anyway. This is done on success automatically by the
  165. // ChatRoom instance.
  166. this.getParticipants().forEach(
  167. participant => this.onMemberLeft(participant.getJid()));
  168. // Close the JingleSession
  169. if (this.jingleSession) {
  170. this.jingleSession.close();
  171. this.jingleSession = null;
  172. }
  173. });
  174. }
  175. // If this.room == null we are calling second time leave().
  176. return Promise.reject(
  177. new Error("The conference is has been already left"));
  178. };
  179. /**
  180. * Returns name of this conference.
  181. */
  182. JitsiConference.prototype.getName = function () {
  183. return this.options.name;
  184. };
  185. /**
  186. * Check if authentication is enabled for this conference.
  187. */
  188. JitsiConference.prototype.isAuthEnabled = function () {
  189. return this.authEnabled;
  190. };
  191. /**
  192. * Check if user is logged in.
  193. */
  194. JitsiConference.prototype.isLoggedIn = function () {
  195. return !!this.authIdentity;
  196. };
  197. /**
  198. * Get authorized login.
  199. */
  200. JitsiConference.prototype.getAuthLogin = function () {
  201. return this.authIdentity;
  202. };
  203. /**
  204. * Check if external authentication is enabled for this conference.
  205. */
  206. JitsiConference.prototype.isExternalAuthEnabled = function () {
  207. return this.room && this.room.moderator.isExternalAuthEnabled();
  208. };
  209. /**
  210. * Get url for external authentication.
  211. * @param {boolean} [urlForPopup] if true then return url for login popup,
  212. * else url of login page.
  213. * @returns {Promise}
  214. */
  215. JitsiConference.prototype.getExternalAuthUrl = function (urlForPopup) {
  216. return new Promise(function (resolve, reject) {
  217. if (!this.isExternalAuthEnabled()) {
  218. reject();
  219. return;
  220. }
  221. if (urlForPopup) {
  222. this.room.moderator.getPopupLoginUrl(resolve, reject);
  223. } else {
  224. this.room.moderator.getLoginUrl(resolve, reject);
  225. }
  226. }.bind(this));
  227. };
  228. /**
  229. * Returns the local tracks of the given media type, or all local tracks if no
  230. * specific type is given.
  231. * @param {MediaType} [mediaType] Optional media type (audio or video).
  232. */
  233. JitsiConference.prototype.getLocalTracks = function (mediaType) {
  234. let tracks = [];
  235. if (this.rtc) {
  236. tracks = this.rtc.localTracks.slice();
  237. }
  238. if (mediaType !== undefined) {
  239. tracks = tracks.filter(
  240. (track) => {
  241. return track && track.getType && track.getType() === mediaType;
  242. });
  243. }
  244. return tracks;
  245. };
  246. /**
  247. * Attaches a handler for events(For example - "participant joined".) in the conference. All possible event are defined
  248. * in JitsiConferenceEvents.
  249. * @param eventId the event ID.
  250. * @param handler handler for the event.
  251. *
  252. * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
  253. */
  254. JitsiConference.prototype.on = function (eventId, handler) {
  255. if(this.eventEmitter)
  256. this.eventEmitter.on(eventId, handler);
  257. };
  258. /**
  259. * Removes event listener
  260. * @param eventId the event ID.
  261. * @param [handler] optional, the specific handler to unbind
  262. *
  263. * Note: consider adding eventing functionality by extending an EventEmitter impl, instead of rolling ourselves
  264. */
  265. JitsiConference.prototype.off = function (eventId, handler) {
  266. if(this.eventEmitter)
  267. this.eventEmitter.removeListener(eventId, handler);
  268. };
  269. // Common aliases for event emitter
  270. JitsiConference.prototype.addEventListener = JitsiConference.prototype.on;
  271. JitsiConference.prototype.removeEventListener = JitsiConference.prototype.off;
  272. /**
  273. * Receives notifications from other participants about commands / custom events
  274. * (sent by sendCommand or sendCommandOnce methods).
  275. * @param command {String} the name of the command
  276. * @param handler {Function} handler for the command
  277. */
  278. JitsiConference.prototype.addCommandListener = function (command, handler) {
  279. if(this.room)
  280. this.room.addPresenceListener(command, handler);
  281. };
  282. /**
  283. * Removes command listener
  284. * @param command {String} the name of the command
  285. */
  286. JitsiConference.prototype.removeCommandListener = function (command) {
  287. if(this.room)
  288. this.room.removePresenceListener(command);
  289. };
  290. /**
  291. * Sends text message to the other participants in the conference
  292. * @param message the text message.
  293. */
  294. JitsiConference.prototype.sendTextMessage = function (message) {
  295. if(this.room)
  296. this.room.sendMessage(message);
  297. };
  298. /**
  299. * Send presence command.
  300. * @param name {String} the name of the command.
  301. * @param values {Object} with keys and values that will be sent.
  302. **/
  303. JitsiConference.prototype.sendCommand = function (name, values) {
  304. if(this.room) {
  305. this.room.addToPresence(name, values);
  306. this.room.sendPresence();
  307. }
  308. };
  309. /**
  310. * Send presence command one time.
  311. * @param name {String} the name of the command.
  312. * @param values {Object} with keys and values that will be sent.
  313. **/
  314. JitsiConference.prototype.sendCommandOnce = function (name, values) {
  315. this.sendCommand(name, values);
  316. this.removeCommand(name);
  317. };
  318. /**
  319. * Removes presence command.
  320. * @param name {String} the name of the command.
  321. **/
  322. JitsiConference.prototype.removeCommand = function (name) {
  323. if(this.room)
  324. this.room.removeFromPresence(name);
  325. };
  326. /**
  327. * Sets the display name for this conference.
  328. * @param name the display name to set
  329. */
  330. JitsiConference.prototype.setDisplayName = function(name) {
  331. if(this.room){
  332. // remove previously set nickname
  333. this.room.removeFromPresence("nick");
  334. this.room.addToPresence("nick", {attributes: {xmlns: 'http://jabber.org/protocol/nick'}, value: name});
  335. this.room.sendPresence();
  336. }
  337. };
  338. /**
  339. * Set new subject for this conference. (available only for moderator)
  340. * @param {string} subject new subject
  341. */
  342. JitsiConference.prototype.setSubject = function (subject) {
  343. if (this.room && this.isModerator()) {
  344. this.room.setSubject(subject);
  345. }
  346. };
  347. /**
  348. * Get a transcriber object for all current participants in this conference
  349. * @return {Transcriber} the transcriber object
  350. */
  351. JitsiConference.prototype.getTranscriber = function(){
  352. if(this.transcriber === undefined){
  353. this.transcriber = new Transcriber();
  354. //add all existing local audio tracks to the transcriber
  355. this.rtc.localTracks.forEach(function (localTrack) {
  356. if(localTrack.isAudioTrack()){
  357. this.transcriber.addTrack(localTrack);
  358. }
  359. }.bind(this));
  360. //and all remote audio tracks
  361. this.rtc.remoteTracks.forEach(function (remoteTrack){
  362. if(remoteTrack.isAudioTrack()){
  363. this.transcriber.addTrack(remoteTrack);
  364. }
  365. }.bind(this));
  366. }
  367. return this.transcriber;
  368. };
  369. /**
  370. * Adds JitsiLocalTrack object to the conference.
  371. * @param track the JitsiLocalTrack object.
  372. * @returns {Promise<JitsiLocalTrack>}
  373. * @throws {Error} if the specified track is a video track and there is already
  374. * another video track in the conference.
  375. */
  376. JitsiConference.prototype.addTrack = function (track) {
  377. if (track.isVideoTrack()) {
  378. // Ensure there's exactly 1 local video track in the conference.
  379. var localVideoTrack = this.rtc.getLocalVideoTrack();
  380. if (localVideoTrack) {
  381. // Don't be excessively harsh and severe if the API client happens
  382. // to attempt to add the same local video track twice.
  383. if (track === localVideoTrack) {
  384. return Promise.resolve(track);
  385. } else {
  386. return Promise.reject(new Error(
  387. "cannot add second video track to the conference"));
  388. }
  389. }
  390. }
  391. return this.replaceTrack(null, track);
  392. };
  393. /**
  394. * Fires TRACK_AUDIO_LEVEL_CHANGED change conference event.
  395. * @param audioLevel the audio level
  396. */
  397. JitsiConference.prototype._fireAudioLevelChangeEvent = function (audioLevel) {
  398. this.eventEmitter.emit(
  399. JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  400. this.myUserId(), audioLevel);
  401. };
  402. /**
  403. * Fires TRACK_MUTE_CHANGED change conference event.
  404. * @param track the JitsiTrack object related to the event.
  405. */
  406. JitsiConference.prototype._fireMuteChangeEvent = function (track) {
  407. // check if track was muted by focus and now is unmuted by user
  408. if (this.isMutedByFocus && track.isAudioTrack() && !track.isMuted()) {
  409. this.isMutedByFocus = false;
  410. // unmute local user on server
  411. this.room.muteParticipant(this.room.myroomjid, false);
  412. }
  413. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  414. };
  415. /**
  416. * Clear JitsiLocalTrack properties and listeners.
  417. * @param track the JitsiLocalTrack object.
  418. */
  419. JitsiConference.prototype.onTrackRemoved = function (track) {
  420. track._setSSRC(null);
  421. track._setConference(null);
  422. this.rtc.removeLocalTrack(track);
  423. track.removeEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
  424. track.muteHandler);
  425. track.removeEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  426. track.audioLevelHandler);
  427. this.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
  428. track.ssrcHandler);
  429. // send event for stopping screen sharing
  430. // FIXME: we assume we have only one screen sharing track
  431. // if we change this we need to fix this check
  432. if (track.isVideoTrack() && track.videoType === VideoType.DESKTOP)
  433. this.statistics.sendScreenSharingEvent(false);
  434. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  435. };
  436. /**
  437. * Removes JitsiLocalTrack from the conference and performs
  438. * a new offer/answer cycle.
  439. * @param track the JitsiLocalTrack object.
  440. * @returns {Promise}
  441. */
  442. JitsiConference.prototype.removeTrack = function (track) {
  443. return this.replaceTrack (track, null);
  444. };
  445. /**
  446. * Replaces oldTrack with newTrack and performs a single offer/answer
  447. * cycle after both operations are done. Either oldTrack or newTrack
  448. * can be null; replacing a valid 'oldTrack' with a null 'newTrack'
  449. * effectively just removes 'oldTrack'
  450. * @param {JitsiLocalTrack} oldTrack the current stream in use to be replaced
  451. * @param {JitsiLocalTrack} newTrack the new stream to use
  452. * @returns {Promise} resolves when the replacement is finished
  453. */
  454. JitsiConference.prototype.replaceTrack = function (oldTrack, newTrack) {
  455. // First do the removal of the oldTrack at the JitsiConference level
  456. if (oldTrack) {
  457. if (oldTrack.disposed) {
  458. return Promise.reject(
  459. new JitsiTrackError(JitsiTrackErrors.TRACK_IS_DISPOSED));
  460. }
  461. }
  462. if (newTrack) {
  463. if (newTrack.disposed) {
  464. return Promise.reject(
  465. new JitsiTrackError(JitsiTrackErrors.TRACK_IS_DISPOSED));
  466. }
  467. // Set up the ssrcHandler for the new track before we add it at the lower levels
  468. newTrack.ssrcHandler = function (conference, ssrcMap) {
  469. if (ssrcMap[this.getMSID()]) {
  470. this._setSSRC(ssrcMap[this.getMSID()]);
  471. conference.room.removeListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
  472. this.ssrcHandler);
  473. }
  474. }.bind(newTrack, this);
  475. this.room.addListener(XMPPEvents.SENDRECV_STREAMS_CHANGED,
  476. newTrack.ssrcHandler);
  477. }
  478. // Now replace the stream at the lower levels
  479. return this._doReplaceTrack(oldTrack, newTrack)
  480. .then(() => {
  481. if (oldTrack) {
  482. this.onTrackRemoved(oldTrack);
  483. }
  484. if (newTrack) {
  485. // Now handle the addition of the newTrack at the JitsiConference level
  486. this._setupNewTrack(newTrack);
  487. }
  488. return Promise.resolve();
  489. }, (error) => {
  490. return Promise.reject(new Error(error));
  491. });
  492. };
  493. /**
  494. * Replaces the tracks at the lower level by going through the Jingle session
  495. * and WebRTC peer connection. The method will resolve immediately if there is
  496. * currently no JingleSession started.
  497. * @param {JitsiLocalTrack|null} oldTrack the track to be removed during
  498. * the process or <tt>null</t> if the method should act as "add track"
  499. * @param {JitsiLocalTrackn|null} newTrack the new track to be added or
  500. * <tt>null</tt> if the method should act as "remove track"
  501. * @return {Promise}
  502. * @private
  503. */
  504. JitsiConference.prototype._doReplaceTrack = function (oldTrack, newTrack) {
  505. if (this.jingleSession) {
  506. return this.jingleSession.replaceStream(oldTrack, newTrack);
  507. } else {
  508. return Promise.resolve();
  509. }
  510. };
  511. /**
  512. * Operations related to creating a new track
  513. * @param {JitsiLocalTrack} newTrack the new track being created
  514. */
  515. JitsiConference.prototype._setupNewTrack = function (newTrack) {
  516. if (newTrack.isAudioTrack() || (newTrack.isVideoTrack() &&
  517. newTrack.videoType !== VideoType.DESKTOP)) {
  518. // Report active device to statistics
  519. var devices = RTC.getCurrentlyAvailableMediaDevices();
  520. var device = devices.find(function (d) {
  521. return d.kind === newTrack.getTrack().kind + 'input'
  522. && d.label === newTrack.getTrack().label;
  523. });
  524. if (device) {
  525. Statistics.sendActiveDeviceListEvent(
  526. RTC.getEventDataForActiveDevice(device));
  527. }
  528. }
  529. if (newTrack.isVideoTrack()) {
  530. this.removeCommand("videoType");
  531. this.sendCommand("videoType", {
  532. value: newTrack.videoType,
  533. attributes: {
  534. xmlns: 'http://jitsi.org/jitmeet/video'
  535. }
  536. });
  537. }
  538. this.rtc.addLocalTrack(newTrack);
  539. if (newTrack.startMuted) {
  540. newTrack.mute();
  541. }
  542. // ensure that we're sharing proper "is muted" state
  543. if (newTrack.isAudioTrack()) {
  544. this.room.setAudioMute(newTrack.isMuted());
  545. } else {
  546. this.room.setVideoMute(newTrack.isMuted());
  547. }
  548. newTrack.muteHandler = this._fireMuteChangeEvent.bind(this, newTrack);
  549. newTrack.audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
  550. newTrack.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
  551. newTrack.muteHandler);
  552. newTrack.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  553. newTrack.audioLevelHandler);
  554. newTrack._setConference(this);
  555. // send event for starting screen sharing
  556. // FIXME: we assume we have only one screen sharing track
  557. // if we change this we need to fix this check
  558. if (newTrack.isVideoTrack() && newTrack.videoType === VideoType.DESKTOP)
  559. this.statistics.sendScreenSharingEvent(true);
  560. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, newTrack);
  561. };
  562. /**
  563. * Adds loca WebRTC stream to the conference.
  564. * @param {MediaStream} stream new stream that will be added.
  565. * @param {function} callback callback executed after successful stream addition.
  566. * @param {function(error)} errorCallback callback executed if stream addition fail.
  567. * @param {object} ssrcInfo object with information about the SSRCs associated with the
  568. * stream.
  569. * @param {boolean} [dontModifySources] if true _modifySources won't be called.
  570. * Used for streams added before the call start.
  571. */
  572. JitsiConference.prototype.addLocalWebRTCStream
  573. = function (stream, callback, errorCallback, ssrcInfo, dontModifySources) {
  574. if(this.jingleSession) {
  575. this.jingleSession.addStream(
  576. stream, callback, errorCallback, ssrcInfo, dontModifySources);
  577. } else {
  578. // We are done immediately
  579. logger.warn("Add local MediaStream - no JingleSession started yet");
  580. callback();
  581. }
  582. };
  583. /**
  584. * Remove local WebRTC media stream.
  585. * @param {MediaStream} stream the stream that will be removed.
  586. * @param {function} callback callback executed after successful stream removal.
  587. * @param {function} errorCallback callback executed if stream removal fail.
  588. * @param {object} ssrcInfo object with information about the SSRCs associated
  589. * with the stream.
  590. */
  591. JitsiConference.prototype.removeLocalWebRTCStream
  592. = function (stream, callback, errorCallback, ssrcInfo) {
  593. if(this.jingleSession) {
  594. this.jingleSession.removeStream(
  595. stream, callback, errorCallback, ssrcInfo);
  596. } else {
  597. // We are done immediately
  598. logger.warn("Remove local MediaStream - no JingleSession started yet");
  599. callback();
  600. }
  601. };
  602. /**
  603. * Generate ssrc info object for a stream with the following properties:
  604. * - ssrcs - Array of the ssrcs associated with the stream.
  605. * - groups - Array of the groups associated with the stream.
  606. */
  607. JitsiConference.prototype._generateNewStreamSSRCInfo = function () {
  608. if(!this.jingleSession) {
  609. logger.warn("The call haven't been started. " +
  610. "Cannot generate ssrc info at the moment!");
  611. return null;
  612. }
  613. return this.jingleSession.generateNewStreamSSRCInfo();
  614. };
  615. /**
  616. * Get role of the local user.
  617. * @returns {string} user role: 'moderator' or 'none'
  618. */
  619. JitsiConference.prototype.getRole = function () {
  620. return this.room.role;
  621. };
  622. /**
  623. * Check if local user is moderator.
  624. * @returns {boolean|null} true if local user is moderator, false otherwise. If
  625. * we're no longer in the conference room then <tt>null</tt> is returned.
  626. */
  627. JitsiConference.prototype.isModerator = function () {
  628. return this.room ? this.room.isModerator() : null;
  629. };
  630. /**
  631. * Set password for the room.
  632. * @param {string} password new password for the room.
  633. * @returns {Promise}
  634. */
  635. JitsiConference.prototype.lock = function (password) {
  636. if (!this.isModerator()) {
  637. return Promise.reject();
  638. }
  639. var conference = this;
  640. return new Promise(function (resolve, reject) {
  641. conference.room.lockRoom(password || "", function () {
  642. resolve();
  643. }, function (err) {
  644. reject(err);
  645. }, function () {
  646. reject(JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED);
  647. });
  648. });
  649. };
  650. /**
  651. * Remove password from the room.
  652. * @returns {Promise}
  653. */
  654. JitsiConference.prototype.unlock = function () {
  655. return this.lock();
  656. };
  657. /**
  658. * Elects the participant with the given id to be the selected participant in
  659. * order to receive higher video quality (if simulcast is enabled).
  660. * Or cache it if channel is not created and send it once channel is available.
  661. * @param participantId the identifier of the participant
  662. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  663. */
  664. JitsiConference.prototype.selectParticipant = function(participantId) {
  665. this.rtc.selectEndpoint(participantId);
  666. };
  667. /**
  668. * Elects the participant with the given id to be the pinned participant in
  669. * order to always receive video for this participant (even when last n is
  670. * enabled).
  671. * @param participantId the identifier of the participant
  672. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  673. */
  674. JitsiConference.prototype.pinParticipant = function(participantId) {
  675. this.rtc.pinEndpoint(participantId);
  676. };
  677. /**
  678. * Selects a new value for "lastN". The requested amount of videos are going
  679. * to be delivered after the value is in effect. Set to -1 for unlimited or
  680. * all available videos.
  681. * @param lastN the new number of videos the user would like to receive.
  682. * @throws Error or RangeError if the given value is not a number or is smaller
  683. * than -1.
  684. */
  685. JitsiConference.prototype.setLastN = function(lastN) {
  686. if (!Number.isInteger(lastN) && !Number.parseInt(lastN)) {
  687. throw new Error('Invalid value for lastN: ' + lastN);
  688. }
  689. if (lastN < -1) {
  690. throw new RangeError('lastN cannot be smaller than -1');
  691. }
  692. this.rtc.setLastN(lastN | 0);
  693. };
  694. /**
  695. * @return Array<JitsiParticipant> an array of all participants in this
  696. * conference.
  697. */
  698. JitsiConference.prototype.getParticipants = function() {
  699. return Object.keys(this.participants).map(function (key) {
  700. return this.participants[key];
  701. }, this);
  702. };
  703. /**
  704. * Returns the number of participants in the conference, including the local
  705. * participant.
  706. * @param countHidden {boolean} Whether or not to include hidden participants
  707. * in the count. Default: false.
  708. **/
  709. JitsiConference.prototype.getParticipantCount
  710. = function(countHidden = false) {
  711. let participants = this.getParticipants();
  712. if (!countHidden) {
  713. participants = participants.filter(p => !p.isHidden());
  714. }
  715. // Add one for the local participant.
  716. return participants.length + 1;
  717. };
  718. /**
  719. * @returns {JitsiParticipant} the participant in this conference with the
  720. * specified id (or undefined if there isn't one).
  721. * @param id the id of the participant.
  722. */
  723. JitsiConference.prototype.getParticipantById = function(id) {
  724. return this.participants[id];
  725. };
  726. /**
  727. * Kick participant from this conference.
  728. * @param {string} id id of the participant to kick
  729. */
  730. JitsiConference.prototype.kickParticipant = function (id) {
  731. var participant = this.getParticipantById(id);
  732. if (!participant) {
  733. return;
  734. }
  735. this.room.kick(participant.getJid());
  736. };
  737. /**
  738. * Mutes a participant.
  739. * @param {string} id The id of the participant to mute.
  740. */
  741. JitsiConference.prototype.muteParticipant = function (id) {
  742. var participant = this.getParticipantById(id);
  743. if (!participant) {
  744. return;
  745. }
  746. this.room.muteParticipant(participant.getJid(), true);
  747. };
  748. /**
  749. * Notifies this JitsiConference that a new member has joined its chat room.
  750. *
  751. * FIXME This should NOT be exposed!
  752. *
  753. * @param jid the jid of the participant in the MUC
  754. * @param nick the display name of the participant
  755. * @param role the role of the participant in the MUC
  756. * @param isHidden indicates if this is a hidden participant (system
  757. * participant for example a recorder).
  758. */
  759. JitsiConference.prototype.onMemberJoined
  760. = function (jid, nick, role, isHidden) {
  761. var id = Strophe.getResourceFromJid(jid);
  762. if (id === 'focus' || this.myUserId() === id) {
  763. return;
  764. }
  765. var participant = new JitsiParticipant(jid, this, nick, isHidden);
  766. participant._role = role;
  767. this.participants[id] = participant;
  768. this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
  769. this.xmpp.caps.getFeatures(jid).then(features => {
  770. participant._supportsDTMF = features.has("urn:xmpp:jingle:dtmf:0");
  771. this.updateDTMFSupport();
  772. }, error => logger.error(error));
  773. };
  774. JitsiConference.prototype.onMemberLeft = function (jid) {
  775. var id = Strophe.getResourceFromJid(jid);
  776. if (id === 'focus' || this.myUserId() === id) {
  777. return;
  778. }
  779. var participant = this.participants[id];
  780. delete this.participants[id];
  781. var removedTracks = this.rtc.removeRemoteTracks(id);
  782. removedTracks.forEach(function (track) {
  783. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  784. }.bind(this));
  785. // there can be no participant in case the member that left is focus
  786. if (participant)
  787. this.eventEmitter.emit(
  788. JitsiConferenceEvents.USER_LEFT, id, participant);
  789. };
  790. JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
  791. var id = Strophe.getResourceFromJid(jid);
  792. var participant = this.getParticipantById(id);
  793. if (!participant) {
  794. return;
  795. }
  796. participant._role = role;
  797. this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
  798. };
  799. JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
  800. var id = Strophe.getResourceFromJid(jid);
  801. var participant = this.getParticipantById(id);
  802. if (!participant) {
  803. return;
  804. }
  805. if (participant._displayName === displayName)
  806. return;
  807. participant._displayName = displayName;
  808. this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
  809. };
  810. /**
  811. * Notifies this JitsiConference that a JitsiRemoteTrack was added (into the
  812. * ChatRoom of this JitsiConference).
  813. *
  814. * @param {JitsiRemoteTrack} track the JitsiRemoteTrack which was added to this
  815. * JitsiConference
  816. */
  817. JitsiConference.prototype.onTrackAdded = function (track) {
  818. var id = track.getParticipantId();
  819. var participant = this.getParticipantById(id);
  820. if (!participant) {
  821. return;
  822. }
  823. // Add track to JitsiParticipant.
  824. participant._tracks.push(track);
  825. if(this.transcriber){
  826. this.transcriber.addTrack(track);
  827. }
  828. var emitter = this.eventEmitter;
  829. track.addEventListener(
  830. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  831. function () {
  832. emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  833. }
  834. );
  835. track.addEventListener(
  836. JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  837. function (audioLevel) {
  838. emitter.emit(
  839. JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  840. id,
  841. audioLevel);
  842. }
  843. );
  844. emitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  845. };
  846. /**
  847. * Handles incoming call event.
  848. */
  849. JitsiConference.prototype.onIncomingCall =
  850. function (jingleSession, jingleOffer, now) {
  851. if (!this.room.isFocus(jingleSession.peerjid)) {
  852. // Error cause this should never happen unless something is wrong!
  853. var errmsg = "Rejecting session-initiate from non-focus user: "
  854. + jingleSession.peerjid;
  855. GlobalOnErrorHandler.callErrorHandler(new Error(errmsg));
  856. logger.error(errmsg);
  857. // Terminate the jingle session with a reason
  858. jingleSession.terminate(
  859. 'security-error', 'Only focus can start new sessions',
  860. null /* success callback => we don't care */,
  861. function (error) {
  862. logger.warn(
  863. "An error occurred while trying to terminate"
  864. + " invalid Jingle session", error);
  865. });
  866. return;
  867. }
  868. // Accept incoming call
  869. this.jingleSession = jingleSession;
  870. this.room.connectionTimes["session.initiate"] = now;
  871. // Log "session.restart"
  872. if (this.wasStopped) {
  873. Statistics.sendEventToAll("session.restart");
  874. }
  875. // add info whether call is cross-region
  876. var crossRegion = null;
  877. if (window.jitsiRegionInfo) {
  878. crossRegion = window.jitsiRegionInfo["CrossRegion"];
  879. }
  880. Statistics.analytics.sendEvent(
  881. "session.initiate", {
  882. value: now - this.room.connectionTimes["muc.joined"],
  883. label: crossRegion
  884. });
  885. try {
  886. jingleSession.initialize(false /* initiator */,this.room);
  887. } catch (error) {
  888. GlobalOnErrorHandler.callErrorHandler(error);
  889. }
  890. this.rtc.initializeDataChannels(jingleSession.peerconnection);
  891. // Add local Tracks to the ChatRoom
  892. this.rtc.localTracks.forEach(function(localTrack) {
  893. var ssrcInfo = null;
  894. /**
  895. * We don't do this for Firefox because, on Firefox, we keep the
  896. * stream in the peer connection and just set 'enabled' on the
  897. * track to false (see JitsiLocalTrack::_setMute). This means
  898. * that if we generated an ssrc here and set it in the cache, it
  899. * would clash with the one firefox generates (since, unlike chrome,
  900. * the stream is still attached to the peer connection) and causes
  901. * problems between sdp-interop and trying to keep the ssrcs
  902. * consistent
  903. */
  904. if(localTrack.isVideoTrack() && localTrack.isMuted() && !RTCBrowserType.isFirefox()) {
  905. /**
  906. * Handles issues when the stream is added before the peerconnection
  907. * is created. The peerconnection is created when second participant
  908. * enters the call. In that use case the track doesn't have
  909. * information about it's ssrcs and no jingle packets are sent. That
  910. * can cause inconsistent behavior later.
  911. *
  912. * For example:
  913. * If we mute the stream and than second participant enter it's
  914. * remote SDP won't include that track. On unmute we are not sending
  915. * any jingle packets which will brake the unmute.
  916. *
  917. * In order to solve issues like the above one here we have to
  918. * generate the ssrc information for the track .
  919. */
  920. localTrack._setSSRC(this._generateNewStreamSSRCInfo());
  921. ssrcInfo = {
  922. mtype: localTrack.getType(),
  923. type: "addMuted",
  924. ssrc: localTrack.ssrc,
  925. msid: localTrack.initialMSID
  926. };
  927. }
  928. try {
  929. this.addLocalWebRTCStream(
  930. localTrack.getOriginalStream(), function () {}, function () {},
  931. ssrcInfo, true /* don't modify SSRCs */);
  932. } catch(e) {
  933. GlobalOnErrorHandler.callErrorHandler(e);
  934. logger.error(e);
  935. }
  936. }.bind(this));
  937. // Generate the 'recvonly' SSRC in case there are no video tracks
  938. if (!this.getLocalTracks(MediaType.VIDEO).length) {
  939. this.room.generateRecvonlySsrc();
  940. }
  941. jingleSession.acceptOffer(jingleOffer, null,
  942. function (error) {
  943. GlobalOnErrorHandler.callErrorHandler(error);
  944. logger.error(
  945. "Failed to accept incoming Jingle session", error);
  946. }
  947. );
  948. // Start callstats as soon as peerconnection is initialized,
  949. // do not wait for XMPPEvents.PEERCONNECTION_READY, as it may never
  950. // happen in case if user doesn't have or denied permission to
  951. // both camera and microphone.
  952. this.statistics.startCallStats(jingleSession);
  953. this.statistics.startRemoteStats(jingleSession.peerconnection);
  954. };
  955. /**
  956. * Handles the call ended event.
  957. * @param {JingleSessionPC} JingleSession the jingle session which has been
  958. * terminated.
  959. * @param {String} reasonCondition the Jingle reason condition.
  960. * @param {String|null} reasonText human readable reason text which may provide
  961. * more details about why the call has been terminated.
  962. */
  963. JitsiConference.prototype.onCallEnded
  964. = function (JingleSession, reasonCondition, reasonText) {
  965. logger.info("Call ended: " + reasonCondition + " - " + reasonText);
  966. this.wasStopped = true;
  967. // Send session.terminate event
  968. Statistics.sendEventToAll("session.terminate");
  969. // Stop the stats
  970. if (this.statistics) {
  971. this.statistics.stopRemoteStats();
  972. this.statistics.stopCallStats();
  973. }
  974. // Current JingleSession is invalid so set it to null on the room
  975. this.jingleSession = null;
  976. // Let the RTC service do any cleanups
  977. this.rtc.onCallEnded();
  978. // PeerConnection has been closed which means that SSRCs stored in
  979. // JitsiLocalTrack will not match those assigned by the old PeerConnection
  980. // and SSRC replacement logic will not work as expected.
  981. // We want to re-register 'ssrcHandler' of our local tracks, so that they
  982. // will learn what their SSRC from the new PeerConnection which will be
  983. // created on incoming call event.
  984. var self = this;
  985. this.rtc.localTracks.forEach(function(localTrack) {
  986. // Reset SSRC as it will no longer be valid
  987. localTrack._setSSRC(null);
  988. // Bind the handler to fetch new SSRC, it will un register itself once
  989. // it reads the values
  990. self.room.addListener(
  991. XMPPEvents.SENDRECV_STREAMS_CHANGED, localTrack.ssrcHandler);
  992. });
  993. };
  994. /**
  995. * Handles the suspend detected event. Leaves the room and fires suspended.
  996. */
  997. JitsiConference.prototype.onSuspendDetected = function () {
  998. this.leave();
  999. this.eventEmitter.emit(JitsiConferenceEvents.SUSPEND_DETECTED);
  1000. };
  1001. JitsiConference.prototype.updateDTMFSupport = function () {
  1002. var somebodySupportsDTMF = false;
  1003. var participants = this.getParticipants();
  1004. // check if at least 1 participant supports DTMF
  1005. for (var i = 0; i < participants.length; i += 1) {
  1006. if (participants[i].supportsDTMF()) {
  1007. somebodySupportsDTMF = true;
  1008. break;
  1009. }
  1010. }
  1011. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  1012. this.somebodySupportsDTMF = somebodySupportsDTMF;
  1013. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  1014. }
  1015. };
  1016. /**
  1017. * Allows to check if there is at least one user in the conference
  1018. * that supports DTMF.
  1019. * @returns {boolean} true if somebody supports DTMF, false otherwise
  1020. */
  1021. JitsiConference.prototype.isDTMFSupported = function () {
  1022. return this.somebodySupportsDTMF;
  1023. };
  1024. /**
  1025. * Returns the local user's ID
  1026. * @return {string} local user's ID
  1027. */
  1028. JitsiConference.prototype.myUserId = function () {
  1029. return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  1030. };
  1031. JitsiConference.prototype.sendTones = function (tones, duration, pause) {
  1032. if (!this.dtmfManager) {
  1033. var connection = this.xmpp.connection.jingle.activecall.peerconnection;
  1034. if (!connection) {
  1035. logger.warn("cannot sendTones: no conneciton");
  1036. return;
  1037. }
  1038. var tracks = this.getLocalTracks().filter(function (track) {
  1039. return track.isAudioTrack();
  1040. });
  1041. if (!tracks.length) {
  1042. logger.warn("cannot sendTones: no local audio stream");
  1043. return;
  1044. }
  1045. this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
  1046. }
  1047. this.dtmfManager.sendTones(tones, duration, pause);
  1048. };
  1049. /**
  1050. * Returns true if recording is supported and false if not.
  1051. */
  1052. JitsiConference.prototype.isRecordingSupported = function () {
  1053. if(this.room)
  1054. return this.room.isRecordingSupported();
  1055. return false;
  1056. };
  1057. /**
  1058. * Returns null if the recording is not supported, "on" if the recording started
  1059. * and "off" if the recording is not started.
  1060. */
  1061. JitsiConference.prototype.getRecordingState = function () {
  1062. return (this.room) ? this.room.getRecordingState() : undefined;
  1063. };
  1064. /**
  1065. * Returns the url of the recorded video.
  1066. */
  1067. JitsiConference.prototype.getRecordingURL = function () {
  1068. return (this.room) ? this.room.getRecordingURL() : null;
  1069. };
  1070. /**
  1071. * Starts/stops the recording
  1072. */
  1073. JitsiConference.prototype.toggleRecording = function (options) {
  1074. if(this.room)
  1075. return this.room.toggleRecording(options, function (status, error) {
  1076. this.eventEmitter.emit(
  1077. JitsiConferenceEvents.RECORDER_STATE_CHANGED, status, error);
  1078. }.bind(this));
  1079. this.eventEmitter.emit(
  1080. JitsiConferenceEvents.RECORDER_STATE_CHANGED, "error",
  1081. new Error("The conference is not created yet!"));
  1082. };
  1083. /**
  1084. * Returns true if the SIP calls are supported and false otherwise
  1085. */
  1086. JitsiConference.prototype.isSIPCallingSupported = function () {
  1087. if(this.room)
  1088. return this.room.isSIPCallingSupported();
  1089. return false;
  1090. };
  1091. /**
  1092. * Dials a number.
  1093. * @param number the number
  1094. */
  1095. JitsiConference.prototype.dial = function (number) {
  1096. if(this.room)
  1097. return this.room.dial(number);
  1098. return new Promise(function(resolve, reject){
  1099. reject(new Error("The conference is not created yet!"));});
  1100. };
  1101. /**
  1102. * Hangup an existing call
  1103. */
  1104. JitsiConference.prototype.hangup = function () {
  1105. if(this.room)
  1106. return this.room.hangup();
  1107. return new Promise(function(resolve, reject){
  1108. reject(new Error("The conference is not created yet!"));});
  1109. };
  1110. /**
  1111. * Returns the phone number for joining the conference.
  1112. */
  1113. JitsiConference.prototype.getPhoneNumber = function () {
  1114. if(this.room)
  1115. return this.room.getPhoneNumber();
  1116. return null;
  1117. };
  1118. /**
  1119. * Returns the pin for joining the conference with phone.
  1120. */
  1121. JitsiConference.prototype.getPhonePin = function () {
  1122. if(this.room)
  1123. return this.room.getPhonePin();
  1124. return null;
  1125. };
  1126. /**
  1127. * Returns the connection state for the current room. Its ice connection state
  1128. * for its session.
  1129. */
  1130. JitsiConference.prototype.getConnectionState = function () {
  1131. if(this.jingleSession)
  1132. return this.jingleSession.getIceConnectionState();
  1133. return null;
  1134. };
  1135. /**
  1136. * Make all new participants mute their audio/video on join.
  1137. * @param policy {Object} object with 2 boolean properties for video and audio:
  1138. * @param {boolean} audio if audio should be muted.
  1139. * @param {boolean} video if video should be muted.
  1140. */
  1141. JitsiConference.prototype.setStartMutedPolicy = function (policy) {
  1142. if (!this.isModerator()) {
  1143. return;
  1144. }
  1145. this.startMutedPolicy = policy;
  1146. this.room.removeFromPresence("startmuted");
  1147. this.room.addToPresence("startmuted", {
  1148. attributes: {
  1149. audio: policy.audio,
  1150. video: policy.video,
  1151. xmlns: 'http://jitsi.org/jitmeet/start-muted'
  1152. }
  1153. });
  1154. this.room.sendPresence();
  1155. };
  1156. /**
  1157. * Returns current start muted policy
  1158. * @returns {Object} with 2 properties - audio and video.
  1159. */
  1160. JitsiConference.prototype.getStartMutedPolicy = function () {
  1161. return this.startMutedPolicy;
  1162. };
  1163. /**
  1164. * Check if audio is muted on join.
  1165. */
  1166. JitsiConference.prototype.isStartAudioMuted = function () {
  1167. return this.startAudioMuted;
  1168. };
  1169. /**
  1170. * Check if video is muted on join.
  1171. */
  1172. JitsiConference.prototype.isStartVideoMuted = function () {
  1173. return this.startVideoMuted;
  1174. };
  1175. /**
  1176. * Get object with internal logs.
  1177. */
  1178. JitsiConference.prototype.getLogs = function () {
  1179. var data = this.xmpp.getJingleLog();
  1180. var metadata = {};
  1181. metadata.time = new Date();
  1182. metadata.url = window.location.href;
  1183. metadata.ua = navigator.userAgent;
  1184. var log = this.xmpp.getXmppLog();
  1185. if (log) {
  1186. metadata.xmpp = log;
  1187. }
  1188. data.metadata = metadata;
  1189. return data;
  1190. };
  1191. /**
  1192. * Returns measured connectionTimes.
  1193. */
  1194. JitsiConference.prototype.getConnectionTimes = function () {
  1195. return this.room.connectionTimes;
  1196. };
  1197. /**
  1198. * Sets a property for the local participant.
  1199. */
  1200. JitsiConference.prototype.setLocalParticipantProperty = function(name, value) {
  1201. this.sendCommand("jitsi_participant_" + name, {value: value});
  1202. };
  1203. /**
  1204. * Sends the given feedback through CallStats if enabled.
  1205. *
  1206. * @param overallFeedback an integer between 1 and 5 indicating the
  1207. * user feedback
  1208. * @param detailedFeedback detailed feedback from the user. Not yet used
  1209. */
  1210. JitsiConference.prototype.sendFeedback =
  1211. function(overallFeedback, detailedFeedback){
  1212. this.statistics.sendFeedback(overallFeedback, detailedFeedback);
  1213. };
  1214. /**
  1215. * Returns true if the callstats integration is enabled, otherwise returns
  1216. * false.
  1217. *
  1218. * @returns true if the callstats integration is enabled, otherwise returns
  1219. * false.
  1220. */
  1221. JitsiConference.prototype.isCallstatsEnabled = function () {
  1222. return this.statistics.isCallstatsEnabled();
  1223. };
  1224. /**
  1225. * Handles track attached to container (Calls associateStreamWithVideoTag method
  1226. * from statistics module)
  1227. * @param track the track
  1228. * @param container the container
  1229. */
  1230. JitsiConference.prototype._onTrackAttach = function(track, container) {
  1231. var ssrc = track.getSSRC();
  1232. if (!container.id || !ssrc) {
  1233. return;
  1234. }
  1235. this.statistics.associateStreamWithVideoTag(
  1236. ssrc, track.isLocal(), track.getUsageLabel(), container.id);
  1237. };
  1238. /**
  1239. * Logs an "application log" message.
  1240. * @param message {string} The message to log. Note that while this can be a
  1241. * generic string, the convention used by lib-jitsi-meet and jitsi-meet is to
  1242. * log valid JSON strings, with an "id" field used for distinguishing between
  1243. * message types. E.g.: {id: "recorder_status", status: "off"}
  1244. */
  1245. JitsiConference.prototype.sendApplicationLog = function(message) {
  1246. Statistics.sendLog(message);
  1247. };
  1248. /**
  1249. * Checks if the user identified by given <tt>mucJid</tt> is the conference
  1250. * focus.
  1251. * @param mucJid the full MUC address of the user to be checked.
  1252. * @returns {boolean|null} <tt>true</tt> if MUC user is the conference focus,
  1253. * <tt>false</tt> when is not. <tt>null</tt> if we're not in the MUC anymore and
  1254. * are unable to figure out the status or if given <tt>mucJid</tt> is invalid.
  1255. */
  1256. JitsiConference.prototype._isFocus = function (mucJid) {
  1257. return this.room ? this.room.isFocus(mucJid) : null;
  1258. };
  1259. /**
  1260. * Fires CONFERENCE_FAILED event with INCOMPATIBLE_SERVER_VERSIONS parameter
  1261. */
  1262. JitsiConference.prototype._fireIncompatibleVersionsEvent = function () {
  1263. this.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  1264. JitsiConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS);
  1265. };
  1266. /**
  1267. * Sends a message via the data channel.
  1268. * @param to {string} the id of the endpoint that should receive the message.
  1269. * If "" the message will be sent to all participants.
  1270. * @param payload {object} the payload of the message.
  1271. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  1272. */
  1273. JitsiConference.prototype.sendEndpointMessage = function (to, payload) {
  1274. this.rtc.sendDataChannelMessage(to, payload);
  1275. };
  1276. /**
  1277. * Sends a broadcast message via the data channel.
  1278. * @param payload {object} the payload of the message.
  1279. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  1280. */
  1281. JitsiConference.prototype.broadcastEndpointMessage = function (payload) {
  1282. this.sendEndpointMessage("", payload);
  1283. };
  1284. JitsiConference.prototype.isConnectionInterrupted = function () {
  1285. return this.connectionIsInterrupted;
  1286. };
  1287. module.exports = JitsiConference;