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

JitsiConference.js 43KB

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