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