You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JitsiConference.js 42KB

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