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