Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

JitsiConference.js 43KB

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