You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiConference.js 43KB

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