Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

JitsiConference.js 49KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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 => Promise.reject(new Error(error)));
  509. };
  510. /**
  511. * Replaces the tracks at the lower level by going through the Jingle session
  512. * and WebRTC peer connection. The method will resolve immediately if there is
  513. * currently no JingleSession started.
  514. * @param {JitsiLocalTrack|null} oldTrack the track to be removed during
  515. * the process or <tt>null</t> if the method should act as "add track"
  516. * @param {JitsiLocalTrack|null} newTrack the new track to be added or
  517. * <tt>null</tt> if the method should act as "remove track"
  518. * @return {Promise}
  519. * @private
  520. */
  521. JitsiConference.prototype._doReplaceTrack = function(oldTrack, newTrack) {
  522. if (this.jingleSession) {
  523. return this.jingleSession.replaceTrack(oldTrack, newTrack);
  524. } else {
  525. return Promise.resolve();
  526. }
  527. };
  528. /**
  529. * Operations related to creating a new track
  530. * @param {JitsiLocalTrack} newTrack the new track being created
  531. */
  532. JitsiConference.prototype._setupNewTrack = function(newTrack) {
  533. if (newTrack.isAudioTrack() || (newTrack.isVideoTrack() &&
  534. newTrack.videoType !== VideoType.DESKTOP)) {
  535. // Report active device to statistics
  536. var devices = RTC.getCurrentlyAvailableMediaDevices();
  537. var device = devices.find(function(d) {
  538. return d.kind === newTrack.getTrack().kind + 'input'
  539. && d.label === newTrack.getTrack().label;
  540. });
  541. if (device) {
  542. Statistics.sendActiveDeviceListEvent(
  543. RTC.getEventDataForActiveDevice(device));
  544. }
  545. }
  546. if (newTrack.isVideoTrack()) {
  547. this.removeCommand("videoType");
  548. this.sendCommand("videoType", {
  549. value: newTrack.videoType,
  550. attributes: {
  551. xmlns: 'http://jitsi.org/jitmeet/video'
  552. }
  553. });
  554. }
  555. this.rtc.addLocalTrack(newTrack);
  556. if (newTrack.startMuted) {
  557. newTrack.mute();
  558. }
  559. // ensure that we're sharing proper "is muted" state
  560. if (newTrack.isAudioTrack()) {
  561. this.room.setAudioMute(newTrack.isMuted());
  562. } else {
  563. this.room.setVideoMute(newTrack.isMuted());
  564. }
  565. newTrack.muteHandler = this._fireMuteChangeEvent.bind(this, newTrack);
  566. newTrack.audioLevelHandler = this._fireAudioLevelChangeEvent.bind(this);
  567. newTrack.addEventListener(JitsiTrackEvents.TRACK_MUTE_CHANGED,
  568. newTrack.muteHandler);
  569. newTrack.addEventListener(JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  570. newTrack.audioLevelHandler);
  571. newTrack._setConference(this);
  572. // send event for starting screen sharing
  573. // FIXME: we assume we have only one screen sharing track
  574. // if we change this we need to fix this check
  575. if (newTrack.isVideoTrack() && newTrack.videoType === VideoType.DESKTOP) {
  576. this.statistics.sendScreenSharingEvent(true);
  577. }
  578. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_ADDED, newTrack);
  579. };
  580. /**
  581. * Adds loca WebRTC stream to the conference.
  582. * @param {MediaStream} stream new stream that will be added.
  583. * @param {function} callback callback executed after successful stream addition.
  584. * @param {function(error)} errorCallback callback executed if stream addition fail.
  585. * @param {object} ssrcInfo object with information about the SSRCs associated with the
  586. * stream.
  587. * @param {boolean} [dontModifySources] if <tt>true</tt> _modifySources won't be
  588. * called. The option is used for adding stream, before the Jingle call is
  589. * started. That is before the 'session-accept' is sent.
  590. */
  591. JitsiConference.prototype._addLocalStream
  592. = function(stream, callback, errorCallback, ssrcInfo, dontModifySources) {
  593. if (this.jingleSession) {
  594. this.jingleSession.addStream(
  595. stream, callback, errorCallback, ssrcInfo, dontModifySources);
  596. } else {
  597. // We are done immediately
  598. logger.warn("Add local MediaStream - no JingleSession started yet");
  599. callback();
  600. }
  601. };
  602. /**
  603. * Remove local WebRTC media stream.
  604. * @param {MediaStream} stream the stream that will be removed.
  605. * @param {function} callback callback executed after successful stream removal.
  606. * @param {function} errorCallback callback executed if stream removal fail.
  607. * @param {object} ssrcInfo object with information about the SSRCs associated
  608. * with the stream.
  609. */
  610. JitsiConference.prototype.removeLocalStream
  611. = function(stream, callback, errorCallback, ssrcInfo) {
  612. if (this.jingleSession) {
  613. this.jingleSession.removeStream(
  614. stream, callback, errorCallback, ssrcInfo);
  615. } else {
  616. // We are done immediately
  617. logger.warn("Remove local MediaStream - no JingleSession started yet");
  618. callback();
  619. }
  620. };
  621. /**
  622. * Generate ssrc info object for a stream with the following properties:
  623. * - ssrcs - Array of the ssrcs associated with the stream.
  624. * - groups - Array of the groups associated with the stream.
  625. */
  626. JitsiConference.prototype._generateNewStreamSSRCInfo = function() {
  627. if (!this.jingleSession) {
  628. logger.warn("The call haven't been started. " +
  629. "Cannot generate ssrc info at the moment!");
  630. return null;
  631. }
  632. return this.jingleSession.generateNewStreamSSRCInfo();
  633. };
  634. /**
  635. * Get role of the local user.
  636. * @returns {string} user role: 'moderator' or 'none'
  637. */
  638. JitsiConference.prototype.getRole = function() {
  639. return this.room.role;
  640. };
  641. /**
  642. * Check if local user is moderator.
  643. * @returns {boolean|null} true if local user is moderator, false otherwise. If
  644. * we're no longer in the conference room then <tt>null</tt> is returned.
  645. */
  646. JitsiConference.prototype.isModerator = function() {
  647. return this.room ? this.room.isModerator() : null;
  648. };
  649. /**
  650. * Set password for the room.
  651. * @param {string} password new password for the room.
  652. * @returns {Promise}
  653. */
  654. JitsiConference.prototype.lock = function(password) {
  655. if (!this.isModerator()) {
  656. return Promise.reject();
  657. }
  658. var conference = this;
  659. return new Promise(function(resolve, reject) {
  660. conference.room.lockRoom(password || "", function() {
  661. resolve();
  662. }, function(err) {
  663. reject(err);
  664. }, function() {
  665. reject(JitsiConferenceErrors.PASSWORD_NOT_SUPPORTED);
  666. });
  667. });
  668. };
  669. /**
  670. * Remove password from the room.
  671. * @returns {Promise}
  672. */
  673. JitsiConference.prototype.unlock = function() {
  674. return this.lock();
  675. };
  676. /**
  677. * Elects the participant with the given id to be the selected participant in
  678. * order to receive higher video quality (if simulcast is enabled).
  679. * Or cache it if channel is not created and send it once channel is available.
  680. * @param participantId the identifier of the participant
  681. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  682. */
  683. JitsiConference.prototype.selectParticipant = function(participantId) {
  684. this.rtc.selectEndpoint(participantId);
  685. };
  686. /**
  687. * Elects the participant with the given id to be the pinned participant in
  688. * order to always receive video for this participant (even when last n is
  689. * enabled).
  690. * @param participantId the identifier of the participant
  691. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  692. */
  693. JitsiConference.prototype.pinParticipant = function(participantId) {
  694. this.rtc.pinEndpoint(participantId);
  695. };
  696. /**
  697. * Selects a new value for "lastN". The requested amount of videos are going
  698. * to be delivered after the value is in effect. Set to -1 for unlimited or
  699. * all available videos.
  700. * @param lastN the new number of videos the user would like to receive.
  701. * @throws Error or RangeError if the given value is not a number or is smaller
  702. * than -1.
  703. */
  704. JitsiConference.prototype.setLastN = function(lastN) {
  705. if (!Number.isInteger(lastN) && !Number.parseInt(lastN)) {
  706. throw new Error('Invalid value for lastN: ' + lastN);
  707. }
  708. if (lastN < -1) {
  709. throw new RangeError('lastN cannot be smaller than -1');
  710. }
  711. this.rtc.setLastN(lastN | 0);
  712. };
  713. /**
  714. * @return Array<JitsiParticipant> an array of all participants in this
  715. * conference.
  716. */
  717. JitsiConference.prototype.getParticipants = function() {
  718. return Object.keys(this.participants).map(function(key) {
  719. return this.participants[key];
  720. }, this);
  721. };
  722. /**
  723. * Returns the number of participants in the conference, including the local
  724. * participant.
  725. * @param countHidden {boolean} Whether or not to include hidden participants
  726. * in the count. Default: false.
  727. **/
  728. JitsiConference.prototype.getParticipantCount
  729. = function(countHidden = false) {
  730. let participants = this.getParticipants();
  731. if (!countHidden) {
  732. participants = participants.filter(p => !p.isHidden());
  733. }
  734. // Add one for the local participant.
  735. return participants.length + 1;
  736. };
  737. /**
  738. * @returns {JitsiParticipant} the participant in this conference with the
  739. * specified id (or undefined if there isn't one).
  740. * @param id the id of the participant.
  741. */
  742. JitsiConference.prototype.getParticipantById = function(id) {
  743. return this.participants[id];
  744. };
  745. /**
  746. * Kick participant from this conference.
  747. * @param {string} id id of the participant to kick
  748. */
  749. JitsiConference.prototype.kickParticipant = function(id) {
  750. var participant = this.getParticipantById(id);
  751. if (!participant) {
  752. return;
  753. }
  754. this.room.kick(participant.getJid());
  755. };
  756. /**
  757. * Mutes a participant.
  758. * @param {string} id The id of the participant to mute.
  759. */
  760. JitsiConference.prototype.muteParticipant = function(id) {
  761. var participant = this.getParticipantById(id);
  762. if (!participant) {
  763. return;
  764. }
  765. this.room.muteParticipant(participant.getJid(), true);
  766. };
  767. /**
  768. * Notifies this JitsiConference that a new member has joined its chat room.
  769. *
  770. * FIXME This should NOT be exposed!
  771. *
  772. * @param jid the jid of the participant in the MUC
  773. * @param nick the display name of the participant
  774. * @param role the role of the participant in the MUC
  775. * @param isHidden indicates if this is a hidden participant (system
  776. * participant for example a recorder).
  777. */
  778. JitsiConference.prototype.onMemberJoined
  779. = function(jid, nick, role, isHidden) {
  780. var id = Strophe.getResourceFromJid(jid);
  781. if (id === 'focus' || this.myUserId() === id) {
  782. return;
  783. }
  784. var participant = new JitsiParticipant(jid, this, nick, isHidden);
  785. participant._role = role;
  786. this.participants[id] = participant;
  787. this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
  788. this.xmpp.caps.getFeatures(jid).then(features => {
  789. participant._supportsDTMF = features.has("urn:xmpp:jingle:dtmf:0");
  790. this.updateDTMFSupport();
  791. }, error => logger.error(error));
  792. };
  793. JitsiConference.prototype.onMemberLeft = function(jid) {
  794. var id = Strophe.getResourceFromJid(jid);
  795. if (id === 'focus' || this.myUserId() === id) {
  796. return;
  797. }
  798. var participant = this.participants[id];
  799. delete this.participants[id];
  800. var removedTracks = this.rtc.removeRemoteTracks(id);
  801. removedTracks.forEach(function(track) {
  802. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  803. }.bind(this));
  804. // there can be no participant in case the member that left is focus
  805. if (participant) {
  806. this.eventEmitter.emit(
  807. JitsiConferenceEvents.USER_LEFT, id, participant);
  808. }
  809. };
  810. JitsiConference.prototype.onUserRoleChanged = function(jid, role) {
  811. var id = Strophe.getResourceFromJid(jid);
  812. var participant = this.getParticipantById(id);
  813. if (!participant) {
  814. return;
  815. }
  816. participant._role = role;
  817. this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
  818. };
  819. JitsiConference.prototype.onDisplayNameChanged = function(jid, displayName) {
  820. var id = Strophe.getResourceFromJid(jid);
  821. var participant = this.getParticipantById(id);
  822. if (!participant) {
  823. return;
  824. }
  825. if (participant._displayName === displayName) {
  826. return;
  827. }
  828. participant._displayName = displayName;
  829. this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
  830. };
  831. /**
  832. * Notifies this JitsiConference that a JitsiRemoteTrack was added into
  833. * the conference.
  834. *
  835. * @param {JitsiRemoteTrack} track the JitsiRemoteTrack which was added to this
  836. * JitsiConference
  837. */
  838. JitsiConference.prototype.onRemoteTrackAdded = function(track) {
  839. const id = track.getParticipantId();
  840. const participant = this.getParticipantById(id);
  841. if (!participant) {
  842. logger.error(`No participant found for id: ${id}`);
  843. return;
  844. }
  845. // Add track to JitsiParticipant.
  846. participant._tracks.push(track);
  847. if (this.transcriber){
  848. this.transcriber.addTrack(track);
  849. }
  850. const emitter = this.eventEmitter;
  851. track.addEventListener(
  852. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  853. function() {
  854. emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  855. }
  856. );
  857. track.addEventListener(
  858. JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  859. function(audioLevel) {
  860. emitter.emit(
  861. JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  862. id,
  863. audioLevel);
  864. }
  865. );
  866. emitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  867. };
  868. /**
  869. * Notifies this JitsiConference that a JitsiRemoteTrack was removed from
  870. * the conference.
  871. *
  872. * @param {JitsiRemoteTrack} removedTrack
  873. */
  874. JitsiConference.prototype.onRemoteTrackRemoved = function(removedTrack) {
  875. let consumed = false;
  876. this.getParticipants().forEach(function(participant) {
  877. const tracks = participant.getTracks();
  878. for(let i = 0; i < tracks.length; i++) {
  879. if (tracks[i] === removedTrack) {
  880. // Since the tracks have been compared and are
  881. // considered equal the result of splice can be ignored.
  882. participant._tracks.splice(i, 1);
  883. this.eventEmitter.emit(
  884. JitsiConferenceEvents.TRACK_REMOVED, removedTrack);
  885. if (this.transcriber){
  886. this.transcriber.removeTrack(removedTrack);
  887. }
  888. consumed = true;
  889. break;
  890. }
  891. }
  892. }, this);
  893. if (!consumed) {
  894. logger.error(
  895. "Failed to match remote track on remove"
  896. + " with any of the participants",
  897. removedTrack.getStreamId(),
  898. removedTrack.getParticipantId());
  899. }
  900. };
  901. /**
  902. * Handles incoming call event.
  903. */
  904. JitsiConference.prototype.onIncomingCall =
  905. function(jingleSession, jingleOffer, now) {
  906. if (!this.room.isFocus(jingleSession.peerjid)) {
  907. // Error cause this should never happen unless something is wrong!
  908. var errmsg = "Rejecting session-initiate from non-focus user: "
  909. + jingleSession.peerjid;
  910. GlobalOnErrorHandler.callErrorHandler(new Error(errmsg));
  911. logger.error(errmsg);
  912. // Terminate the jingle session with a reason
  913. jingleSession.terminate(
  914. 'security-error', 'Only focus can start new sessions',
  915. null /* success callback => we don't care */,
  916. function(error) {
  917. logger.warn(
  918. "An error occurred while trying to terminate"
  919. + " invalid Jingle session", error);
  920. });
  921. return;
  922. }
  923. // Accept incoming call
  924. this.jingleSession = jingleSession;
  925. this.room.connectionTimes["session.initiate"] = now;
  926. // Log "session.restart"
  927. if (this.wasStopped) {
  928. Statistics.sendEventToAll("session.restart");
  929. }
  930. // add info whether call is cross-region
  931. var crossRegion = null;
  932. if (window.jitsiRegionInfo) {
  933. crossRegion = window.jitsiRegionInfo["CrossRegion"];
  934. }
  935. Statistics.analytics.sendEvent(
  936. "session.initiate", {
  937. value: now - this.room.connectionTimes["muc.joined"],
  938. label: crossRegion
  939. });
  940. try {
  941. jingleSession.initialize(false /* initiator */, this.room, this.rtc);
  942. } catch (error) {
  943. GlobalOnErrorHandler.callErrorHandler(error);
  944. }
  945. this.rtc.initializeDataChannels(jingleSession.peerconnection);
  946. // Add local Tracks to the ChatRoom
  947. this.getLocalTracks().forEach(function(localTrack) {
  948. let ssrcInfo = null;
  949. /**
  950. * We don't do this for Firefox because, on Firefox, we keep the
  951. * stream in the peer connection and just set 'enabled' on the
  952. * track to false (see JitsiLocalTrack::_setMute). This means
  953. * that if we generated an ssrc here and set it in the cache, it
  954. * would clash with the one firefox generates (since, unlike chrome,
  955. * the stream is still attached to the peer connection) and causes
  956. * problems between sdp-interop and trying to keep the ssrcs
  957. * consistent
  958. */
  959. if (localTrack.isVideoTrack() && localTrack.isMuted() && !RTCBrowserType.isFirefox()) {
  960. /**
  961. * Handles issues when the stream is added before the peerconnection
  962. * is created. The peerconnection is created when second participant
  963. * enters the call. In that use case the track doesn't have
  964. * information about it's ssrcs and no jingle packets are sent. That
  965. * can cause inconsistent behavior later.
  966. *
  967. * For example:
  968. * If we mute the stream and than second participant enter it's
  969. * remote SDP won't include that track. On unmute we are not sending
  970. * any jingle packets which will brake the unmute.
  971. *
  972. * In order to solve issues like the above one here we have to
  973. * generate the ssrc information for the track .
  974. */
  975. localTrack._setSSRC(this._generateNewStreamSSRCInfo());
  976. ssrcInfo = {
  977. mtype: localTrack.getType(),
  978. type: "addMuted",
  979. ssrcs: localTrack.ssrc.ssrcs,
  980. groups: localTrack.ssrc.groups,
  981. msid: localTrack.initialMSID
  982. };
  983. }
  984. try {
  985. this._addLocalStream(
  986. localTrack.getOriginalStream(), function() {}, function() {},
  987. ssrcInfo, true /* don't modify SSRCs */);
  988. } catch(e) {
  989. GlobalOnErrorHandler.callErrorHandler(e);
  990. logger.error(e);
  991. }
  992. }.bind(this));
  993. // Generate the 'recvonly' SSRC in case there are no video tracks
  994. if (!this.getLocalTracks(MediaType.VIDEO).length) {
  995. jingleSession.generateRecvonlySsrc();
  996. }
  997. jingleSession.acceptOffer(jingleOffer, null,
  998. function(error) {
  999. GlobalOnErrorHandler.callErrorHandler(error);
  1000. logger.error(
  1001. "Failed to accept incoming Jingle session", error);
  1002. }
  1003. );
  1004. // Start callstats as soon as peerconnection is initialized,
  1005. // do not wait for XMPPEvents.PEERCONNECTION_READY, as it may never
  1006. // happen in case if user doesn't have or denied permission to
  1007. // both camera and microphone.
  1008. this.statistics.startCallStats(jingleSession);
  1009. this.statistics.startRemoteStats(jingleSession.peerconnection);
  1010. };
  1011. /**
  1012. * Handles the call ended event.
  1013. * @param {JingleSessionPC} JingleSession the jingle session which has been
  1014. * terminated.
  1015. * @param {String} reasonCondition the Jingle reason condition.
  1016. * @param {String|null} reasonText human readable reason text which may provide
  1017. * more details about why the call has been terminated.
  1018. */
  1019. JitsiConference.prototype.onCallEnded
  1020. = function(JingleSession, reasonCondition, reasonText) {
  1021. logger.info("Call ended: " + reasonCondition + " - " + reasonText);
  1022. this.wasStopped = true;
  1023. // Send session.terminate event
  1024. Statistics.sendEventToAll("session.terminate");
  1025. // Stop the stats
  1026. if (this.statistics) {
  1027. this.statistics.stopRemoteStats();
  1028. this.statistics.stopCallStats();
  1029. }
  1030. // Current JingleSession is invalid so set it to null on the room
  1031. this.jingleSession = null;
  1032. // Let the RTC service do any cleanups
  1033. this.rtc.onCallEnded();
  1034. // PeerConnection has been closed which means that SSRCs stored in
  1035. // JitsiLocalTrack will not match those assigned by the old PeerConnection
  1036. // and SSRC replacement logic will not work as expected.
  1037. // We want to re-register 'ssrcHandler' of our local tracks, so that they
  1038. // will learn what their SSRC from the new PeerConnection which will be
  1039. // created on incoming call event.
  1040. var self = this;
  1041. this.getLocalTracks().forEach(function(localTrack) {
  1042. // Reset SSRC as it will no longer be valid
  1043. localTrack._setSSRC(null);
  1044. // Bind the handler to fetch new SSRC, it will un register itself once
  1045. // it reads the values
  1046. self.rtc.addListener(
  1047. RTCEvents.SENDRECV_STREAMS_CHANGED, localTrack.ssrcHandler);
  1048. });
  1049. };
  1050. /**
  1051. * Handles the suspend detected event. Leaves the room and fires suspended.
  1052. */
  1053. JitsiConference.prototype.onSuspendDetected = function() {
  1054. this.leave();
  1055. this.eventEmitter.emit(JitsiConferenceEvents.SUSPEND_DETECTED);
  1056. };
  1057. JitsiConference.prototype.updateDTMFSupport = function() {
  1058. var somebodySupportsDTMF = false;
  1059. var participants = this.getParticipants();
  1060. // check if at least 1 participant supports DTMF
  1061. for (var i = 0; i < participants.length; i += 1) {
  1062. if (participants[i].supportsDTMF()) {
  1063. somebodySupportsDTMF = true;
  1064. break;
  1065. }
  1066. }
  1067. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  1068. this.somebodySupportsDTMF = somebodySupportsDTMF;
  1069. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  1070. }
  1071. };
  1072. /**
  1073. * Allows to check if there is at least one user in the conference
  1074. * that supports DTMF.
  1075. * @returns {boolean} true if somebody supports DTMF, false otherwise
  1076. */
  1077. JitsiConference.prototype.isDTMFSupported = function() {
  1078. return this.somebodySupportsDTMF;
  1079. };
  1080. /**
  1081. * Returns the local user's ID
  1082. * @return {string} local user's ID
  1083. */
  1084. JitsiConference.prototype.myUserId = function() {
  1085. return this.room && this.room.myroomjid ? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  1086. };
  1087. JitsiConference.prototype.sendTones = function(tones, duration, pause) {
  1088. // FIXME P2P 'dtmfManager' must be cleared, after switching jingleSessions
  1089. if (!this.dtmfManager) {
  1090. if (!this.jingleSession) {
  1091. logger.warn("cannot sendTones: no jingle session");
  1092. return;
  1093. }
  1094. const peerConnection = this.jingleSession.peerconnection;
  1095. if (!peerConnection) {
  1096. logger.warn("cannot sendTones: no peer connection");
  1097. return;
  1098. }
  1099. const localAudio = this.getLocalAudioTrack();
  1100. if (!localAudio) {
  1101. logger.warn("cannot sendTones: no local audio stream");
  1102. return;
  1103. }
  1104. this.dtmfManager = new JitsiDTMFManager(localAudio, peerConnection);
  1105. }
  1106. this.dtmfManager.sendTones(tones, duration, pause);
  1107. };
  1108. /**
  1109. * Returns true if recording is supported and false if not.
  1110. */
  1111. JitsiConference.prototype.isRecordingSupported = function() {
  1112. if (this.room) {
  1113. return this.room.isRecordingSupported();
  1114. }
  1115. return false;
  1116. };
  1117. /**
  1118. * Returns null if the recording is not supported, "on" if the recording started
  1119. * and "off" if the recording is not started.
  1120. */
  1121. JitsiConference.prototype.getRecordingState = function() {
  1122. return this.room ? this.room.getRecordingState() : undefined;
  1123. };
  1124. /**
  1125. * Returns the url of the recorded video.
  1126. */
  1127. JitsiConference.prototype.getRecordingURL = function() {
  1128. return this.room ? this.room.getRecordingURL() : null;
  1129. };
  1130. /**
  1131. * Starts/stops the recording
  1132. */
  1133. JitsiConference.prototype.toggleRecording = function(options) {
  1134. if (this.room) {
  1135. return this.room.toggleRecording(options, function(status, error) {
  1136. this.eventEmitter.emit(
  1137. JitsiConferenceEvents.RECORDER_STATE_CHANGED, status, error);
  1138. }.bind(this));
  1139. }
  1140. this.eventEmitter.emit(
  1141. JitsiConferenceEvents.RECORDER_STATE_CHANGED, "error",
  1142. new Error("The conference is not created yet!"));
  1143. };
  1144. /**
  1145. * Returns true if the SIP calls are supported and false otherwise
  1146. */
  1147. JitsiConference.prototype.isSIPCallingSupported = function() {
  1148. if (this.room) {
  1149. return this.room.isSIPCallingSupported();
  1150. }
  1151. return false;
  1152. };
  1153. /**
  1154. * Dials a number.
  1155. * @param number the number
  1156. */
  1157. JitsiConference.prototype.dial = function(number) {
  1158. if (this.room) {
  1159. return this.room.dial(number);
  1160. }
  1161. return new Promise(function(resolve, reject){
  1162. reject(new Error("The conference is not created yet!"));
  1163. });
  1164. };
  1165. /**
  1166. * Hangup an existing call
  1167. */
  1168. JitsiConference.prototype.hangup = function() {
  1169. if (this.room) {
  1170. return this.room.hangup();
  1171. }
  1172. return new Promise(function(resolve, reject){
  1173. reject(new Error("The conference is not created yet!"));
  1174. });
  1175. };
  1176. /**
  1177. * Returns the phone number for joining the conference.
  1178. */
  1179. JitsiConference.prototype.getPhoneNumber = function() {
  1180. if (this.room) {
  1181. return this.room.getPhoneNumber();
  1182. }
  1183. return null;
  1184. };
  1185. /**
  1186. * Returns the pin for joining the conference with phone.
  1187. */
  1188. JitsiConference.prototype.getPhonePin = function() {
  1189. if (this.room) {
  1190. return this.room.getPhonePin();
  1191. }
  1192. return null;
  1193. };
  1194. /**
  1195. * Returns the connection state for the current room. Its ice connection state
  1196. * for its session.
  1197. */
  1198. JitsiConference.prototype.getConnectionState = function() {
  1199. if (this.jingleSession) {
  1200. return this.jingleSession.getIceConnectionState();
  1201. } else {
  1202. return null;
  1203. }
  1204. };
  1205. /**
  1206. * Make all new participants mute their audio/video on join.
  1207. * @param policy {Object} object with 2 boolean properties for video and audio:
  1208. * @param {boolean} audio if audio should be muted.
  1209. * @param {boolean} video if video should be muted.
  1210. */
  1211. JitsiConference.prototype.setStartMutedPolicy = function(policy) {
  1212. if (!this.isModerator()) {
  1213. return;
  1214. }
  1215. this.startMutedPolicy = policy;
  1216. this.room.removeFromPresence("startmuted");
  1217. this.room.addToPresence("startmuted", {
  1218. attributes: {
  1219. audio: policy.audio,
  1220. video: policy.video,
  1221. xmlns: 'http://jitsi.org/jitmeet/start-muted'
  1222. }
  1223. });
  1224. this.room.sendPresence();
  1225. };
  1226. /**
  1227. * Returns current start muted policy
  1228. * @returns {Object} with 2 properties - audio and video.
  1229. */
  1230. JitsiConference.prototype.getStartMutedPolicy = function() {
  1231. return this.startMutedPolicy;
  1232. };
  1233. /**
  1234. * Check if audio is muted on join.
  1235. */
  1236. JitsiConference.prototype.isStartAudioMuted = function() {
  1237. return this.startAudioMuted;
  1238. };
  1239. /**
  1240. * Check if video is muted on join.
  1241. */
  1242. JitsiConference.prototype.isStartVideoMuted = function() {
  1243. return this.startVideoMuted;
  1244. };
  1245. /**
  1246. * Get object with internal logs.
  1247. */
  1248. JitsiConference.prototype.getLogs = function() {
  1249. var data = this.xmpp.getJingleLog();
  1250. var metadata = {};
  1251. metadata.time = new Date();
  1252. metadata.url = window.location.href;
  1253. metadata.ua = navigator.userAgent;
  1254. var log = this.xmpp.getXmppLog();
  1255. if (log) {
  1256. metadata.xmpp = log;
  1257. }
  1258. data.metadata = metadata;
  1259. return data;
  1260. };
  1261. /**
  1262. * Returns measured connectionTimes.
  1263. */
  1264. JitsiConference.prototype.getConnectionTimes = function() {
  1265. return this.room.connectionTimes;
  1266. };
  1267. /**
  1268. * Sets a property for the local participant.
  1269. */
  1270. JitsiConference.prototype.setLocalParticipantProperty = function(name, value) {
  1271. this.sendCommand("jitsi_participant_" + name, {value});
  1272. };
  1273. /**
  1274. * Sends the given feedback through CallStats if enabled.
  1275. *
  1276. * @param overallFeedback an integer between 1 and 5 indicating the
  1277. * user feedback
  1278. * @param detailedFeedback detailed feedback from the user. Not yet used
  1279. */
  1280. JitsiConference.prototype.sendFeedback =
  1281. function(overallFeedback, detailedFeedback){
  1282. this.statistics.sendFeedback(overallFeedback, detailedFeedback);
  1283. };
  1284. /**
  1285. * Returns true if the callstats integration is enabled, otherwise returns
  1286. * false.
  1287. *
  1288. * @returns true if the callstats integration is enabled, otherwise returns
  1289. * false.
  1290. */
  1291. JitsiConference.prototype.isCallstatsEnabled = function() {
  1292. return this.statistics.isCallstatsEnabled();
  1293. };
  1294. /**
  1295. * Handles track attached to container (Calls associateStreamWithVideoTag method
  1296. * from statistics module)
  1297. * @param track the track
  1298. * @param container the container
  1299. */
  1300. JitsiConference.prototype._onTrackAttach = function(track, container) {
  1301. var ssrc = track.getSSRC();
  1302. if (!container.id || !ssrc) {
  1303. return;
  1304. }
  1305. this.statistics.associateStreamWithVideoTag(
  1306. ssrc, track.isLocal(), track.getUsageLabel(), container.id);
  1307. };
  1308. /**
  1309. * Logs an "application log" message.
  1310. * @param message {string} The message to log. Note that while this can be a
  1311. * generic string, the convention used by lib-jitsi-meet and jitsi-meet is to
  1312. * log valid JSON strings, with an "id" field used for distinguishing between
  1313. * message types. E.g.: {id: "recorder_status", status: "off"}
  1314. */
  1315. JitsiConference.prototype.sendApplicationLog = function(message) {
  1316. Statistics.sendLog(message);
  1317. };
  1318. /**
  1319. * Checks if the user identified by given <tt>mucJid</tt> is the conference
  1320. * focus.
  1321. * @param mucJid the full MUC address of the user to be checked.
  1322. * @returns {boolean|null} <tt>true</tt> if MUC user is the conference focus,
  1323. * <tt>false</tt> when is not. <tt>null</tt> if we're not in the MUC anymore and
  1324. * are unable to figure out the status or if given <tt>mucJid</tt> is invalid.
  1325. */
  1326. JitsiConference.prototype._isFocus = function(mucJid) {
  1327. return this.room ? this.room.isFocus(mucJid) : null;
  1328. };
  1329. /**
  1330. * Fires CONFERENCE_FAILED event with INCOMPATIBLE_SERVER_VERSIONS parameter
  1331. */
  1332. JitsiConference.prototype._fireIncompatibleVersionsEvent = function() {
  1333. this.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  1334. JitsiConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS);
  1335. };
  1336. /**
  1337. * Sends a message via the data channel.
  1338. * @param to {string} the id of the endpoint that should receive the message.
  1339. * If "" the message will be sent to all participants.
  1340. * @param payload {object} the payload of the message.
  1341. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  1342. */
  1343. JitsiConference.prototype.sendEndpointMessage = function(to, payload) {
  1344. this.rtc.sendDataChannelMessage(to, payload);
  1345. };
  1346. /**
  1347. * Sends a broadcast message via the data channel.
  1348. * @param payload {object} the payload of the message.
  1349. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  1350. */
  1351. JitsiConference.prototype.broadcastEndpointMessage = function(payload) {
  1352. this.sendEndpointMessage("", payload);
  1353. };
  1354. JitsiConference.prototype.isConnectionInterrupted = function() {
  1355. return this.connectionIsInterrupted;
  1356. };
  1357. module.exports = JitsiConference;