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

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