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

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