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

JitsiConference.js 42KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  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. * Or cache it if channel is not created and send it once channel is available.
  540. * @param participantId the identifier of the participant
  541. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  542. */
  543. JitsiConference.prototype.selectParticipant = function(participantId) {
  544. this.rtc.selectEndpoint(participantId);
  545. };
  546. /**
  547. * Elects the participant with the given id to be the pinned participant in
  548. * order to always receive video for this participant (even when last n is
  549. * enabled).
  550. * @param participantId the identifier of the participant
  551. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  552. */
  553. JitsiConference.prototype.pinParticipant = function(participantId) {
  554. this.rtc.pinEndpoint(participantId);
  555. };
  556. /**
  557. * Returns the list of participants for this conference.
  558. * @return Array<JitsiParticipant> a list of participant identifiers containing all conference participants.
  559. */
  560. JitsiConference.prototype.getParticipants = function() {
  561. return Object.keys(this.participants).map(function (key) {
  562. return this.participants[key];
  563. }, this);
  564. };
  565. /**
  566. * @returns {JitsiParticipant} the participant in this conference with the specified id (or
  567. * undefined if there isn't one).
  568. * @param id the id of the participant.
  569. */
  570. JitsiConference.prototype.getParticipantById = function(id) {
  571. return this.participants[id];
  572. };
  573. /**
  574. * Kick participant from this conference.
  575. * @param {string} id id of the participant to kick
  576. */
  577. JitsiConference.prototype.kickParticipant = function (id) {
  578. var participant = this.getParticipantById(id);
  579. if (!participant) {
  580. return;
  581. }
  582. this.room.kick(participant.getJid());
  583. };
  584. /**
  585. * Kick participant from this conference.
  586. * @param {string} id id of the participant to kick
  587. */
  588. JitsiConference.prototype.muteParticipant = function (id) {
  589. var participant = this.getParticipantById(id);
  590. if (!participant) {
  591. return;
  592. }
  593. this.room.muteParticipant(participant.getJid(), true);
  594. };
  595. /**
  596. * Indicates that a participant has joined the conference.
  597. *
  598. * @param jid the jid of the participant in the MUC
  599. * @param nick the display name of the participant
  600. * @param role the role of the participant in the MUC
  601. * @param isHidden indicates if this is a hidden participant (sysem participant,
  602. * for example a recorder).
  603. */
  604. JitsiConference.prototype.onMemberJoined
  605. = function (jid, nick, role, isHidden) {
  606. var id = Strophe.getResourceFromJid(jid);
  607. if (id === 'focus' || this.myUserId() === id) {
  608. return;
  609. }
  610. var participant = new JitsiParticipant(jid, this, nick, isHidden);
  611. participant._role = role;
  612. this.participants[id] = participant;
  613. this.eventEmitter.emit(JitsiConferenceEvents.USER_JOINED, id, participant);
  614. // XXX Since disco is checked in multiple places (e.g.
  615. // modules/xmpp/strophe.jingle.js, modules/xmpp/strophe.rayo.js), check it
  616. // here as well.
  617. var disco = this.xmpp.connection.disco;
  618. if (disco) {
  619. disco.info(
  620. jid, "node", function(iq) {
  621. participant._supportsDTMF = $(iq).find(
  622. '>query>feature[var="urn:xmpp:jingle:dtmf:0"]').length > 0;
  623. this.updateDTMFSupport();
  624. }.bind(this)
  625. );
  626. } else {
  627. // FIXME Should participant._supportsDTMF be assigned false here (and
  628. // this.updateDTMFSupport invoked)?
  629. }
  630. };
  631. JitsiConference.prototype.onMemberLeft = function (jid) {
  632. var id = Strophe.getResourceFromJid(jid);
  633. if (id === 'focus' || this.myUserId() === id) {
  634. return;
  635. }
  636. var participant = this.participants[id];
  637. delete this.participants[id];
  638. var removedTracks = this.rtc.removeRemoteTracks(id);
  639. removedTracks.forEach(function (track) {
  640. this.eventEmitter.emit(JitsiConferenceEvents.TRACK_REMOVED, track);
  641. }.bind(this));
  642. this.eventEmitter.emit(JitsiConferenceEvents.USER_LEFT, id, participant);
  643. };
  644. JitsiConference.prototype.onUserRoleChanged = function (jid, role) {
  645. var id = Strophe.getResourceFromJid(jid);
  646. var participant = this.getParticipantById(id);
  647. if (!participant) {
  648. return;
  649. }
  650. participant._role = role;
  651. this.eventEmitter.emit(JitsiConferenceEvents.USER_ROLE_CHANGED, id, role);
  652. };
  653. JitsiConference.prototype.onDisplayNameChanged = function (jid, displayName) {
  654. var id = Strophe.getResourceFromJid(jid);
  655. var participant = this.getParticipantById(id);
  656. if (!participant) {
  657. return;
  658. }
  659. if (participant._displayName === displayName)
  660. return;
  661. participant._displayName = displayName;
  662. this.eventEmitter.emit(JitsiConferenceEvents.DISPLAY_NAME_CHANGED, id, displayName);
  663. };
  664. /**
  665. * Notifies this JitsiConference that a JitsiRemoteTrack was added (into the
  666. * ChatRoom of this JitsiConference).
  667. *
  668. * @param {JitsiRemoteTrack} track the JitsiRemoteTrack which was added to this
  669. * JitsiConference
  670. */
  671. JitsiConference.prototype.onTrackAdded = function (track) {
  672. var id = track.getParticipantId();
  673. var participant = this.getParticipantById(id);
  674. if (!participant) {
  675. return;
  676. }
  677. // Add track to JitsiParticipant.
  678. participant._tracks.push(track);
  679. if(this.transcriber){
  680. this.transcriber.addTrack(track);
  681. }
  682. var emitter = this.eventEmitter;
  683. track.addEventListener(
  684. JitsiTrackEvents.TRACK_MUTE_CHANGED,
  685. function () {
  686. emitter.emit(JitsiConferenceEvents.TRACK_MUTE_CHANGED, track);
  687. }
  688. );
  689. track.addEventListener(
  690. JitsiTrackEvents.TRACK_AUDIO_LEVEL_CHANGED,
  691. function (audioLevel) {
  692. emitter.emit(
  693. JitsiConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED,
  694. id,
  695. audioLevel);
  696. }
  697. );
  698. emitter.emit(JitsiConferenceEvents.TRACK_ADDED, track);
  699. };
  700. /**
  701. * Handles incoming call event.
  702. */
  703. JitsiConference.prototype.onIncomingCall =
  704. function (jingleSession, jingleOffer, now) {
  705. if (!this.room.isFocus(jingleSession.peerjid)) {
  706. // Error cause this should never happen unless something is wrong!
  707. var errmsg = "Rejecting session-initiate from non-focus user: "
  708. + jingleSession.peerjid;
  709. GlobalOnErrorHandler.callErrorHandler(new Error(errmsg));
  710. logger.error(errmsg);
  711. return;
  712. }
  713. // Accept incoming call
  714. this.room.setJingleSession(jingleSession);
  715. this.room.connectionTimes["session.initiate"] = now;
  716. // Log "session.restart"
  717. if (this.wasStopped) {
  718. Statistics.sendEventToAll("session.restart");
  719. }
  720. // add info whether call is cross-region
  721. var crossRegion = null;
  722. if (window.jitsiRegionInfo)
  723. crossRegion = window.jitsiRegionInfo["CrossRegion"];
  724. Statistics.analytics.sendEvent("session.initiate",
  725. (now - this.room.connectionTimes["muc.joined"]),
  726. crossRegion);
  727. try{
  728. jingleSession.initialize(false /* initiator */,this.room);
  729. } catch (error) {
  730. GlobalOnErrorHandler.callErrorHandler(error);
  731. };
  732. this.rtc.onIncommingCall(jingleSession);
  733. // Add local Tracks to the ChatRoom
  734. this.rtc.localTracks.forEach(function(localTrack) {
  735. var ssrcInfo = null;
  736. if(localTrack.isVideoTrack() && localTrack.isMuted()) {
  737. /**
  738. * Handles issues when the stream is added before the peerconnection
  739. * is created. The peerconnection is created when second participant
  740. * enters the call. In that use case the track doesn't have
  741. * information about it's ssrcs and no jingle packets are sent. That
  742. * can cause inconsistent behavior later.
  743. *
  744. * For example:
  745. * If we mute the stream and than second participant enter it's
  746. * remote SDP won't include that track. On unmute we are not sending
  747. * any jingle packets which will brake the unmute.
  748. *
  749. * In order to solve issues like the above one here we have to
  750. * generate the ssrc information for the track .
  751. */
  752. localTrack._setSSRC(
  753. this.room.generateNewStreamSSRCInfo());
  754. ssrcInfo = {
  755. mtype: localTrack.getType(),
  756. type: "addMuted",
  757. ssrc: localTrack.ssrc,
  758. msid: localTrack.initialMSID
  759. };
  760. }
  761. try {
  762. this.room.addStream(
  763. localTrack.getOriginalStream(), function () {}, function () {},
  764. ssrcInfo, true);
  765. } catch(e) {
  766. GlobalOnErrorHandler.callErrorHandler(e);
  767. logger.error(e);
  768. }
  769. }.bind(this));
  770. jingleSession.acceptOffer(jingleOffer, null,
  771. function (error) {
  772. GlobalOnErrorHandler.callErrorHandler(error);
  773. logger.error(
  774. "Failed to accept incoming Jingle session", error);
  775. }
  776. );
  777. // Start callstats as soon as peerconnection is initialized,
  778. // do not wait for XMPPEvents.PEERCONNECTION_READY, as it may never
  779. // happen in case if user doesn't have or denied permission to
  780. // both camera and microphone.
  781. this.statistics.startCallStats(jingleSession, this.settings);
  782. this.statistics.startRemoteStats(jingleSession.peerconnection);
  783. };
  784. /**
  785. * Handles the call ended event.
  786. * @param {JingleSessionPC} JingleSession the jingle session which has been
  787. * terminated.
  788. * @param {String} reasonCondition the Jingle reason condition.
  789. * @param {String|null} reasonText human readable reason text which may provide
  790. * more details about why the call has been terminated.
  791. */
  792. JitsiConference.prototype.onCallEnded
  793. = function (JingleSession, reasonCondition, reasonText) {
  794. logger.info("Call ended: " + reasonCondition + " - " + reasonText);
  795. this.wasStopped = true;
  796. // Send session.terminate event
  797. Statistics.sendEventToAll("session.terminate");
  798. // Stop the stats
  799. if (this.statistics) {
  800. this.statistics.stopRemoteStats();
  801. this.statistics.stopCallStats();
  802. }
  803. // Current JingleSession is invalid so set it to null on the room
  804. this.room.setJingleSession(null);
  805. // Let the RTC service do any cleanups
  806. this.rtc.onCallEnded();
  807. // PeerConnection has been closed which means that SSRCs stored in
  808. // JitsiLocalTrack will not match those assigned by the old PeerConnection
  809. // and SSRC replacement logic will not work as expected.
  810. // We want to re-register 'ssrcHandler' of our local tracks, so that they
  811. // will learn what their SSRC from the new PeerConnection which will be
  812. // created on incoming call event.
  813. var self = this;
  814. this.rtc.localTracks.forEach(function(localTrack) {
  815. // Reset SSRC as it will no longer be valid
  816. localTrack._setSSRC(null);
  817. // Bind the handler to fetch new SSRC, it will un register itself once
  818. // it reads the values
  819. self.room.addListener(
  820. XMPPEvents.SENDRECV_STREAMS_CHANGED, localTrack.ssrcHandler);
  821. });
  822. };
  823. JitsiConference.prototype.updateDTMFSupport = function () {
  824. var somebodySupportsDTMF = false;
  825. var participants = this.getParticipants();
  826. // check if at least 1 participant supports DTMF
  827. for (var i = 0; i < participants.length; i += 1) {
  828. if (participants[i].supportsDTMF()) {
  829. somebodySupportsDTMF = true;
  830. break;
  831. }
  832. }
  833. if (somebodySupportsDTMF !== this.somebodySupportsDTMF) {
  834. this.somebodySupportsDTMF = somebodySupportsDTMF;
  835. this.eventEmitter.emit(JitsiConferenceEvents.DTMF_SUPPORT_CHANGED, somebodySupportsDTMF);
  836. }
  837. };
  838. /**
  839. * Allows to check if there is at least one user in the conference
  840. * that supports DTMF.
  841. * @returns {boolean} true if somebody supports DTMF, false otherwise
  842. */
  843. JitsiConference.prototype.isDTMFSupported = function () {
  844. return this.somebodySupportsDTMF;
  845. };
  846. /**
  847. * Returns the local user's ID
  848. * @return {string} local user's ID
  849. */
  850. JitsiConference.prototype.myUserId = function () {
  851. return (this.room && this.room.myroomjid)? Strophe.getResourceFromJid(this.room.myroomjid) : null;
  852. };
  853. JitsiConference.prototype.sendTones = function (tones, duration, pause) {
  854. if (!this.dtmfManager) {
  855. var connection = this.xmpp.connection.jingle.activecall.peerconnection;
  856. if (!connection) {
  857. logger.warn("cannot sendTones: no conneciton");
  858. return;
  859. }
  860. var tracks = this.getLocalTracks().filter(function (track) {
  861. return track.isAudioTrack();
  862. });
  863. if (!tracks.length) {
  864. logger.warn("cannot sendTones: no local audio stream");
  865. return;
  866. }
  867. this.dtmfManager = new JitsiDTMFManager(tracks[0], connection);
  868. }
  869. this.dtmfManager.sendTones(tones, duration, pause);
  870. };
  871. /**
  872. * Returns true if the recording is supproted and false if not.
  873. */
  874. JitsiConference.prototype.isRecordingSupported = function () {
  875. if(this.room)
  876. return this.room.isRecordingSupported();
  877. return false;
  878. };
  879. /**
  880. * Returns null if the recording is not supported, "on" if the recording started
  881. * and "off" if the recording is not started.
  882. */
  883. JitsiConference.prototype.getRecordingState = function () {
  884. return (this.room) ? this.room.getRecordingState() : undefined;
  885. }
  886. /**
  887. * Returns the url of the recorded video.
  888. */
  889. JitsiConference.prototype.getRecordingURL = function () {
  890. return (this.room) ? this.room.getRecordingURL() : null;
  891. }
  892. /**
  893. * Starts/stops the recording
  894. */
  895. JitsiConference.prototype.toggleRecording = function (options) {
  896. if(this.room)
  897. return this.room.toggleRecording(options, function (status, error) {
  898. this.eventEmitter.emit(
  899. JitsiConferenceEvents.RECORDER_STATE_CHANGED, status, error);
  900. }.bind(this));
  901. this.eventEmitter.emit(
  902. JitsiConferenceEvents.RECORDER_STATE_CHANGED, "error",
  903. new Error("The conference is not created yet!"));
  904. }
  905. /**
  906. * Returns true if the SIP calls are supported and false otherwise
  907. */
  908. JitsiConference.prototype.isSIPCallingSupported = function () {
  909. if(this.room)
  910. return this.room.isSIPCallingSupported();
  911. return false;
  912. }
  913. /**
  914. * Dials a number.
  915. * @param number the number
  916. */
  917. JitsiConference.prototype.dial = function (number) {
  918. if(this.room)
  919. return this.room.dial(number);
  920. return new Promise(function(resolve, reject){
  921. reject(new Error("The conference is not created yet!"))});
  922. }
  923. /**
  924. * Hangup an existing call
  925. */
  926. JitsiConference.prototype.hangup = function () {
  927. if(this.room)
  928. return this.room.hangup();
  929. return new Promise(function(resolve, reject){
  930. reject(new Error("The conference is not created yet!"))});
  931. }
  932. /**
  933. * Returns the phone number for joining the conference.
  934. */
  935. JitsiConference.prototype.getPhoneNumber = function () {
  936. if(this.room)
  937. return this.room.getPhoneNumber();
  938. return null;
  939. }
  940. /**
  941. * Returns the pin for joining the conference with phone.
  942. */
  943. JitsiConference.prototype.getPhonePin = function () {
  944. if(this.room)
  945. return this.room.getPhonePin();
  946. return null;
  947. }
  948. /**
  949. * Returns the connection state for the current room. Its ice connection state
  950. * for its session.
  951. */
  952. JitsiConference.prototype.getConnectionState = function () {
  953. if(this.room)
  954. return this.room.getConnectionState();
  955. return null;
  956. }
  957. /**
  958. * Make all new participants mute their audio/video on join.
  959. * @param policy {Object} object with 2 boolean properties for video and audio:
  960. * @param {boolean} audio if audio should be muted.
  961. * @param {boolean} video if video should be muted.
  962. */
  963. JitsiConference.prototype.setStartMutedPolicy = function (policy) {
  964. if (!this.isModerator()) {
  965. return;
  966. }
  967. this.startMutedPolicy = policy;
  968. this.room.removeFromPresence("startmuted");
  969. this.room.addToPresence("startmuted", {
  970. attributes: {
  971. audio: policy.audio,
  972. video: policy.video,
  973. xmlns: 'http://jitsi.org/jitmeet/start-muted'
  974. }
  975. });
  976. this.room.sendPresence();
  977. };
  978. /**
  979. * Returns current start muted policy
  980. * @returns {Object} with 2 proprties - audio and video.
  981. */
  982. JitsiConference.prototype.getStartMutedPolicy = function () {
  983. return this.startMutedPolicy;
  984. };
  985. /**
  986. * Check if audio is muted on join.
  987. */
  988. JitsiConference.prototype.isStartAudioMuted = function () {
  989. return this.startAudioMuted;
  990. };
  991. /**
  992. * Check if video is muted on join.
  993. */
  994. JitsiConference.prototype.isStartVideoMuted = function () {
  995. return this.startVideoMuted;
  996. };
  997. /**
  998. * Get object with internal logs.
  999. */
  1000. JitsiConference.prototype.getLogs = function () {
  1001. var data = this.xmpp.getJingleLog();
  1002. var metadata = {};
  1003. metadata.time = new Date();
  1004. metadata.url = window.location.href;
  1005. metadata.ua = navigator.userAgent;
  1006. var log = this.xmpp.getXmppLog();
  1007. if (log) {
  1008. metadata.xmpp = log;
  1009. }
  1010. data.metadata = metadata;
  1011. return data;
  1012. };
  1013. /**
  1014. * Returns measured connectionTimes.
  1015. */
  1016. JitsiConference.prototype.getConnectionTimes = function () {
  1017. return this.room.connectionTimes;
  1018. };
  1019. /**
  1020. * Sets a property for the local participant.
  1021. */
  1022. JitsiConference.prototype.setLocalParticipantProperty = function(name, value) {
  1023. this.sendCommand("jitsi_participant_" + name, {value: value});
  1024. };
  1025. /**
  1026. * Sends the given feedback through CallStats if enabled.
  1027. *
  1028. * @param overallFeedback an integer between 1 and 5 indicating the
  1029. * user feedback
  1030. * @param detailedFeedback detailed feedback from the user. Not yet used
  1031. */
  1032. JitsiConference.prototype.sendFeedback =
  1033. function(overallFeedback, detailedFeedback){
  1034. this.statistics.sendFeedback(overallFeedback, detailedFeedback);
  1035. }
  1036. /**
  1037. * Returns true if the callstats integration is enabled, otherwise returns
  1038. * false.
  1039. *
  1040. * @returns true if the callstats integration is enabled, otherwise returns
  1041. * false.
  1042. */
  1043. JitsiConference.prototype.isCallstatsEnabled = function () {
  1044. return this.statistics.isCallstatsEnabled();
  1045. }
  1046. /**
  1047. * Handles track attached to container (Calls associateStreamWithVideoTag method
  1048. * from statistics module)
  1049. * @param track the track
  1050. * @param container the container
  1051. */
  1052. JitsiConference.prototype._onTrackAttach = function(track, container) {
  1053. var ssrc = track.getSSRC();
  1054. if (!container.id || !ssrc) {
  1055. return;
  1056. }
  1057. this.statistics.associateStreamWithVideoTag(
  1058. ssrc, track.isLocal(), track.getUsageLabel(), container.id);
  1059. }
  1060. /**
  1061. * Reports detected audio problem with the media stream related to the passed
  1062. * ssrc.
  1063. * @param ssrc {string} the ssrc
  1064. * NOTE: all logger.log calls are there only to be able to see the info in
  1065. * torture
  1066. */
  1067. JitsiConference.prototype._reportAudioProblem = function (ssrc) {
  1068. if(this.reportedAudioSSRCs[ssrc])
  1069. return;
  1070. var track = this.rtc.getRemoteTrackBySSRC(ssrc);
  1071. if(!track || !track.isAudioTrack())
  1072. return;
  1073. var id = track.getParticipantId();
  1074. var displayName = null;
  1075. if(id) {
  1076. var participant = this.getParticipantById(id);
  1077. if(participant) {
  1078. displayName = participant.getDisplayName();
  1079. }
  1080. }
  1081. this.reportedAudioSSRCs[ssrc] = true;
  1082. var errorContent = {
  1083. errMsg: "The audio is received but not played",
  1084. ssrc: ssrc,
  1085. jid: id,
  1086. displayName: displayName
  1087. };
  1088. logger.log("=================The audio is received but not played" +
  1089. "======================");
  1090. logger.log("ssrc: ", ssrc);
  1091. logger.log("jid: ", id);
  1092. logger.log("displayName: ", displayName);
  1093. var mstream = track.stream, mtrack = track.track;
  1094. if(mstream) {
  1095. logger.log("MediaStream:");
  1096. errorContent.MediaStream = {
  1097. active: mstream.active,
  1098. id: mstream.id
  1099. };
  1100. logger.log("active: ", mstream.active);
  1101. logger.log("id: ", mstream.id);
  1102. }
  1103. if(mtrack) {
  1104. logger.log("MediaStreamTrack:");
  1105. errorContent.MediaStreamTrack = {
  1106. enabled: mtrack.enabled,
  1107. id: mtrack.id,
  1108. label: mtrack.label,
  1109. muted: mtrack.muted
  1110. }
  1111. logger.log("enabled: ", mtrack.enabled);
  1112. logger.log("id: ", mtrack.id);
  1113. logger.log("label: ", mtrack.label);
  1114. logger.log("muted: ", mtrack.muted);
  1115. }
  1116. if(track.containers) {
  1117. errorContent.containers = [];
  1118. logger.log("Containers:");
  1119. track.containers.forEach(function (container) {
  1120. logger.log("Container:");
  1121. errorContent.containers.push({
  1122. autoplay: container.autoplay,
  1123. muted: container.muted,
  1124. src: container.src,
  1125. volume: container.volume,
  1126. id: container.id,
  1127. ended: container.ended,
  1128. paused: container.paused,
  1129. readyState: container.readyState
  1130. });
  1131. logger.log("autoplay: ", container.autoplay);
  1132. logger.log("muted: ", container.muted);
  1133. logger.log("src: ", container.src);
  1134. logger.log("volume: ", container.volume);
  1135. logger.log("id: ", container.id);
  1136. logger.log("ended: ", container.ended);
  1137. logger.log("paused: ", container.paused);
  1138. logger.log("readyState: ", container.readyState);
  1139. });
  1140. }
  1141. // Prints JSON.stringify(errorContent) to be able to see all properties of
  1142. // errorContent from torture
  1143. logger.error("Audio problem detected. The audio is received but not played",
  1144. errorContent);
  1145. delete errorContent.displayName;
  1146. this.statistics.sendDetectedAudioProblem(
  1147. new Error(JSON.stringify(errorContent)));
  1148. };
  1149. /**
  1150. * Logs an "application log" message.
  1151. * @param message {string} The message to log. Note that while this can be a
  1152. * generic string, the convention used by lib-jitsi-meet and jitsi-meet is to
  1153. * log valid JSON strings, with an "id" field used for distinguishing between
  1154. * message types. E.g.: {id: "recorder_status", status: "off"}
  1155. */
  1156. JitsiConference.prototype.sendApplicationLog = function(message) {
  1157. Statistics.sendLog(message);
  1158. };
  1159. /**
  1160. * Checks if the user identified by given <tt>mucJid</tt> is the conference
  1161. * focus.
  1162. * @param mucJid the full MUC address of the user to be checked.
  1163. * @returns {boolean} <tt>true</tt> if MUC user is the conference focus.
  1164. */
  1165. JitsiConference.prototype._isFocus = function (mucJid) {
  1166. return this.room.isFocus(mucJid);
  1167. };
  1168. /**
  1169. * Fires CONFERENCE_FAILED event with INCOMPATIBLE_SERVER_VERSIONS parameter
  1170. */
  1171. JitsiConference.prototype._fireIncompatibleVersionsEvent = function () {
  1172. this.eventEmitter.emit(JitsiConferenceEvents.CONFERENCE_FAILED,
  1173. JitsiConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS);
  1174. };
  1175. /**
  1176. * Sends message via the datachannels.
  1177. * @param to {string} the id of the endpoint that should receive the message.
  1178. * If "" the message will be sent to all participants.
  1179. * @param payload {object} the payload of the message.
  1180. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  1181. */
  1182. JitsiConference.prototype.sendEndpointMessage = function (to, payload) {
  1183. this.rtc.sendDataChannelMessage(to, payload);
  1184. }
  1185. /**
  1186. * Sends broadcast message via the datachannels.
  1187. * @param payload {object} the payload of the message.
  1188. * @throws NetworkError or InvalidStateError or Error if the operation fails.
  1189. */
  1190. JitsiConference.prototype.broadcastEndpointMessage = function (payload) {
  1191. this.sendEndpointMessage("", payload);
  1192. }
  1193. module.exports = JitsiConference;