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

JitsiConference.js 42KB

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