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 43KB

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