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

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