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.

external_api.js 35KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. import { jitsiLocalStorage } from '@jitsi/js-utils/jitsi-local-storage';
  2. import EventEmitter from 'events';
  3. import { urlObjectToString } from '../../../react/features/base/util/uri';
  4. import {
  5. PostMessageTransportBackend,
  6. Transport
  7. } from '../../transport';
  8. import {
  9. getAvailableDevices,
  10. getCurrentDevices,
  11. isDeviceChangeAvailable,
  12. isDeviceListAvailable,
  13. isMultipleAudioInputSupported,
  14. setAudioInputDevice,
  15. setAudioOutputDevice,
  16. setVideoInputDevice
  17. } from './functions';
  18. const ALWAYS_ON_TOP_FILENAMES = [
  19. 'css/all.css', 'libs/alwaysontop.min.js'
  20. ];
  21. /**
  22. * Maps the names of the commands expected by the API with the name of the
  23. * commands expected by jitsi-meet
  24. */
  25. const commands = {
  26. avatarUrl: 'avatar-url',
  27. displayName: 'display-name',
  28. e2eeKey: 'e2ee-key',
  29. email: 'email',
  30. toggleLobby: 'toggle-lobby',
  31. hangup: 'video-hangup',
  32. muteEveryone: 'mute-everyone',
  33. password: 'password',
  34. pinParticipant: 'pin-participant',
  35. resizeLargeVideo: 'resize-large-video',
  36. sendEndpointTextMessage: 'send-endpoint-text-message',
  37. sendTones: 'send-tones',
  38. setLargeVideoParticipant: 'set-large-video-participant',
  39. setVideoQuality: 'set-video-quality',
  40. startRecording: 'start-recording',
  41. stopRecording: 'stop-recording',
  42. subject: 'subject',
  43. submitFeedback: 'submit-feedback',
  44. toggleAudio: 'toggle-audio',
  45. toggleChat: 'toggle-chat',
  46. toggleFilmStrip: 'toggle-film-strip',
  47. toggleShareScreen: 'toggle-share-screen',
  48. toggleTileView: 'toggle-tile-view',
  49. toggleVideo: 'toggle-video'
  50. };
  51. /**
  52. * Maps the names of the events expected by the API with the name of the
  53. * events expected by jitsi-meet
  54. */
  55. const events = {
  56. 'avatar-changed': 'avatarChanged',
  57. 'audio-availability-changed': 'audioAvailabilityChanged',
  58. 'audio-mute-status-changed': 'audioMuteStatusChanged',
  59. 'camera-error': 'cameraError',
  60. 'device-list-changed': 'deviceListChanged',
  61. 'display-name-change': 'displayNameChange',
  62. 'email-change': 'emailChange',
  63. 'endpoint-text-message-received': 'endpointTextMessageReceived',
  64. 'feedback-submitted': 'feedbackSubmitted',
  65. 'feedback-prompt-displayed': 'feedbackPromptDisplayed',
  66. 'filmstrip-display-changed': 'filmstripDisplayChanged',
  67. 'incoming-message': 'incomingMessage',
  68. 'log': 'log',
  69. 'mic-error': 'micError',
  70. 'outgoing-message': 'outgoingMessage',
  71. 'participant-joined': 'participantJoined',
  72. 'participant-kicked-out': 'participantKickedOut',
  73. 'participant-left': 'participantLeft',
  74. 'participant-role-changed': 'participantRoleChanged',
  75. 'password-required': 'passwordRequired',
  76. 'proxy-connection-event': 'proxyConnectionEvent',
  77. 'raise-hand-updated': 'raiseHandUpdated',
  78. 'video-ready-to-close': 'readyToClose',
  79. 'video-conference-joined': 'videoConferenceJoined',
  80. 'video-conference-left': 'videoConferenceLeft',
  81. 'video-availability-changed': 'videoAvailabilityChanged',
  82. 'video-mute-status-changed': 'videoMuteStatusChanged',
  83. 'video-quality-changed': 'videoQualityChanged',
  84. 'screen-sharing-status-changed': 'screenSharingStatusChanged',
  85. 'dominant-speaker-changed': 'dominantSpeakerChanged',
  86. 'subject-change': 'subjectChange',
  87. 'suspend-detected': 'suspendDetected',
  88. 'tile-view-changed': 'tileViewChanged'
  89. };
  90. /**
  91. * Last id of api object
  92. * @type {number}
  93. */
  94. let id = 0;
  95. /**
  96. * Adds given number to the numberOfParticipants property of given APIInstance.
  97. *
  98. * @param {JitsiMeetExternalAPI} APIInstance - The instance of the API.
  99. * @param {int} number - The number of participants to be added to
  100. * numberOfParticipants property (this parameter can be negative number if the
  101. * numberOfParticipants should be decreased).
  102. * @returns {void}
  103. */
  104. function changeParticipantNumber(APIInstance, number) {
  105. APIInstance._numberOfParticipants += number;
  106. }
  107. /**
  108. * Generates the URL for the iframe.
  109. *
  110. * @param {string} domain - The domain name of the server that hosts the
  111. * conference.
  112. * @param {string} [options] - Another optional parameters.
  113. * @param {Object} [options.configOverwrite] - Object containing configuration
  114. * options defined in config.js to be overridden.
  115. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  116. * configuration options defined in interface_config.js to be overridden.
  117. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  118. * authentication.
  119. * @param {string} [options.roomName] - The name of the room to join.
  120. * @returns {string} The URL.
  121. */
  122. function generateURL(domain, options = {}) {
  123. return urlObjectToString({
  124. ...options,
  125. url: `https://${domain}/#jitsi_meet_external_api_id=${id}`
  126. });
  127. }
  128. /**
  129. * Parses the arguments passed to the constructor. If the old format is used
  130. * the function translates the arguments to the new format.
  131. *
  132. * @param {Array} args - The arguments to be parsed.
  133. * @returns {Object} JS object with properties.
  134. */
  135. function parseArguments(args) {
  136. if (!args.length) {
  137. return {};
  138. }
  139. const firstArg = args[0];
  140. switch (typeof firstArg) {
  141. case 'string': // old arguments format
  142. case undefined: {
  143. // Not sure which format but we are trying to parse the old
  144. // format because if the new format is used everything will be undefined
  145. // anyway.
  146. const [
  147. roomName,
  148. width,
  149. height,
  150. parentNode,
  151. configOverwrite,
  152. interfaceConfigOverwrite,
  153. jwt,
  154. onload
  155. ] = args;
  156. return {
  157. roomName,
  158. width,
  159. height,
  160. parentNode,
  161. configOverwrite,
  162. interfaceConfigOverwrite,
  163. jwt,
  164. onload
  165. };
  166. }
  167. case 'object': // new arguments format
  168. return args[0];
  169. default:
  170. throw new Error('Can\'t parse the arguments!');
  171. }
  172. }
  173. /**
  174. * Compute valid values for height and width. If a number is specified it's
  175. * treated as pixel units. If the value is expressed in px, em, pt or
  176. * percentage, it's used as is.
  177. *
  178. * @param {any} value - The value to be parsed.
  179. * @returns {string|undefined} The parsed value that can be used for setting
  180. * sizes through the style property. If invalid value is passed the method
  181. * retuns undefined.
  182. */
  183. function parseSizeParam(value) {
  184. let parsedValue;
  185. // This regex parses values of the form 100px, 100em, 100pt or 100%.
  186. // Values like 100 or 100px are handled outside of the regex, and
  187. // invalid values will be ignored and the minimum will be used.
  188. const re = /([0-9]*\.?[0-9]+)(em|pt|px|%)$/;
  189. if (typeof value === 'string' && String(value).match(re) !== null) {
  190. parsedValue = value;
  191. } else if (typeof value === 'number') {
  192. parsedValue = `${value}px`;
  193. }
  194. return parsedValue;
  195. }
  196. /**
  197. * The IFrame API interface class.
  198. */
  199. export default class JitsiMeetExternalAPI extends EventEmitter {
  200. /**
  201. * Constructs new API instance. Creates iframe and loads Jitsi Meet in it.
  202. *
  203. * @param {string} domain - The domain name of the server that hosts the
  204. * conference.
  205. * @param {Object} [options] - Optional arguments.
  206. * @param {string} [options.roomName] - The name of the room to join.
  207. * @param {number|string} [options.width] - Width of the iframe. Check
  208. * parseSizeParam for format details.
  209. * @param {number|string} [options.height] - Height of the iframe. Check
  210. * parseSizeParam for format details.
  211. * @param {DOMElement} [options.parentNode] - The node that will contain the
  212. * iframe.
  213. * @param {Object} [options.configOverwrite] - Object containing
  214. * configuration options defined in config.js to be overridden.
  215. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  216. * configuration options defined in interface_config.js to be overridden.
  217. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  218. * authentication.
  219. * @param {string} [options.onload] - The onload function that will listen
  220. * for iframe onload event.
  221. * @param {Array<Object>} [options.invitees] - Array of objects containing
  222. * information about new participants that will be invited in the call.
  223. * @param {Array<Object>} [options.devices] - Array of objects containing
  224. * information about the initial devices that will be used in the call.
  225. * @param {Object} [options.userInfo] - Object containing information about
  226. * the participant opening the meeting.
  227. * @param {string} [options.e2eeKey] - The key used for End-to-End encryption.
  228. * THIS IS EXPERIMENTAL.
  229. */
  230. constructor(domain, ...args) {
  231. super();
  232. const {
  233. roomName = '',
  234. width = '100%',
  235. height = '100%',
  236. parentNode = document.body,
  237. configOverwrite = {},
  238. interfaceConfigOverwrite = {},
  239. jwt = undefined,
  240. onload = undefined,
  241. invitees,
  242. devices,
  243. userInfo,
  244. e2eeKey
  245. } = parseArguments(args);
  246. const localStorageContent = jitsiLocalStorage.getItem('jitsiLocalStorage');
  247. this._parentNode = parentNode;
  248. this._url = generateURL(domain, {
  249. configOverwrite,
  250. interfaceConfigOverwrite,
  251. jwt,
  252. roomName,
  253. devices,
  254. userInfo,
  255. appData: {
  256. localStorageContent
  257. }
  258. });
  259. this._createIFrame(height, width, onload);
  260. this._transport = new Transport({
  261. backend: new PostMessageTransportBackend({
  262. postisOptions: {
  263. allowedOrigin: new URL(this._url).origin,
  264. scope: `jitsi_meet_external_api_${id}`,
  265. window: this._frame.contentWindow
  266. }
  267. })
  268. });
  269. if (Array.isArray(invitees) && invitees.length > 0) {
  270. this.invite(invitees);
  271. }
  272. this._tmpE2EEKey = e2eeKey;
  273. this._isLargeVideoVisible = true;
  274. this._numberOfParticipants = 0;
  275. this._participants = {};
  276. this._myUserID = undefined;
  277. this._onStageParticipant = undefined;
  278. this._setupListeners();
  279. id++;
  280. }
  281. /**
  282. * Creates the iframe element.
  283. *
  284. * @param {number|string} height - The height of the iframe. Check
  285. * parseSizeParam for format details.
  286. * @param {number|string} width - The with of the iframe. Check
  287. * parseSizeParam for format details.
  288. * @param {Function} onload - The function that will listen
  289. * for onload event.
  290. * @returns {void}
  291. *
  292. * @private
  293. */
  294. _createIFrame(height, width, onload) {
  295. const frameName = `jitsiConferenceFrame${id}`;
  296. this._frame = document.createElement('iframe');
  297. this._frame.allow = 'camera; microphone; display-capture';
  298. this._frame.src = this._url;
  299. this._frame.name = frameName;
  300. this._frame.id = frameName;
  301. this._setSize(height, width);
  302. this._frame.setAttribute('allowFullScreen', 'true');
  303. this._frame.style.border = 0;
  304. if (onload) {
  305. // waits for iframe resources to load
  306. // and fires event when it is done
  307. this._frame.onload = onload;
  308. }
  309. this._frame = this._parentNode.appendChild(this._frame);
  310. }
  311. /**
  312. * Returns arrays with the all resources for the always on top feature.
  313. *
  314. * @returns {Array<string>}
  315. */
  316. _getAlwaysOnTopResources() {
  317. const iframeWindow = this._frame.contentWindow;
  318. const iframeDocument = iframeWindow.document;
  319. let baseURL = '';
  320. const base = iframeDocument.querySelector('base');
  321. if (base && base.href) {
  322. baseURL = base.href;
  323. } else {
  324. const { protocol, host } = iframeWindow.location;
  325. baseURL = `${protocol}//${host}`;
  326. }
  327. return ALWAYS_ON_TOP_FILENAMES.map(
  328. filename => (new URL(filename, baseURL)).href
  329. );
  330. }
  331. /**
  332. * Returns the formatted display name of a participant.
  333. *
  334. * @param {string} participantId - The id of the participant.
  335. * @returns {string} The formatted display name.
  336. */
  337. _getFormattedDisplayName(participantId) {
  338. const { formattedDisplayName }
  339. = this._participants[participantId] || {};
  340. return formattedDisplayName;
  341. }
  342. /**
  343. * Returns the id of the on stage participant.
  344. *
  345. * @returns {string} - The id of the on stage participant.
  346. */
  347. _getOnStageParticipant() {
  348. return this._onStageParticipant;
  349. }
  350. /**
  351. * Getter for the large video element in Jitsi Meet.
  352. *
  353. * @returns {HTMLElement|undefined} - The large video.
  354. */
  355. _getLargeVideo() {
  356. const iframe = this.getIFrame();
  357. if (!this._isLargeVideoVisible
  358. || !iframe
  359. || !iframe.contentWindow
  360. || !iframe.contentWindow.document) {
  361. return;
  362. }
  363. return iframe.contentWindow.document.getElementById('largeVideo');
  364. }
  365. /**
  366. * Getter for participant specific video element in Jitsi Meet.
  367. *
  368. * @param {string|undefined} participantId - Id of participant to return the video for.
  369. *
  370. * @returns {HTMLElement|undefined} - The requested video. Will return the local video
  371. * by default if participantId is undefined.
  372. */
  373. _getParticipantVideo(participantId) {
  374. const iframe = this.getIFrame();
  375. if (!iframe
  376. || !iframe.contentWindow
  377. || !iframe.contentWindow.document) {
  378. return;
  379. }
  380. if (typeof participantId === 'undefined' || participantId === this._myUserID) {
  381. return iframe.contentWindow.document.getElementById('localVideo_container');
  382. }
  383. return iframe.contentWindow.document.querySelector(`#participant_${participantId} video`);
  384. }
  385. /**
  386. * Sets the size of the iframe element.
  387. *
  388. * @param {number|string} height - The height of the iframe.
  389. * @param {number|string} width - The with of the iframe.
  390. * @returns {void}
  391. *
  392. * @private
  393. */
  394. _setSize(height, width) {
  395. const parsedHeight = parseSizeParam(height);
  396. const parsedWidth = parseSizeParam(width);
  397. if (parsedHeight !== undefined) {
  398. this._height = height;
  399. this._frame.style.height = parsedHeight;
  400. }
  401. if (parsedWidth !== undefined) {
  402. this._width = width;
  403. this._frame.style.width = parsedWidth;
  404. }
  405. }
  406. /**
  407. * Setups listeners that are used internally for JitsiMeetExternalAPI.
  408. *
  409. * @returns {void}
  410. *
  411. * @private
  412. */
  413. _setupListeners() {
  414. this._transport.on('event', ({ name, ...data }) => {
  415. const userID = data.id;
  416. switch (name) {
  417. case 'video-conference-joined': {
  418. if (typeof this._tmpE2EEKey !== 'undefined') {
  419. this.executeCommand(commands.e2eeKey, this._tmpE2EEKey);
  420. this._tmpE2EEKey = undefined;
  421. }
  422. this._myUserID = userID;
  423. this._participants[userID] = {
  424. avatarURL: data.avatarURL
  425. };
  426. }
  427. // eslint-disable-next-line no-fallthrough
  428. case 'participant-joined': {
  429. this._participants[userID] = this._participants[userID] || {};
  430. this._participants[userID].displayName = data.displayName;
  431. this._participants[userID].formattedDisplayName
  432. = data.formattedDisplayName;
  433. changeParticipantNumber(this, 1);
  434. break;
  435. }
  436. case 'participant-left':
  437. changeParticipantNumber(this, -1);
  438. delete this._participants[userID];
  439. break;
  440. case 'display-name-change': {
  441. const user = this._participants[userID];
  442. if (user) {
  443. user.displayName = data.displayname;
  444. user.formattedDisplayName = data.formattedDisplayName;
  445. }
  446. break;
  447. }
  448. case 'email-change': {
  449. const user = this._participants[userID];
  450. if (user) {
  451. user.email = data.email;
  452. }
  453. break;
  454. }
  455. case 'avatar-changed': {
  456. const user = this._participants[userID];
  457. if (user) {
  458. user.avatarURL = data.avatarURL;
  459. }
  460. break;
  461. }
  462. case 'on-stage-participant-changed':
  463. this._onStageParticipant = userID;
  464. this.emit('largeVideoChanged');
  465. break;
  466. case 'large-video-visibility-changed':
  467. this._isLargeVideoVisible = data.isVisible;
  468. this.emit('largeVideoChanged');
  469. break;
  470. case 'video-conference-left':
  471. changeParticipantNumber(this, -1);
  472. delete this._participants[this._myUserID];
  473. break;
  474. case 'video-quality-changed':
  475. this._videoQuality = data.videoQuality;
  476. break;
  477. case 'local-storage-changed':
  478. jitsiLocalStorage.setItem('jitsiLocalStorage', data.localStorageContent);
  479. // Since this is internal event we don't need to emit it to the consumer of the API.
  480. return true;
  481. }
  482. const eventName = events[name];
  483. if (eventName) {
  484. this.emit(eventName, data);
  485. return true;
  486. }
  487. return false;
  488. });
  489. }
  490. /**
  491. * Adds event listener to Meet Jitsi.
  492. *
  493. * @param {string} event - The name of the event.
  494. * @param {Function} listener - The listener.
  495. * @returns {void}
  496. *
  497. * @deprecated
  498. * NOTE: This method is not removed for backward comatability purposes.
  499. */
  500. addEventListener(event, listener) {
  501. this.on(event, listener);
  502. }
  503. /**
  504. * Adds event listeners to Meet Jitsi.
  505. *
  506. * @param {Object} listeners - The object key should be the name of
  507. * the event and value - the listener.
  508. * Currently we support the following
  509. * events:
  510. * {@code log} - receives event notifications whenever information has
  511. * been logged and has a log level specified within {@code config.apiLogLevels}.
  512. * The listener will receive object with the following structure:
  513. * {{
  514. * logLevel: the message log level
  515. * arguments: an array of strings that compose the actual log message
  516. * }}
  517. * {@code incomingMessage} - receives event notifications about incoming
  518. * messages. The listener will receive object with the following structure:
  519. * {{
  520. * 'from': from,//JID of the user that sent the message
  521. * 'nick': nick,//the nickname of the user that sent the message
  522. * 'message': txt//the text of the message
  523. * }}
  524. * {@code outgoingMessage} - receives event notifications about outgoing
  525. * messages. The listener will receive object with the following structure:
  526. * {{
  527. * 'message': txt//the text of the message
  528. * }}
  529. * {@code displayNameChanged} - receives event notifications about display
  530. * name change. The listener will receive object with the following
  531. * structure:
  532. * {{
  533. * jid: jid,//the JID of the participant that changed his display name
  534. * displayname: displayName //the new display name
  535. * }}
  536. * {@code participantJoined} - receives event notifications about new
  537. * participant.
  538. * The listener will receive object with the following structure:
  539. * {{
  540. * jid: jid //the jid of the participant
  541. * }}
  542. * {@code participantLeft} - receives event notifications about the
  543. * participant that left the room.
  544. * The listener will receive object with the following structure:
  545. * {{
  546. * jid: jid //the jid of the participant
  547. * }}
  548. * {@code videoConferenceJoined} - receives event notifications about the
  549. * local user has successfully joined the video conference.
  550. * The listener will receive object with the following structure:
  551. * {{
  552. * roomName: room //the room name of the conference
  553. * }}
  554. * {@code videoConferenceLeft} - receives event notifications about the
  555. * local user has left the video conference.
  556. * The listener will receive object with the following structure:
  557. * {{
  558. * roomName: room //the room name of the conference
  559. * }}
  560. * {@code screenSharingStatusChanged} - receives event notifications about
  561. * turning on/off the local user screen sharing.
  562. * The listener will receive object with the following structure:
  563. * {{
  564. * on: on //whether screen sharing is on
  565. * }}
  566. * {@code dominantSpeakerChanged} - receives event notifications about
  567. * change in the dominant speaker.
  568. * The listener will receive object with the following structure:
  569. * {{
  570. * id: participantId //participantId of the new dominant speaker
  571. * }}
  572. * {@code suspendDetected} - receives event notifications about detecting suspend event in host computer.
  573. * {@code readyToClose} - all hangup operations are completed and Jitsi Meet
  574. * is ready to be disposed.
  575. * @returns {void}
  576. *
  577. * @deprecated
  578. * NOTE: This method is not removed for backward comatability purposes.
  579. */
  580. addEventListeners(listeners) {
  581. for (const event in listeners) { // eslint-disable-line guard-for-in
  582. this.addEventListener(event, listeners[event]);
  583. }
  584. }
  585. /**
  586. * Captures the screenshot of the large video.
  587. *
  588. * @returns {Promise<string>} - Resolves with a base64 encoded image data of the screenshot
  589. * if large video is detected, an error otherwise.
  590. */
  591. captureLargeVideoScreenshot() {
  592. return this._transport.sendRequest({
  593. name: 'capture-largevideo-screenshot'
  594. });
  595. }
  596. /**
  597. * Removes the listeners and removes the Jitsi Meet frame.
  598. *
  599. * @returns {void}
  600. */
  601. dispose() {
  602. this.emit('_willDispose');
  603. this._transport.dispose();
  604. this.removeAllListeners();
  605. if (this._frame && this._frame.parentNode) {
  606. this._frame.parentNode.removeChild(this._frame);
  607. }
  608. }
  609. /**
  610. * Executes command. The available commands are:
  611. * {@code displayName} - Sets the display name of the local participant to
  612. * the value passed in the arguments array.
  613. * {@code subject} - Sets the subject of the conference, the value passed
  614. * in the arguments array. Note: Available only for moderator.
  615. *
  616. * {@code toggleAudio} - Mutes / unmutes audio with no arguments.
  617. * {@code toggleVideo} - Mutes / unmutes video with no arguments.
  618. * {@code toggleFilmStrip} - Hides / shows the filmstrip with no arguments.
  619. *
  620. * If the command doesn't require any arguments the parameter should be set
  621. * to empty array or it may be omitted.
  622. *
  623. * @param {string} name - The name of the command.
  624. * @returns {void}
  625. */
  626. executeCommand(name, ...args) {
  627. if (!(name in commands)) {
  628. console.error('Not supported command name.');
  629. return;
  630. }
  631. this._transport.sendEvent({
  632. data: args,
  633. name: commands[name]
  634. });
  635. }
  636. /**
  637. * Executes commands. The available commands are:
  638. * {@code displayName} - Sets the display name of the local participant to
  639. * the value passed in the arguments array.
  640. * {@code toggleAudio} - Mutes / unmutes audio. No arguments.
  641. * {@code toggleVideo} - Mutes / unmutes video. No arguments.
  642. * {@code toggleFilmStrip} - Hides / shows the filmstrip. No arguments.
  643. * {@code toggleChat} - Hides / shows chat. No arguments.
  644. * {@code toggleShareScreen} - Starts / stops screen sharing. No arguments.
  645. *
  646. * @param {Object} commandList - The object with commands to be executed.
  647. * The keys of the object are the commands that will be executed and the
  648. * values are the arguments for the command.
  649. * @returns {void}
  650. */
  651. executeCommands(commandList) {
  652. for (const key in commandList) { // eslint-disable-line guard-for-in
  653. this.executeCommand(key, commandList[key]);
  654. }
  655. }
  656. /**
  657. * Returns Promise that resolves with a list of available devices.
  658. *
  659. * @returns {Promise}
  660. */
  661. getAvailableDevices() {
  662. return getAvailableDevices(this._transport);
  663. }
  664. /**
  665. * Returns Promise that resolves with current selected devices.
  666. *
  667. * @returns {Promise}
  668. */
  669. getCurrentDevices() {
  670. return getCurrentDevices(this._transport);
  671. }
  672. /**
  673. * Returns the conference participants information.
  674. *
  675. * @returns {Array<Object>} - Returns an array containing participants
  676. * information like participant id, display name, avatar URL and email.
  677. */
  678. getParticipantsInfo() {
  679. const participantIds = Object.keys(this._participants);
  680. const participantsInfo = Object.values(this._participants);
  681. participantsInfo.forEach((participant, idx) => {
  682. participant.participantId = participantIds[idx];
  683. });
  684. return participantsInfo;
  685. }
  686. /**
  687. * Returns the current video quality setting.
  688. *
  689. * @returns {number}
  690. */
  691. getVideoQuality() {
  692. return this._videoQuality;
  693. }
  694. /**
  695. * Check if the audio is available.
  696. *
  697. * @returns {Promise} - Resolves with true if the audio available, with
  698. * false if not and rejects on failure.
  699. */
  700. isAudioAvailable() {
  701. return this._transport.sendRequest({
  702. name: 'is-audio-available'
  703. });
  704. }
  705. /**
  706. * Returns Promise that resolves with true if the device change is available
  707. * and with false if not.
  708. *
  709. * @param {string} [deviceType] - Values - 'output', 'input' or undefined.
  710. * Default - 'input'.
  711. * @returns {Promise}
  712. */
  713. isDeviceChangeAvailable(deviceType) {
  714. return isDeviceChangeAvailable(this._transport, deviceType);
  715. }
  716. /**
  717. * Returns Promise that resolves with true if the device list is available
  718. * and with false if not.
  719. *
  720. * @returns {Promise}
  721. */
  722. isDeviceListAvailable() {
  723. return isDeviceListAvailable(this._transport);
  724. }
  725. /**
  726. * Returns Promise that resolves with true if multiple audio input is supported
  727. * and with false if not.
  728. *
  729. * @returns {Promise}
  730. */
  731. isMultipleAudioInputSupported() {
  732. return isMultipleAudioInputSupported(this._transport);
  733. }
  734. /**
  735. * Invite people to the call.
  736. *
  737. * @param {Array<Object>} invitees - The invitees.
  738. * @returns {Promise} - Resolves on success and rejects on failure.
  739. */
  740. invite(invitees) {
  741. if (!Array.isArray(invitees) || invitees.length === 0) {
  742. return Promise.reject(new TypeError('Invalid Argument'));
  743. }
  744. return this._transport.sendRequest({
  745. name: 'invite',
  746. invitees
  747. });
  748. }
  749. /**
  750. * Returns the audio mute status.
  751. *
  752. * @returns {Promise} - Resolves with the audio mute status and rejects on
  753. * failure.
  754. */
  755. isAudioMuted() {
  756. return this._transport.sendRequest({
  757. name: 'is-audio-muted'
  758. });
  759. }
  760. /**
  761. * Returns screen sharing status.
  762. *
  763. * @returns {Promise} - Resolves with screensharing status and rejects on failure.
  764. */
  765. isSharingScreen() {
  766. return this._transport.sendRequest({
  767. name: 'is-sharing-screen'
  768. });
  769. }
  770. /**
  771. * Returns the avatar URL of a participant.
  772. *
  773. * @param {string} participantId - The id of the participant.
  774. * @returns {string} The avatar URL.
  775. */
  776. getAvatarURL(participantId) {
  777. const { avatarURL } = this._participants[participantId] || {};
  778. return avatarURL;
  779. }
  780. /**
  781. * Returns the display name of a participant.
  782. *
  783. * @param {string} participantId - The id of the participant.
  784. * @returns {string} The display name.
  785. */
  786. getDisplayName(participantId) {
  787. const { displayName } = this._participants[participantId] || {};
  788. return displayName;
  789. }
  790. /**
  791. * Returns the email of a participant.
  792. *
  793. * @param {string} participantId - The id of the participant.
  794. * @returns {string} The email.
  795. */
  796. getEmail(participantId) {
  797. const { email } = this._participants[participantId] || {};
  798. return email;
  799. }
  800. /**
  801. * Returns the iframe that loads Jitsi Meet.
  802. *
  803. * @returns {HTMLElement} The iframe.
  804. */
  805. getIFrame() {
  806. return this._frame;
  807. }
  808. /**
  809. * Returns the number of participants in the conference. The local
  810. * participant is included.
  811. *
  812. * @returns {int} The number of participants in the conference.
  813. */
  814. getNumberOfParticipants() {
  815. return this._numberOfParticipants;
  816. }
  817. /**
  818. * Check if the video is available.
  819. *
  820. * @returns {Promise} - Resolves with true if the video available, with
  821. * false if not and rejects on failure.
  822. */
  823. isVideoAvailable() {
  824. return this._transport.sendRequest({
  825. name: 'is-video-available'
  826. });
  827. }
  828. /**
  829. * Returns the audio mute status.
  830. *
  831. * @returns {Promise} - Resolves with the audio mute status and rejects on
  832. * failure.
  833. */
  834. isVideoMuted() {
  835. return this._transport.sendRequest({
  836. name: 'is-video-muted'
  837. });
  838. }
  839. /**
  840. * Pins a participant's video on to the stage view.
  841. *
  842. * @param {string} participantId - Participant id (JID) of the participant
  843. * that needs to be pinned on the stage view.
  844. * @returns {void}
  845. */
  846. pinParticipant(participantId) {
  847. this.executeCommand('pinParticipant', participantId);
  848. }
  849. /**
  850. * Removes event listener.
  851. *
  852. * @param {string} event - The name of the event.
  853. * @returns {void}
  854. *
  855. * @deprecated
  856. * NOTE: This method is not removed for backward comatability purposes.
  857. */
  858. removeEventListener(event) {
  859. this.removeAllListeners(event);
  860. }
  861. /**
  862. * Removes event listeners.
  863. *
  864. * @param {Array<string>} eventList - Array with the names of the events.
  865. * @returns {void}
  866. *
  867. * @deprecated
  868. * NOTE: This method is not removed for backward comatability purposes.
  869. */
  870. removeEventListeners(eventList) {
  871. eventList.forEach(event => this.removeEventListener(event));
  872. }
  873. /**
  874. * Resizes the large video container as per the dimensions provided.
  875. *
  876. * @param {number} width - Width that needs to be applied on the large video container.
  877. * @param {number} height - Height that needs to be applied on the large video container.
  878. * @returns {void}
  879. */
  880. resizeLargeVideo(width, height) {
  881. if (width <= this._width && height <= this._height) {
  882. this.executeCommand('resizeLargeVideo', width, height);
  883. }
  884. }
  885. /**
  886. * Passes an event along to the local conference participant to establish
  887. * or update a direct peer connection. This is currently used for developing
  888. * wireless screensharing with room integration and it is advised against to
  889. * use as its api may change.
  890. *
  891. * @param {Object} event - An object with information to pass along.
  892. * @param {Object} event.data - The payload of the event.
  893. * @param {string} event.from - The jid of the sender of the event. Needed
  894. * when a reply is to be sent regarding the event.
  895. * @returns {void}
  896. */
  897. sendProxyConnectionEvent(event) {
  898. this._transport.sendEvent({
  899. data: [ event ],
  900. name: 'proxy-connection-event'
  901. });
  902. }
  903. /**
  904. * Sets the audio input device to the one with the label or id that is
  905. * passed.
  906. *
  907. * @param {string} label - The label of the new device.
  908. * @param {string} deviceId - The id of the new device.
  909. * @returns {Promise}
  910. */
  911. setAudioInputDevice(label, deviceId) {
  912. return setAudioInputDevice(this._transport, label, deviceId);
  913. }
  914. /**
  915. * Sets the audio output device to the one with the label or id that is
  916. * passed.
  917. *
  918. * @param {string} label - The label of the new device.
  919. * @param {string} deviceId - The id of the new device.
  920. * @returns {Promise}
  921. */
  922. setAudioOutputDevice(label, deviceId) {
  923. return setAudioOutputDevice(this._transport, label, deviceId);
  924. }
  925. /**
  926. * Displays the given participant on the large video. If no participant id is specified,
  927. * dominant and pinned speakers will be taken into consideration while selecting the
  928. * the large video participant.
  929. *
  930. * @param {string} participantId - Jid of the participant to be displayed on the large video.
  931. * @returns {void}
  932. */
  933. setLargeVideoParticipant(participantId) {
  934. this.executeCommand('setLargeVideoParticipant', participantId);
  935. }
  936. /**
  937. * Sets the video input device to the one with the label or id that is
  938. * passed.
  939. *
  940. * @param {string} label - The label of the new device.
  941. * @param {string} deviceId - The id of the new device.
  942. * @returns {Promise}
  943. */
  944. setVideoInputDevice(label, deviceId) {
  945. return setVideoInputDevice(this._transport, label, deviceId);
  946. }
  947. /**
  948. * Starts a file recording or streaming session depending on the passed on params.
  949. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  950. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  951. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  952. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  953. * No other params should be passed.
  954. *
  955. * @param {Object} options - An object with config options to pass along.
  956. * @param { string } options.mode - Recording mode, either `file` or `stream`.
  957. * @param { string } options.dropboxToken - Dropbox oauth2 token.
  958. * @param { boolean } options.shouldShare - Whether the recording should be shared with the participants or not.
  959. * Only applies to certain jitsi meet deploys.
  960. * @param { string } options.rtmpStreamKey - The RTMP stream key.
  961. * @param { string } options.rtmpBroadcastID - The RTMP broacast ID.
  962. * @param { string } options.youtubeStreamKey - The youtube stream key.
  963. * @param { string } options.youtubeBroadcastID - The youtube broacast ID.
  964. * @returns {void}
  965. */
  966. startRecording(options) {
  967. this.executeCommand('startRecording', options);
  968. }
  969. /**
  970. * Stops a recording or streaming session that is in progress.
  971. *
  972. * @param {string} mode - `file` or `stream`.
  973. * @returns {void}
  974. */
  975. stopRecording(mode) {
  976. this.executeCommand('startRecording', mode);
  977. }
  978. }