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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  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. value: now - this.room.connectionTimes["muc.joined"],
  743. label: crossRegion
  744. });
  745. try{
  746. jingleSession.initialize(false /* initiator */,this.room);
  747. } catch (error) {
  748. GlobalOnErrorHandler.callErrorHandler(error);
  749. }
  750. this.rtc.onIncommingCall(jingleSession);
  751. // Add local Tracks to the ChatRoom
  752. this.rtc.localTracks.forEach(function(localTrack) {
  753. var ssrcInfo = null;
  754. if(localTrack.isVideoTrack() && localTrack.isMuted()) {
  755. /**
  756. * Handles issues when the stream is added before the peerconnection
  757. * is created. The peerconnection is created when second participant
  758. * enters the call. In that use case the track doesn't have
  759. * information about it's ssrcs and no jingle packets are sent. That
  760. * can cause inconsistent behavior later.
  761. *
  762. * For example:
  763. * If we mute the stream and than second participant enter it's
  764. * remote SDP won't include that track. On unmute we are not sending
  765. * any jingle packets which will brake the unmute.
  766. *
  767. * In order to solve issues like the above one here we have to
  768. * generate the ssrc information for the track .
  769. */
  770. localTrack._setSSRC(
  771. this.room.generateNewStreamSSRCInfo());
  772. ssrcInfo = {
  773. mtype: localTrack.getType(),
  774. type: "addMuted",
  775. ssrc: localTrack.ssrc,
  776. msid: localTrack.initialMSID
  777. };
  778. }
  779. try {
  780. this.room.addStream(
  781. localTrack.getOriginalStream(), function () {}, function () {},
  782. ssrcInfo, true);
  783. } catch(e) {
  784. GlobalOnErrorHandler.callErrorHandler(e);
  785. logger.error(e);
  786. }
  787. }.bind(this));
  788. jingleSession.acceptOffer(jingleOffer, null,
  789. function (error) {
  790. GlobalOnErrorHandler.callErrorHandler(error);
  791. logger.error(
  792. "Failed to accept incoming Jingle session", error);
  793. }
  794. );
  795. // Start callstats as soon as peerconnection is initialized,
  796. // do not wait for XMPPEvents.PEERCONNECTION_READY, as it may never
  797. // happen in case if user doesn't have or denied permission to
  798. // both camera and microphone.
  799. this.statistics.startCallStats(jingleSession, this.settings);
  800. this.statistics.startRemoteStats(jingleSession.peerconnection);
  801. };
  802. /**
  803. * Handles the call ended event.
  804. * @param {JingleSessionPC} JingleSession the jingle session which has been
  805. * terminated.
  806. * @param {String} reasonCondition the Jingle reason condition.
  807. * @param {String|null} reasonText human readable reason text which may provide
  808. * more details about why the call has been terminated.
  809. */
  810. JitsiConference.prototype.onCallEnded
  811. = function (JingleSession, reasonCondition, reasonText) {
  812. logger.info("Call ended: " + reasonCondition + " - " + reasonText);
  813. this.wasStopped = true;
  814. // Send session.terminate event
  815. Statistics.sendEventToAll("session.terminate");
  816. // Stop the stats
  817. if (this.statistics) {
  818. this.statistics.stopRemoteStats();
  819. this.statistics.stopCallStats();
  820. }
  821. // Current JingleSession is invalid so set it to null on the room
  822. this.room.setJingleSession(null);
  823. // Let the RTC service do any cleanups
  824. this.rtc.onCallEnded();
  825. // PeerConnection has been closed which means that SSRCs stored in
  826. // JitsiLocalTrack will not match those assigned by the old PeerConnection
  827. // and SSRC replacement logic will not work as expected.
  828. // We want to re-register 'ssrcHandler' of our local tracks, so that they
  829. // will learn what their SSRC from the new PeerConnection which will be
  830. // created on incoming call event.
  831. var self = this;
  832. this.rtc.localTracks.forEach(function(localTrack) {
  833. // Reset SSRC as it will no longer be valid
  834. localTrack._setSSRC(null);
  835. // Bind the handler to fetch new SSRC, it will un register itself once
  836. // it reads the values
  837. self.room.addListener(
  838. XMPPEvents.SENDRECV_STREAMS_CHANGED, localTrack.ssrcHandler);
  839. });
  840. };
  841. JitsiConference.prototype.updateDTMFSupport = function () {
  842. var somebodySupportsDTMF = false;
  843. var participants = this.getParticipants();
  844. // check if at least 1 participant supports DTMF
  845. for (var i = 0; i < participants.length; i += 1) {
  846. if (participants[i].supportsDTMF()) {
  847. somebodySupportsDTMF = true;
  848. break;
  849. }
  850. }
  851. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  852. this.somebodySupportsDTMF = somebodySupportsDTMF;
  853. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  854. }
  855. };
  856. /**
  857. * Allows to check if there is at least one user in the conference
  858. * that supports DTMF.
  859. * @returns {boolean} true if somebody supports DTMF, false otherwise
  860. */
  861. JitsiConference.prototype.isDTMFSupported = function () {
  862. return this.somebodySupportsDTMF;
  863. };
  864. /**
  865. * Returns the local user's ID
  866. * @return {string} local user's ID
  867. */
  868. JitsiConference.prototype.myUserId = function () {
  869. return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  870. };
  871. JitsiConference.prototype.sendTones = function (tones, duration, pause) {
  872. if (!this.dtmfManager) {
  873. var connection = this.xmpp.connection.jingle.activecall.peerconnection;
  874. if (!connection) {
  875. logger.warn("cannot sendTones: no conneciton");
  876. return;
  877. }
  878. var tracks = this.getLocalTracks().filter(function (track) {
  879. return track.isAudioTrack();
  880. });
  881. if (!tracks.length) {
  882. logger.warn("cannot sendTones: no local audio stream");
  883. return;
  884. }
  885. this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
  886. }
  887. this.dtmfManager.sendTones(tones, duration, pause);
  888. };
  889. /**
  890. * Returns true if the recording is supproted and false if not.
  891. */
  892. JitsiConference.prototype.isRecordingSupported = function () {
  893. if(this.room)
  894. return this.room.isRecordingSupported();
  895. return false;
  896. };
  897. /**
  898. * Returns null if the recording is not supported, "on" if the recording started
  899. * and "off" if the recording is not started.
  900. */
  901. JitsiConference.prototype.getRecordingState = function () {
  902. return (this.room) ? this.room.getRecordingState() : undefined;
  903. };
  904. /**
  905. * Returns the url of the recorded video.
  906. */
  907. JitsiConference.prototype.getRecordingURL = function () {
  908. return (this.room) ? this.room.getRecordingURL() : null;
  909. };
  910. /**
  911. * Starts/stops the recording
  912. */
  913. JitsiConference.prototype.toggleRecording = function (options) {
  914. if(this.room)
  915. return this.room.toggleRecording(options, function (status, error) {
  916. this.eventEmitter.emit(
  917. JitsiConferenceEvents.RECORDER_STATE_CHANGED, status, error);
  918. }.bind(this));
  919. this.eventEmitter.emit(
  920. JitsiConferenceEvents.RECORDER_STATE_CHANGED, "error",
  921. new Error("The conference is not created yet!"));
  922. };
  923. /**
  924. * Returns true if the SIP calls are supported and false otherwise
  925. */
  926. JitsiConference.prototype.isSIPCallingSupported = function () {
  927. if(this.room)
  928. return this.room.isSIPCallingSupported();
  929. return false;
  930. };
  931. /**
  932. * Dials a number.
  933. * @param number the number
  934. */
  935. JitsiConference.prototype.dial = function (number) {
  936. if(this.room)
  937. return this.room.dial(number);
  938. return new Promise(function(resolve, reject){
  939. reject(new Error("The conference is not created yet!"));});
  940. };
  941. /**
  942. * Hangup an existing call
  943. */
  944. JitsiConference.prototype.hangup = function () {
  945. if(this.room)
  946. return this.room.hangup();
  947. return new Promise(function(resolve, reject){
  948. reject(new Error("The conference is not created yet!"));});
  949. };
  950. /**
  951. * Returns the phone number for joining the conference.
  952. */
  953. JitsiConference.prototype.getPhoneNumber = function () {
  954. if(this.room)
  955. return this.room.getPhoneNumber();
  956. return null;
  957. };
  958. /**
  959. * Returns the pin for joining the conference with phone.
  960. */
  961. JitsiConference.prototype.getPhonePin = function () {
  962. if(this.room)
  963. return this.room.getPhonePin();
  964. return null;
  965. };
  966. /**
  967. * Returns the connection state for the current room. Its ice connection state
  968. * for its session.
  969. */
  970. JitsiConference.prototype.getConnectionState = function () {
  971. if(this.room)
  972. return this.room.getConnectionState();
  973. return null;
  974. };
  975. /**
  976. * Make all new participants mute their audio/video on join.
  977. * @param policy {Object} object with 2 boolean properties for video and audio:
  978. * @param {boolean} audio if audio should be muted.
  979. * @param {boolean} video if video should be muted.
  980. */
  981. JitsiConference.prototype.setStartMutedPolicy = function (policy) {
  982. if (!this.isModerator()) {
  983. return;
  984. }
  985. this.startMutedPolicy = policy;
  986. this.room.removeFromPresence("startmuted");
  987. this.room.addToPresence("startmuted", {
  988. attributes: {
  989. audio: policy.audio,
  990. video: policy.video,
  991. xmlns: 'http://jitsi.org/jitmeet/start-muted'
  992. }
  993. });
  994. this.room.sendPresence();
  995. };
  996. /**
  997. * Returns current start muted policy
  998. * @returns {Object} with 2 proprties - audio and video.
  999. */
  1000. JitsiConference.prototype.getStartMutedPolicy = function () {
  1001. return this.startMutedPolicy;
  1002. };
  1003. /**
  1004. * Check if audio is muted on join.
  1005. */
  1006. JitsiConference.prototype.isStartAudioMuted = function () {
  1007. return this.startAudioMuted;
  1008. };
  1009. /**
  1010. * Check if video is muted on join.
  1011. */
  1012. JitsiConference.prototype.isStartVideoMuted = function () {
  1013. return this.startVideoMuted;
  1014. };
  1015. /**
  1016. * Get object with internal logs.
  1017. */
  1018. JitsiConference.prototype.getLogs = function () {
  1019. var data = this.xmpp.getJingleLog();
  1020. var metadata = {};
  1021. metadata.time = new Date();
  1022. metadata.url = window.location.href;
  1023. metadata.ua = navigator.userAgent;
  1024. var log = this.xmpp.getXmppLog();
  1025. if (log) {
  1026. metadata.xmpp = log;
  1027. }
  1028. data.metadata = metadata;
  1029. return data;
  1030. };
  1031. /**
  1032. * Returns measured connectionTimes.
  1033. */
  1034. JitsiConference.prototype.getConnectionTimes = function () {
  1035. return this.room.connectionTimes;
  1036. };
  1037. /**
  1038. * Sets a property for the local participant.
  1039. */
  1040. JitsiConference.prototype.setLocalParticipantProperty = function(name, value) {
  1041. this.sendCommand("jitsi_participant_" + name, {value: value});
  1042. };
  1043. /**
  1044. * Sends the given feedback through CallStats if enabled.
  1045. *
  1046. * @param overallFeedback an integer between 1 and 5 indicating the
  1047. * user feedback
  1048. * @param detailedFeedback detailed feedback from the user. Not yet used
  1049. */
  1050. JitsiConference.prototype.sendFeedback =
  1051. function(overallFeedback, detailedFeedback){
  1052. this.statistics.sendFeedback(overallFeedback, detailedFeedback);
  1053. };
  1054. /**
  1055. * Returns true if the callstats integration is enabled, otherwise returns
  1056. * false.
  1057. *
  1058. * @returns true if the callstats integration is enabled, otherwise returns
  1059. * false.
  1060. */
  1061. JitsiConference.prototype.isCallstatsEnabled = function () {
  1062. return this.statistics.isCallstatsEnabled();
  1063. };
  1064. /**
  1065. * Handles track attached to container (Calls associateStreamWithVideoTag method
  1066. * from statistics module)
  1067. * @param track the track
  1068. * @param container the container
  1069. */
  1070. JitsiConference.prototype._onTrackAttach = function(track, container) {
  1071. var ssrc = track.getSSRC();
  1072. if (!container.id || !ssrc) {
  1073. return;
  1074. }
  1075. this.statistics.associateStreamWithVideoTag(
  1076. ssrc, track.isLocal(), track.getUsageLabel(), container.id);
  1077. };
  1078. /**
  1079. * Reports detected audio problem with the media stream related to the passed
  1080. * ssrc.
  1081. * @param ssrc {string} the ssrc
  1082. * NOTE: all logger.log calls are there only to be able to see the info in
  1083. * torture
  1084. */
  1085. JitsiConference.prototype._reportAudioProblem = function (ssrc) {
  1086. if(this.reportedAudioSSRCs[ssrc])
  1087. return;
  1088. var track = this.rtc.getRemoteTrackBySSRC(ssrc);
  1089. if(!track || !track.isAudioTrack())
  1090. return;
  1091. var id = track.getParticipantId();
  1092. var displayName = null;
  1093. if(id) {
  1094. var participant = this.getParticipantById(id);
  1095. if(participant) {
  1096. displayName = participant.getDisplayName();
  1097. }
  1098. }
  1099. this.reportedAudioSSRCs[ssrc] = true;
  1100. var errorContent = {
  1101. errMsg: "The audio is received but not played",
  1102. ssrc: ssrc,
  1103. jid: id,
  1104. displayName: displayName
  1105. };
  1106. logger.log("=================The audio is received but not played" +
  1107. "======================");
  1108. logger.log("ssrc: ", ssrc);
  1109. logger.log("jid: ", id);
  1110. logger.log("displayName: ", displayName);
  1111. var mstream = track.stream, mtrack = track.track;
  1112. if(mstream) {
  1113. logger.log("MediaStream:");
  1114. errorContent.MediaStream = {
  1115. active: mstream.active,
  1116. id: mstream.id
  1117. };
  1118. logger.log("active: ", mstream.active);
  1119. logger.log("id: ", mstream.id);
  1120. }
  1121. if(mtrack) {
  1122. logger.log("MediaStreamTrack:");
  1123. errorContent.MediaStreamTrack = {
  1124. enabled: mtrack.enabled,
  1125. id: mtrack.id,
  1126. label: mtrack.label,
  1127. muted: mtrack.muted
  1128. };
  1129. logger.log("enabled: ", mtrack.enabled);
  1130. logger.log("id: ", mtrack.id);
  1131. logger.log("label: ", mtrack.label);
  1132. logger.log("muted: ", mtrack.muted);
  1133. }
  1134. if(track.containers) {
  1135. errorContent.containers = [];
  1136. logger.log("Containers:");
  1137. track.containers.forEach(function (container) {
  1138. logger.log("Container:");
  1139. errorContent.containers.push({
  1140. autoplay: container.autoplay,
  1141. muted: container.muted,
  1142. src: container.src,
  1143. volume: container.volume,
  1144. id: container.id,
  1145. ended: container.ended,
  1146. paused: container.paused,
  1147. readyState: container.readyState
  1148. });
  1149. logger.log("autoplay: ", container.autoplay);
  1150. logger.log("muted: ", container.muted);
  1151. logger.log("src: ", container.src);
  1152. logger.log("volume: ", container.volume);
  1153. logger.log("id: ", container.id);
  1154. logger.log("ended: ", container.ended);
  1155. logger.log("paused: ", container.paused);
  1156. logger.log("readyState: ", container.readyState);
  1157. });
  1158. }
  1159. // Prints JSON.stringify(errorContent) to be able to see all properties of
  1160. // errorContent from torture
  1161. logger.error("Audio problem detected. The audio is received but not played",
  1162. errorContent);
  1163. delete errorContent.displayName;
  1164. this.statistics.sendDetectedAudioProblem(
  1165. new Error(JSON.stringify(errorContent)));
  1166. };
  1167. /**
  1168. * Logs an "application log" message.
  1169. * @param message {string} The message to log. Note that while this can be a
  1170. * generic string, the convention used by lib-jitsi-meet and jitsi-meet is to
  1171. * log valid JSON strings, with an "id" field used for distinguishing between
  1172. * message types. E.g.: {id: "recorder_status", status: "off"}
  1173. */
  1174. JitsiConference.prototype.sendApplicationLog = function(message) {
  1175. Statistics.sendLog(message);
  1176. };
  1177. /**
  1178. * Checks if the user identified by given <tt>mucJid</tt> is the conference
  1179. * focus.
  1180. * @param mucJid the full MUC address of the user to be checked.
  1181. * @returns {boolean} <tt>true</tt> if MUC user is the conference focus.
  1182. */
  1183. JitsiConference.prototype._isFocus = function (mucJid) {
  1184. return this.room.isFocus(mucJid);
  1185. };
  1186. /**
  1187. * Fires CONFERENCE_FAILED event with INCOMPATIBLE_SERVER_VERSIONS parameter
  1188. */
  1189. JitsiConference.prototype._fireIncompatibleVersionsEvent = function () {
  1190. this.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  1191. JitsiConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS);
  1192. };
  1193. /**
  1194. * Sends message via the datachannels.
  1195. * @param to {string} the id of the endpoint that should receive the message.
  1196. * If "" the message will be sent to all participants.
  1197. * @param payload {object} the payload of the message.
  1198. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  1199. */
  1200. JitsiConference.prototype.sendEndpointMessage = function (to, payload) {
  1201. this.rtc.sendDataChannelMessage(to, payload);
  1202. };
  1203. /**
  1204. * Sends broadcast message via the datachannels.
  1205. * @param payload {object} the payload of the message.
  1206. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  1207. */
  1208. JitsiConference.prototype.broadcastEndpointMessage = function (payload) {
  1209. this.sendEndpointMessage("", payload);
  1210. };
  1211. module.exports = JitsiConference;