您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

JitsiConference.js 43KB

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