選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

JitsiConference.js 49KB

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