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

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