您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JitsiConference.js 43KB

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