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

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