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

JitsiConference.js 42KB

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