Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

JitsiConference.js 48KB

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