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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  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. addBreakoutRoom: 'add-breakout-room',
  27. answerKnockingParticipant: 'answer-knocking-participant',
  28. approveVideo: 'approve-video',
  29. askToUnmute: 'ask-to-unmute',
  30. autoAssignToBreakoutRooms: 'auto-assign-to-breakout-rooms',
  31. avatarUrl: 'avatar-url',
  32. cancelPrivateChat: 'cancel-private-chat',
  33. closeBreakoutRoom: 'close-breakout-room',
  34. displayName: 'display-name',
  35. endConference: 'end-conference',
  36. email: 'email',
  37. grantModerator: 'grant-moderator',
  38. hangup: 'video-hangup',
  39. hideNotification: 'hide-notification',
  40. initiatePrivateChat: 'initiate-private-chat',
  41. joinBreakoutRoom: 'join-breakout-room',
  42. localSubject: 'local-subject',
  43. kickParticipant: 'kick-participant',
  44. muteEveryone: 'mute-everyone',
  45. overwriteConfig: 'overwrite-config',
  46. overwriteNames: 'overwrite-names',
  47. password: 'password',
  48. pinParticipant: 'pin-participant',
  49. rejectParticipant: 'reject-participant',
  50. removeBreakoutRoom: 'remove-breakout-room',
  51. resizeFilmStrip: 'resize-film-strip',
  52. resizeLargeVideo: 'resize-large-video',
  53. sendCameraFacingMode: 'send-camera-facing-mode-message',
  54. sendChatMessage: 'send-chat-message',
  55. sendEndpointTextMessage: 'send-endpoint-text-message',
  56. sendParticipantToRoom: 'send-participant-to-room',
  57. sendTones: 'send-tones',
  58. setAssumedBandwidthBps: 'set-assumed-bandwidth-bps',
  59. setFollowMe: 'set-follow-me',
  60. setLargeVideoParticipant: 'set-large-video-participant',
  61. setMediaEncryptionKey: 'set-media-encryption-key',
  62. setNoiseSuppressionEnabled: 'set-noise-suppression-enabled',
  63. setParticipantVolume: 'set-participant-volume',
  64. setSubtitles: 'set-subtitles',
  65. setTileView: 'set-tile-view',
  66. setVideoQuality: 'set-video-quality',
  67. showNotification: 'show-notification',
  68. startRecording: 'start-recording',
  69. startShareVideo: 'start-share-video',
  70. stopRecording: 'stop-recording',
  71. stopShareVideo: 'stop-share-video',
  72. subject: 'subject',
  73. submitFeedback: 'submit-feedback',
  74. toggleAudio: 'toggle-audio',
  75. toggleCamera: 'toggle-camera',
  76. toggleCameraMirror: 'toggle-camera-mirror',
  77. toggleChat: 'toggle-chat',
  78. toggleE2EE: 'toggle-e2ee',
  79. toggleFilmStrip: 'toggle-film-strip',
  80. toggleLobby: 'toggle-lobby',
  81. toggleModeration: 'toggle-moderation',
  82. toggleNoiseSuppression: 'toggle-noise-suppression',
  83. toggleParticipantsPane: 'toggle-participants-pane',
  84. toggleRaiseHand: 'toggle-raise-hand',
  85. toggleShareScreen: 'toggle-share-screen',
  86. toggleSubtitles: 'toggle-subtitles',
  87. toggleTileView: 'toggle-tile-view',
  88. toggleVirtualBackgroundDialog: 'toggle-virtual-background',
  89. toggleVideo: 'toggle-video',
  90. toggleWhiteboard: 'toggle-whiteboard'
  91. };
  92. /**
  93. * Maps the names of the events expected by the API with the name of the
  94. * events expected by jitsi-meet.
  95. */
  96. const events = {
  97. 'avatar-changed': 'avatarChanged',
  98. 'audio-availability-changed': 'audioAvailabilityChanged',
  99. 'audio-mute-status-changed': 'audioMuteStatusChanged',
  100. 'audio-or-video-sharing-toggled': 'audioOrVideoSharingToggled',
  101. 'breakout-rooms-updated': 'breakoutRoomsUpdated',
  102. 'browser-support': 'browserSupport',
  103. 'camera-error': 'cameraError',
  104. 'chat-updated': 'chatUpdated',
  105. 'compute-pressure-changed': 'computePressureChanged',
  106. 'content-sharing-participants-changed': 'contentSharingParticipantsChanged',
  107. 'data-channel-closed': 'dataChannelClosed',
  108. 'data-channel-opened': 'dataChannelOpened',
  109. 'device-list-changed': 'deviceListChanged',
  110. 'display-name-change': 'displayNameChange',
  111. 'dominant-speaker-changed': 'dominantSpeakerChanged',
  112. 'email-change': 'emailChange',
  113. 'error-occurred': 'errorOccurred',
  114. 'endpoint-text-message-received': 'endpointTextMessageReceived',
  115. 'face-landmark-detected': 'faceLandmarkDetected',
  116. 'feedback-submitted': 'feedbackSubmitted',
  117. 'feedback-prompt-displayed': 'feedbackPromptDisplayed',
  118. 'filmstrip-display-changed': 'filmstripDisplayChanged',
  119. 'incoming-message': 'incomingMessage',
  120. 'knocking-participant': 'knockingParticipant',
  121. 'log': 'log',
  122. 'mic-error': 'micError',
  123. 'moderation-participant-approved': 'moderationParticipantApproved',
  124. 'moderation-participant-rejected': 'moderationParticipantRejected',
  125. 'moderation-status-changed': 'moderationStatusChanged',
  126. 'mouse-enter': 'mouseEnter',
  127. 'mouse-leave': 'mouseLeave',
  128. 'mouse-move': 'mouseMove',
  129. 'non-participant-message-received': 'nonParticipantMessageReceived',
  130. 'notification-triggered': 'notificationTriggered',
  131. 'outgoing-message': 'outgoingMessage',
  132. 'p2p-status-changed': 'p2pStatusChanged',
  133. 'participant-joined': 'participantJoined',
  134. 'participant-kicked-out': 'participantKickedOut',
  135. 'participant-left': 'participantLeft',
  136. 'participant-role-changed': 'participantRoleChanged',
  137. 'participants-pane-toggled': 'participantsPaneToggled',
  138. 'password-required': 'passwordRequired',
  139. 'peer-connection-failure': 'peerConnectionFailure',
  140. 'prejoin-screen-loaded': 'prejoinScreenLoaded',
  141. 'proxy-connection-event': 'proxyConnectionEvent',
  142. 'raise-hand-updated': 'raiseHandUpdated',
  143. 'ready': 'ready',
  144. 'recording-link-available': 'recordingLinkAvailable',
  145. 'recording-status-changed': 'recordingStatusChanged',
  146. 'participant-menu-button-clicked': 'participantMenuButtonClick',
  147. 'video-ready-to-close': 'readyToClose',
  148. 'video-conference-joined': 'videoConferenceJoined',
  149. 'video-conference-left': 'videoConferenceLeft',
  150. 'video-availability-changed': 'videoAvailabilityChanged',
  151. 'video-mute-status-changed': 'videoMuteStatusChanged',
  152. 'video-quality-changed': 'videoQualityChanged',
  153. 'screen-sharing-status-changed': 'screenSharingStatusChanged',
  154. 'subject-change': 'subjectChange',
  155. 'suspend-detected': 'suspendDetected',
  156. 'tile-view-changed': 'tileViewChanged',
  157. 'toolbar-button-clicked': 'toolbarButtonClicked',
  158. 'transcription-chunk-received': 'transcriptionChunkReceived',
  159. 'whiteboard-status-changed': 'whiteboardStatusChanged'
  160. };
  161. const requests = {
  162. '_request-desktop-sources': '_requestDesktopSources'
  163. };
  164. /**
  165. * Last id of api object.
  166. *
  167. * @type {number}
  168. */
  169. let id = 0;
  170. /**
  171. * Adds given number to the numberOfParticipants property of given APIInstance.
  172. *
  173. * @param {JitsiMeetExternalAPI} APIInstance - The instance of the API.
  174. * @param {int} number - The number of participants to be added to
  175. * numberOfParticipants property (this parameter can be negative number if the
  176. * numberOfParticipants should be decreased).
  177. * @returns {void}
  178. */
  179. function changeParticipantNumber(APIInstance, number) {
  180. APIInstance._numberOfParticipants += number;
  181. }
  182. /**
  183. * Generates the URL for the iframe.
  184. *
  185. * @param {string} domain - The domain name of the server that hosts the
  186. * conference.
  187. * @param {string} [options] - Another optional parameters.
  188. * @param {Object} [options.configOverwrite] - Object containing configuration
  189. * options defined in config.js to be overridden.
  190. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  191. * configuration options defined in interface_config.js to be overridden.
  192. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  193. * authentication.
  194. * @param {string} [options.lang] - The meeting's default language.
  195. * @param {string} [options.roomName] - The name of the room to join.
  196. * @returns {string} The URL.
  197. */
  198. function generateURL(domain, options = {}) {
  199. return urlObjectToString({
  200. ...options,
  201. url: `https://${domain}/#jitsi_meet_external_api_id=${id}`
  202. });
  203. }
  204. /**
  205. * Parses the arguments passed to the constructor. If the old format is used
  206. * the function translates the arguments to the new format.
  207. *
  208. * @param {Array} args - The arguments to be parsed.
  209. * @returns {Object} JS object with properties.
  210. */
  211. function parseArguments(args) {
  212. if (!args.length) {
  213. return {};
  214. }
  215. const firstArg = args[0];
  216. switch (typeof firstArg) {
  217. case 'string': // old arguments format
  218. case 'undefined': {
  219. // Not sure which format but we are trying to parse the old
  220. // format because if the new format is used everything will be undefined
  221. // anyway.
  222. const [
  223. roomName,
  224. width,
  225. height,
  226. parentNode,
  227. configOverwrite,
  228. interfaceConfigOverwrite,
  229. jwt,
  230. onload,
  231. lang
  232. ] = args;
  233. return {
  234. roomName,
  235. width,
  236. height,
  237. parentNode,
  238. configOverwrite,
  239. interfaceConfigOverwrite,
  240. jwt,
  241. onload,
  242. lang
  243. };
  244. }
  245. case 'object': // new arguments format
  246. return args[0];
  247. default:
  248. throw new Error('Can\'t parse the arguments!');
  249. }
  250. }
  251. /**
  252. * Compute valid values for height and width. If a number is specified it's
  253. * treated as pixel units. If the value is expressed in px, em, pt or
  254. * percentage, it's used as is.
  255. *
  256. * @param {any} value - The value to be parsed.
  257. * @returns {string|undefined} The parsed value that can be used for setting
  258. * sizes through the style property. If invalid value is passed the method
  259. * returns undefined.
  260. */
  261. function parseSizeParam(value) {
  262. let parsedValue;
  263. // This regex parses values of the form 100px, 100em, 100pt, 100vh, 100vw or 100%.
  264. // Values like 100 or 100px are handled outside of the regex, and
  265. // invalid values will be ignored and the minimum will be used.
  266. const re = /([0-9]*\.?[0-9]+)(em|pt|px|((d|l|s)?v)(h|w)|%)$/;
  267. if (typeof value === 'string' && String(value).match(re) !== null) {
  268. parsedValue = value;
  269. } else if (typeof value === 'number') {
  270. parsedValue = `${value}px`;
  271. }
  272. return parsedValue;
  273. }
  274. /**
  275. * The IFrame API interface class.
  276. */
  277. export default class JitsiMeetExternalAPI extends EventEmitter {
  278. /**
  279. * Constructs new API instance. Creates iframe and loads Jitsi Meet in it.
  280. *
  281. * @param {string} domain - The domain name of the server that hosts the
  282. * conference.
  283. * @param {Object} [options] - Optional arguments.
  284. * @param {string} [options.roomName] - The name of the room to join.
  285. * @param {number|string} [options.width] - Width of the iframe. Check
  286. * parseSizeParam for format details.
  287. * @param {number|string} [options.height] - Height of the iframe. Check
  288. * parseSizeParam for format details.
  289. * @param {DOMElement} [options.parentNode] - The node that will contain the
  290. * iframe.
  291. * @param {Object} [options.configOverwrite] - Object containing
  292. * configuration options defined in config.js to be overridden.
  293. * @param {Object} [options.interfaceConfigOverwrite] - Object containing
  294. * configuration options defined in interface_config.js to be overridden.
  295. * @param {IIceServers} [options.iceServers] - Object with rules that will be used to modify/remove the existing
  296. * ice server configuration.
  297. * NOTE: This property is currently experimental and may be removed in the future!
  298. * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
  299. * authentication.
  300. * @param {string} [options.lang] - The meeting's default language.
  301. * @param {string} [options.onload] - The onload function that will listen
  302. * for iframe onload event.
  303. * @param {Array<Object>} [options.invitees] - Array of objects containing
  304. * information about new participants that will be invited in the call.
  305. * @param {Array<Object>} [options.devices] - Array of objects containing
  306. * information about the initial devices that will be used in the call.
  307. * @param {Object} [options.userInfo] - Object containing information about
  308. * the participant opening the meeting.
  309. * @param {string} [options.e2eeKey] - The key used for End-to-End encryption.
  310. * THIS IS EXPERIMENTAL.
  311. * @param {string} [options.release] - The key used for specifying release if enabled on the backend.
  312. * @param {string} [options.sandbox] - Sandbox directive for the created iframe, if desired.
  313. */
  314. constructor(domain, ...args) {
  315. super();
  316. const {
  317. roomName = '',
  318. width = '100%',
  319. height = '100%',
  320. parentNode = document.body,
  321. configOverwrite = {},
  322. interfaceConfigOverwrite = {},
  323. jwt = undefined,
  324. lang = undefined,
  325. onload = undefined,
  326. invitees,
  327. iceServers,
  328. devices,
  329. userInfo,
  330. e2eeKey,
  331. release,
  332. sandbox = ''
  333. } = parseArguments(args);
  334. const localStorageContent = jitsiLocalStorage.getItem('jitsiLocalStorage');
  335. this._parentNode = parentNode;
  336. this._url = generateURL(domain, {
  337. configOverwrite,
  338. iceServers,
  339. interfaceConfigOverwrite,
  340. jwt,
  341. lang,
  342. roomName,
  343. devices,
  344. userInfo,
  345. appData: {
  346. localStorageContent
  347. },
  348. release
  349. });
  350. this._createIFrame(height, width, sandbox);
  351. this._transport = new Transport({
  352. backend: new PostMessageTransportBackend({
  353. postisOptions: {
  354. allowedOrigin: new URL(this._url).origin,
  355. scope: `jitsi_meet_external_api_${id}`,
  356. window: this._frame.contentWindow
  357. }
  358. })
  359. });
  360. if (Array.isArray(invitees) && invitees.length > 0) {
  361. this.invite(invitees);
  362. }
  363. this._onload = onload;
  364. this._tmpE2EEKey = e2eeKey;
  365. this._isLargeVideoVisible = false;
  366. this._isPrejoinVideoVisible = false;
  367. this._numberOfParticipants = 0;
  368. this._participants = {};
  369. this._myUserID = undefined;
  370. this._onStageParticipant = undefined;
  371. this._setupListeners();
  372. id++;
  373. }
  374. /**
  375. * Creates the iframe element.
  376. *
  377. * @param {number|string} height - The height of the iframe. Check
  378. * parseSizeParam for format details.
  379. * @param {number|string} width - The with of the iframe. Check
  380. * parseSizeParam for format details.
  381. * @param {string} sandbox - Sandbox directive for the created iframe, if desired.
  382. * @returns {void}
  383. *
  384. * @private
  385. */
  386. _createIFrame(height, width, sandbox) {
  387. const frameName = `jitsiConferenceFrame${id}`;
  388. this._frame = document.createElement('iframe');
  389. this._frame.allow = [
  390. 'autoplay',
  391. 'camera',
  392. 'clipboard-write',
  393. 'compute-pressure',
  394. 'display-capture',
  395. 'hid',
  396. 'microphone',
  397. 'screen-wake-lock',
  398. 'speaker-selection'
  399. ].join('; ');
  400. this._frame.name = frameName;
  401. this._frame.id = frameName;
  402. this._setSize(height, width);
  403. this._frame.setAttribute('allowFullScreen', 'true');
  404. this._frame.style.border = 0;
  405. if (sandbox) {
  406. this._frame.sandbox = sandbox;
  407. }
  408. this._frame.src = this._url;
  409. this._frame = this._parentNode.appendChild(this._frame);
  410. }
  411. /**
  412. * Returns arrays with the all resources for the always on top feature.
  413. *
  414. * @returns {Array<string>}
  415. */
  416. _getAlwaysOnTopResources() {
  417. const iframeWindow = this._frame.contentWindow;
  418. const iframeDocument = iframeWindow.document;
  419. let baseURL = '';
  420. const base = iframeDocument.querySelector('base');
  421. if (base && base.href) {
  422. baseURL = base.href;
  423. } else {
  424. const { protocol, host } = iframeWindow.location;
  425. baseURL = `${protocol}//${host}`;
  426. }
  427. return ALWAYS_ON_TOP_FILENAMES.map(
  428. filename => new URL(filename, baseURL).href
  429. );
  430. }
  431. /**
  432. * Returns the formatted display name of a participant.
  433. *
  434. * @param {string} participantId - The id of the participant.
  435. * @returns {string} The formatted display name.
  436. */
  437. _getFormattedDisplayName(participantId) {
  438. const { formattedDisplayName }
  439. = this._participants[participantId] || {};
  440. return formattedDisplayName;
  441. }
  442. /**
  443. * Returns the id of the on stage participant.
  444. *
  445. * @returns {string} - The id of the on stage participant.
  446. */
  447. _getOnStageParticipant() {
  448. return this._onStageParticipant;
  449. }
  450. /**
  451. * Getter for the large video element in Jitsi Meet.
  452. *
  453. * @returns {HTMLElement|undefined} - The large video.
  454. */
  455. _getLargeVideo() {
  456. const iframe = this.getIFrame();
  457. if (!this._isLargeVideoVisible
  458. || !iframe
  459. || !iframe.contentWindow
  460. || !iframe.contentWindow.document) {
  461. return;
  462. }
  463. return iframe.contentWindow.document.getElementById('largeVideo');
  464. }
  465. /**
  466. * Getter for the prejoin video element in Jitsi Meet.
  467. *
  468. * @returns {HTMLElement|undefined} - The prejoin video.
  469. */
  470. _getPrejoinVideo() {
  471. const iframe = this.getIFrame();
  472. if (!this._isPrejoinVideoVisible
  473. || !iframe
  474. || !iframe.contentWindow
  475. || !iframe.contentWindow.document) {
  476. return;
  477. }
  478. return iframe.contentWindow.document.getElementById('prejoinVideo');
  479. }
  480. /**
  481. * Getter for participant specific video element in Jitsi Meet.
  482. *
  483. * @param {string|undefined} participantId - Id of participant to return the video for.
  484. *
  485. * @returns {HTMLElement|undefined} - The requested video. Will return the local video
  486. * by default if participantId is undefined.
  487. */
  488. _getParticipantVideo(participantId) {
  489. const iframe = this.getIFrame();
  490. if (!iframe
  491. || !iframe.contentWindow
  492. || !iframe.contentWindow.document) {
  493. return;
  494. }
  495. if (typeof participantId === 'undefined' || participantId === this._myUserID) {
  496. return iframe.contentWindow.document.getElementById('localVideo_container');
  497. }
  498. return iframe.contentWindow.document.querySelector(`#participant_${participantId} video`);
  499. }
  500. /**
  501. * Sets the size of the iframe element.
  502. *
  503. * @param {number|string} height - The height of the iframe.
  504. * @param {number|string} width - The with of the iframe.
  505. * @returns {void}
  506. *
  507. * @private
  508. */
  509. _setSize(height, width) {
  510. const parsedHeight = parseSizeParam(height);
  511. const parsedWidth = parseSizeParam(width);
  512. if (parsedHeight !== undefined) {
  513. this._height = height;
  514. this._frame.style.height = parsedHeight;
  515. }
  516. if (parsedWidth !== undefined) {
  517. this._width = width;
  518. this._frame.style.width = parsedWidth;
  519. }
  520. }
  521. /**
  522. * Setups listeners that are used internally for JitsiMeetExternalAPI.
  523. *
  524. * @returns {void}
  525. *
  526. * @private
  527. */
  528. _setupListeners() {
  529. this._transport.on('event', ({ name, ...data }) => {
  530. const userID = data.id;
  531. switch (name) {
  532. case 'ready': {
  533. // Fake the iframe onload event because it's not reliable.
  534. this._onload?.();
  535. break;
  536. }
  537. case 'video-conference-joined': {
  538. if (typeof this._tmpE2EEKey !== 'undefined') {
  539. const hexToBytes = hex => {
  540. const bytes = [];
  541. for (let c = 0; c < hex.length; c += 2) {
  542. bytes.push(parseInt(hex.substring(c, c + 2), 16));
  543. }
  544. return bytes;
  545. };
  546. this.executeCommand('setMediaEncryptionKey', JSON.stringify({
  547. exportedKey: hexToBytes(this._tmpE2EEKey),
  548. index: 0
  549. }));
  550. this._tmpE2EEKey = undefined;
  551. }
  552. this._myUserID = userID;
  553. this._participants[userID] = {
  554. email: data.email,
  555. avatarURL: data.avatarURL
  556. };
  557. }
  558. // eslint-disable-next-line no-fallthrough
  559. case 'participant-joined': {
  560. this._participants[userID] = this._participants[userID] || {};
  561. this._participants[userID].displayName = data.displayName;
  562. this._participants[userID].formattedDisplayName
  563. = data.formattedDisplayName;
  564. changeParticipantNumber(this, 1);
  565. break;
  566. }
  567. case 'participant-left':
  568. changeParticipantNumber(this, -1);
  569. delete this._participants[userID];
  570. break;
  571. case 'display-name-change': {
  572. const user = this._participants[userID];
  573. if (user) {
  574. user.displayName = data.displayname;
  575. user.formattedDisplayName = data.formattedDisplayName;
  576. }
  577. break;
  578. }
  579. case 'email-change': {
  580. const user = this._participants[userID];
  581. if (user) {
  582. user.email = data.email;
  583. }
  584. break;
  585. }
  586. case 'avatar-changed': {
  587. const user = this._participants[userID];
  588. if (user) {
  589. user.avatarURL = data.avatarURL;
  590. }
  591. break;
  592. }
  593. case 'on-stage-participant-changed':
  594. this._onStageParticipant = userID;
  595. this.emit('largeVideoChanged');
  596. break;
  597. case 'large-video-visibility-changed':
  598. this._isLargeVideoVisible = data.isVisible;
  599. this.emit('largeVideoChanged');
  600. break;
  601. case 'prejoin-screen-loaded':
  602. this._participants[userID] = {
  603. displayName: data.displayName,
  604. formattedDisplayName: data.formattedDisplayName
  605. };
  606. break;
  607. case 'on-prejoin-video-changed':
  608. this._isPrejoinVideoVisible = data.isVisible;
  609. this.emit('prejoinVideoChanged');
  610. break;
  611. case 'video-conference-left':
  612. changeParticipantNumber(this, -1);
  613. delete this._participants[this._myUserID];
  614. break;
  615. case 'video-quality-changed':
  616. this._videoQuality = data.videoQuality;
  617. break;
  618. case 'breakout-rooms-updated':
  619. this.updateNumberOfParticipants(data.rooms);
  620. break;
  621. case 'local-storage-changed':
  622. jitsiLocalStorage.setItem('jitsiLocalStorage', data.localStorageContent);
  623. // Since this is internal event we don't need to emit it to the consumer of the API.
  624. return true;
  625. }
  626. const eventName = events[name];
  627. if (eventName) {
  628. this.emit(eventName, data);
  629. return true;
  630. }
  631. return false;
  632. });
  633. this._transport.on('request', (request, callback) => {
  634. const requestName = requests[request.name];
  635. const data = {
  636. ...request,
  637. name: requestName
  638. };
  639. if (requestName) {
  640. this.emit(requestName, data, callback);
  641. }
  642. });
  643. }
  644. /**
  645. * Update number of participants based on all rooms.
  646. *
  647. * @param {Object} rooms - Rooms available rooms in the conference.
  648. * @returns {void}
  649. */
  650. updateNumberOfParticipants(rooms) {
  651. if (!rooms || !Object.keys(rooms).length) {
  652. return;
  653. }
  654. const allParticipants = Object.keys(rooms).reduce((prev, roomItemKey) => {
  655. if (rooms[roomItemKey]?.participants) {
  656. return Object.keys(rooms[roomItemKey].participants).length + prev;
  657. }
  658. return prev;
  659. }, 0);
  660. this._numberOfParticipants = allParticipants;
  661. }
  662. /**
  663. * Returns the rooms info in the conference.
  664. *
  665. * @returns {Object} Rooms info.
  666. */
  667. async getRoomsInfo() {
  668. return this._transport.sendRequest({
  669. name: 'rooms-info'
  670. });
  671. }
  672. /**
  673. * Returns whether the conference is P2P.
  674. *
  675. * @returns {Promise}
  676. */
  677. isP2pActive() {
  678. return this._transport.sendRequest({
  679. name: 'get-p2p-status'
  680. });
  681. }
  682. /**
  683. * Adds event listener to Meet Jitsi.
  684. *
  685. * @param {string} event - The name of the event.
  686. * @param {Function} listener - The listener.
  687. * @returns {void}
  688. *
  689. * @deprecated
  690. * NOTE: This method is not removed for backward comatability purposes.
  691. */
  692. addEventListener(event, listener) {
  693. this.on(event, listener);
  694. }
  695. /**
  696. * Adds event listeners to Meet Jitsi.
  697. *
  698. * @param {Object} listeners - The object key should be the name of
  699. * the event and value - the listener.
  700. * Currently we support the following
  701. * events:
  702. * {@code log} - receives event notifications whenever information has
  703. * been logged and has a log level specified within {@code config.apiLogLevels}.
  704. * The listener will receive object with the following structure:
  705. * {{
  706. * logLevel: the message log level
  707. * arguments: an array of strings that compose the actual log message
  708. * }}
  709. * {@code chatUpdated} - receives event notifications about chat state being
  710. * updated. The listener will receive object with the following structure:
  711. * {{
  712. * 'unreadCount': unreadCounter, // the unread message(s) counter,
  713. * 'isOpen': isOpen, // whether the chat panel is open or not
  714. * }}
  715. * {@code incomingMessage} - receives event notifications about incoming
  716. * messages. The listener will receive object with the following structure:
  717. * {{
  718. * 'from': from,//JID of the user that sent the message
  719. * 'nick': nick,//the nickname of the user that sent the message
  720. * 'message': txt//the text of the message
  721. * }}
  722. * {@code outgoingMessage} - receives event notifications about outgoing
  723. * messages. The listener will receive object with the following structure:
  724. * {{
  725. * 'message': txt//the text of the message
  726. * }}
  727. * {@code displayNameChanged} - receives event notifications about display
  728. * name change. The listener will receive object with the following
  729. * structure:
  730. * {{
  731. * jid: jid,//the JID of the participant that changed his display name
  732. * displayname: displayName //the new display name
  733. * }}
  734. * {@code participantJoined} - receives event notifications about new
  735. * participant.
  736. * The listener will receive object with the following structure:
  737. * {{
  738. * jid: jid //the jid of the participant
  739. * }}
  740. * {@code participantLeft} - receives event notifications about the
  741. * participant that left the room.
  742. * The listener will receive object with the following structure:
  743. * {{
  744. * jid: jid //the jid of the participant
  745. * }}
  746. * {@code videoConferenceJoined} - receives event notifications about the
  747. * local user has successfully joined the video conference.
  748. * The listener will receive object with the following structure:
  749. * {{
  750. * roomName: room //the room name of the conference
  751. * }}
  752. * {@code videoConferenceLeft} - receives event notifications about the
  753. * local user has left the video conference.
  754. * The listener will receive object with the following structure:
  755. * {{
  756. * roomName: room //the room name of the conference
  757. * }}
  758. * {@code screenSharingStatusChanged} - receives event notifications about
  759. * turning on/off the local user screen sharing.
  760. * The listener will receive object with the following structure:
  761. * {{
  762. * on: on //whether screen sharing is on
  763. * }}
  764. * {@code dominantSpeakerChanged} - receives event notifications about
  765. * change in the dominant speaker.
  766. * The listener will receive object with the following structure:
  767. * {{
  768. * id: participantId //participantId of the new dominant speaker
  769. * }}
  770. * {@code suspendDetected} - receives event notifications about detecting suspend event in host computer.
  771. * {@code readyToClose} - all hangup operations are completed and Jitsi Meet
  772. * is ready to be disposed.
  773. * @returns {void}
  774. *
  775. * @deprecated
  776. * NOTE: This method is not removed for backward comatability purposes.
  777. */
  778. addEventListeners(listeners) {
  779. for (const event in listeners) { // eslint-disable-line guard-for-in
  780. this.addEventListener(event, listeners[event]);
  781. }
  782. }
  783. /**
  784. * Captures the screenshot of the large video.
  785. *
  786. * @returns {Promise<string>} - Resolves with a base64 encoded image data of the screenshot
  787. * if large video is detected, an error otherwise.
  788. */
  789. captureLargeVideoScreenshot() {
  790. return this._transport.sendRequest({
  791. name: 'capture-largevideo-screenshot'
  792. });
  793. }
  794. /**
  795. * Removes the listeners and removes the Jitsi Meet frame.
  796. *
  797. * @returns {void}
  798. */
  799. dispose() {
  800. this.emit('_willDispose');
  801. this._transport.dispose();
  802. this.removeAllListeners();
  803. if (this._frame && this._frame.parentNode) {
  804. this._frame.parentNode.removeChild(this._frame);
  805. }
  806. }
  807. /**
  808. * Executes command. The available commands are:
  809. * {@code displayName} - Sets the display name of the local participant to
  810. * the value passed in the arguments array.
  811. * {@code subject} - Sets the subject of the conference, the value passed
  812. * in the arguments array. Note: Available only for moderator.
  813. *
  814. * {@code toggleAudio} - Mutes / unmutes audio with no arguments.
  815. * {@code toggleVideo} - Mutes / unmutes video with no arguments.
  816. * {@code toggleFilmStrip} - Hides / shows the filmstrip with no arguments.
  817. *
  818. * If the command doesn't require any arguments the parameter should be set
  819. * to empty array or it may be omitted.
  820. *
  821. * @param {string} name - The name of the command.
  822. * @returns {void}
  823. */
  824. executeCommand(name, ...args) {
  825. if (!(name in commands)) {
  826. console.error('Not supported command name.');
  827. return;
  828. }
  829. this._transport.sendEvent({
  830. data: args,
  831. name: commands[name]
  832. });
  833. }
  834. /**
  835. * Executes commands. The available commands are:
  836. * {@code displayName} - Sets the display name of the local participant to
  837. * the value passed in the arguments array.
  838. * {@code toggleAudio} - Mutes / unmutes audio. No arguments.
  839. * {@code toggleVideo} - Mutes / unmutes video. No arguments.
  840. * {@code toggleFilmStrip} - Hides / shows the filmstrip. No arguments.
  841. * {@code toggleChat} - Hides / shows chat. No arguments.
  842. * {@code toggleShareScreen} - Starts / stops screen sharing. No arguments.
  843. *
  844. * @param {Object} commandList - The object with commands to be executed.
  845. * The keys of the object are the commands that will be executed and the
  846. * values are the arguments for the command.
  847. * @returns {void}
  848. */
  849. executeCommands(commandList) {
  850. for (const key in commandList) { // eslint-disable-line guard-for-in
  851. this.executeCommand(key, commandList[key]);
  852. }
  853. }
  854. /**
  855. * Returns Promise that resolves with a list of available devices.
  856. *
  857. * @returns {Promise}
  858. */
  859. getAvailableDevices() {
  860. return getAvailableDevices(this._transport);
  861. }
  862. /**
  863. * Gets a list of the currently sharing participant id's.
  864. *
  865. * @returns {Promise} - Resolves with the list of participant id's currently sharing.
  866. */
  867. getContentSharingParticipants() {
  868. return this._transport.sendRequest({
  869. name: 'get-content-sharing-participants'
  870. });
  871. }
  872. /**
  873. * Returns Promise that resolves with current selected devices.
  874. *
  875. * @returns {Promise}
  876. */
  877. getCurrentDevices() {
  878. return getCurrentDevices(this._transport);
  879. }
  880. /**
  881. * Returns any custom avatars backgrounds.
  882. *
  883. * @returns {Promise} - Resolves with the list of custom avatar backgrounds.
  884. */
  885. getCustomAvatarBackgrounds() {
  886. return this._transport.sendRequest({
  887. name: 'get-custom-avatar-backgrounds'
  888. });
  889. }
  890. /**
  891. * Returns the current livestream url.
  892. *
  893. * @returns {Promise} - Resolves with the current livestream URL if exists, with
  894. * undefined if not and rejects on failure.
  895. */
  896. getLivestreamUrl() {
  897. return this._transport.sendRequest({
  898. name: 'get-livestream-url'
  899. });
  900. }
  901. /**
  902. * Returns the conference participants information.
  903. *
  904. * @returns {Array<Object>} - Returns an array containing participants
  905. * information like participant id, display name, avatar URL and email.
  906. */
  907. getParticipantsInfo() {
  908. const participantIds = Object.keys(this._participants);
  909. const participantsInfo = Object.values(this._participants);
  910. participantsInfo.forEach((participant, idx) => {
  911. participant.participantId = participantIds[idx];
  912. });
  913. return participantsInfo;
  914. }
  915. /**
  916. * Returns the current video quality setting.
  917. *
  918. * @returns {number}
  919. */
  920. getVideoQuality() {
  921. return this._videoQuality;
  922. }
  923. /**
  924. * Check if the audio is available.
  925. *
  926. * @returns {Promise} - Resolves with true if the audio available, with
  927. * false if not and rejects on failure.
  928. */
  929. isAudioAvailable() {
  930. return this._transport.sendRequest({
  931. name: 'is-audio-available'
  932. });
  933. }
  934. /**
  935. * Returns Promise that resolves with true if the device change is available
  936. * and with false if not.
  937. *
  938. * @param {string} [deviceType] - Values - 'output', 'input' or undefined.
  939. * Default - 'input'.
  940. * @returns {Promise}
  941. */
  942. isDeviceChangeAvailable(deviceType) {
  943. return isDeviceChangeAvailable(this._transport, deviceType);
  944. }
  945. /**
  946. * Returns Promise that resolves with true if the device list is available
  947. * and with false if not.
  948. *
  949. * @returns {Promise}
  950. */
  951. isDeviceListAvailable() {
  952. return isDeviceListAvailable(this._transport);
  953. }
  954. /**
  955. * Returns Promise that resolves with true if multiple audio input is supported
  956. * and with false if not.
  957. *
  958. * @returns {Promise}
  959. */
  960. isMultipleAudioInputSupported() {
  961. return isMultipleAudioInputSupported(this._transport);
  962. }
  963. /**
  964. * Invite people to the call.
  965. *
  966. * @param {Array<Object>} invitees - The invitees.
  967. * @returns {Promise} - Resolves on success and rejects on failure.
  968. */
  969. invite(invitees) {
  970. if (!Array.isArray(invitees) || invitees.length === 0) {
  971. return Promise.reject(new TypeError('Invalid Argument'));
  972. }
  973. return this._transport.sendRequest({
  974. name: 'invite',
  975. invitees
  976. });
  977. }
  978. /**
  979. * Returns the audio mute status.
  980. *
  981. * @returns {Promise} - Resolves with the audio mute status and rejects on
  982. * failure.
  983. */
  984. isAudioMuted() {
  985. return this._transport.sendRequest({
  986. name: 'is-audio-muted'
  987. });
  988. }
  989. /**
  990. * Returns the audio disabled status.
  991. *
  992. * @returns {Promise} - Resolves with the audio disabled status and rejects on
  993. * failure.
  994. */
  995. isAudioDisabled() {
  996. return this._transport.sendRequest({
  997. name: 'is-audio-disabled'
  998. });
  999. }
  1000. /**
  1001. * Returns the moderation on status on the given mediaType.
  1002. *
  1003. * @param {string} mediaType - The media type for which to check moderation.
  1004. * @returns {Promise} - Resolves with the moderation on status and rejects on
  1005. * failure.
  1006. */
  1007. isModerationOn(mediaType) {
  1008. return this._transport.sendRequest({
  1009. name: 'is-moderation-on',
  1010. mediaType
  1011. });
  1012. }
  1013. /**
  1014. * Returns force muted status of the given participant id for the given media type.
  1015. *
  1016. * @param {string} participantId - The id of the participant to check.
  1017. * @param {string} mediaType - The media type for which to check.
  1018. * @returns {Promise} - Resolves with the force muted status and rejects on
  1019. * failure.
  1020. */
  1021. isParticipantForceMuted(participantId, mediaType) {
  1022. return this._transport.sendRequest({
  1023. name: 'is-participant-force-muted',
  1024. participantId,
  1025. mediaType
  1026. });
  1027. }
  1028. /**
  1029. * Returns whether the participants pane is open.
  1030. *
  1031. * @returns {Promise} - Resolves with true if the participants pane is open
  1032. * and with false if not.
  1033. */
  1034. isParticipantsPaneOpen() {
  1035. return this._transport.sendRequest({
  1036. name: 'is-participants-pane-open'
  1037. });
  1038. }
  1039. /**
  1040. * Returns screen sharing status.
  1041. *
  1042. * @returns {Promise} - Resolves with screensharing status and rejects on failure.
  1043. */
  1044. isSharingScreen() {
  1045. return this._transport.sendRequest({
  1046. name: 'is-sharing-screen'
  1047. });
  1048. }
  1049. /**
  1050. * Returns whether meeting is started silent.
  1051. *
  1052. * @returns {Promise} - Resolves with start silent status.
  1053. */
  1054. isStartSilent() {
  1055. return this._transport.sendRequest({
  1056. name: 'is-start-silent'
  1057. });
  1058. }
  1059. /**
  1060. * Returns the avatar URL of a participant.
  1061. *
  1062. * @param {string} participantId - The id of the participant.
  1063. * @returns {string} The avatar URL.
  1064. */
  1065. getAvatarURL(participantId) {
  1066. const { avatarURL } = this._participants[participantId] || {};
  1067. return avatarURL;
  1068. }
  1069. /**
  1070. * Gets the deployment info.
  1071. *
  1072. * @returns {Promise} - Resolves with the deployment info object.
  1073. */
  1074. getDeploymentInfo() {
  1075. return this._transport.sendRequest({
  1076. name: 'deployment-info'
  1077. });
  1078. }
  1079. /**
  1080. * Returns the display name of a participant.
  1081. *
  1082. * @param {string} participantId - The id of the participant.
  1083. * @returns {string} The display name.
  1084. */
  1085. getDisplayName(participantId) {
  1086. const { displayName } = this._participants[participantId] || {};
  1087. return displayName;
  1088. }
  1089. /**
  1090. * Returns the email of a participant.
  1091. *
  1092. * @param {string} participantId - The id of the participant.
  1093. * @returns {string} The email.
  1094. */
  1095. getEmail(participantId) {
  1096. const { email } = this._participants[participantId] || {};
  1097. return email;
  1098. }
  1099. /**
  1100. * Returns the iframe that loads Jitsi Meet.
  1101. *
  1102. * @returns {HTMLElement} The iframe.
  1103. */
  1104. getIFrame() {
  1105. return this._frame;
  1106. }
  1107. /**
  1108. * Returns the number of participants in the conference from all rooms. The local
  1109. * participant is included.
  1110. *
  1111. * @returns {int} The number of participants in the conference.
  1112. */
  1113. getNumberOfParticipants() {
  1114. return this._numberOfParticipants;
  1115. }
  1116. /**
  1117. * Returns array of commands supported by executeCommand().
  1118. *
  1119. * @returns {Array<string>} Array of commands.
  1120. */
  1121. getSupportedCommands() {
  1122. return Object.keys(commands);
  1123. }
  1124. /**
  1125. * Returns array of events supported by addEventListener().
  1126. *
  1127. * @returns {Array<string>} Array of events.
  1128. */
  1129. getSupportedEvents() {
  1130. return Object.values(events);
  1131. }
  1132. /**
  1133. * Check if the video is available.
  1134. *
  1135. * @returns {Promise} - Resolves with true if the video available, with
  1136. * false if not and rejects on failure.
  1137. */
  1138. isVideoAvailable() {
  1139. return this._transport.sendRequest({
  1140. name: 'is-video-available'
  1141. });
  1142. }
  1143. /**
  1144. * Returns the audio mute status.
  1145. *
  1146. * @returns {Promise} - Resolves with the audio mute status and rejects on
  1147. * failure.
  1148. */
  1149. isVideoMuted() {
  1150. return this._transport.sendRequest({
  1151. name: 'is-video-muted'
  1152. });
  1153. }
  1154. /**
  1155. * Returns the list of breakout rooms.
  1156. *
  1157. * @returns {Promise} Resolves with the list of breakout rooms.
  1158. */
  1159. listBreakoutRooms() {
  1160. return this._transport.sendRequest({
  1161. name: 'list-breakout-rooms'
  1162. });
  1163. }
  1164. /**
  1165. * Returns the state of availability electron share screen via external api.
  1166. *
  1167. * @returns {Promise}
  1168. */
  1169. _isNewElectronScreensharingSupported() {
  1170. return this._transport.sendRequest({
  1171. name: '_new_electron_screensharing_supported'
  1172. });
  1173. }
  1174. /**
  1175. * Pins a participant's video on to the stage view.
  1176. *
  1177. * @param {string} participantId - Participant id (JID) of the participant
  1178. * that needs to be pinned on the stage view.
  1179. * @param {string} [videoType] - Indicates the type of thumbnail to be pinned when multistream support is enabled.
  1180. * Accepts "camera" or "desktop" values. Default is "camera". Any invalid values will be ignored and default will
  1181. * be used.
  1182. * @returns {void}
  1183. */
  1184. pinParticipant(participantId, videoType) {
  1185. this.executeCommand('pinParticipant', participantId, videoType);
  1186. }
  1187. /**
  1188. * Removes event listener.
  1189. *
  1190. * @param {string} event - The name of the event.
  1191. * @returns {void}
  1192. *
  1193. * @deprecated
  1194. * NOTE: This method is not removed for backward comatability purposes.
  1195. */
  1196. removeEventListener(event) {
  1197. this.removeAllListeners(event);
  1198. }
  1199. /**
  1200. * Removes event listeners.
  1201. *
  1202. * @param {Array<string>} eventList - Array with the names of the events.
  1203. * @returns {void}
  1204. *
  1205. * @deprecated
  1206. * NOTE: This method is not removed for backward comatability purposes.
  1207. */
  1208. removeEventListeners(eventList) {
  1209. eventList.forEach(event => this.removeEventListener(event));
  1210. }
  1211. /**
  1212. * Resizes the large video container as per the dimensions provided.
  1213. *
  1214. * @param {number} width - Width that needs to be applied on the large video container.
  1215. * @param {number} height - Height that needs to be applied on the large video container.
  1216. * @returns {void}
  1217. */
  1218. resizeLargeVideo(width, height) {
  1219. if (width <= this._width && height <= this._height) {
  1220. this.executeCommand('resizeLargeVideo', width, height);
  1221. }
  1222. }
  1223. /**
  1224. * Passes an event along to the local conference participant to establish
  1225. * or update a direct peer connection. This is currently used for developing
  1226. * wireless screensharing with room integration and it is advised against to
  1227. * use as its api may change.
  1228. *
  1229. * @param {Object} event - An object with information to pass along.
  1230. * @param {Object} event.data - The payload of the event.
  1231. * @param {string} event.from - The jid of the sender of the event. Needed
  1232. * when a reply is to be sent regarding the event.
  1233. * @returns {void}
  1234. */
  1235. sendProxyConnectionEvent(event) {
  1236. this._transport.sendEvent({
  1237. data: [ event ],
  1238. name: 'proxy-connection-event'
  1239. });
  1240. }
  1241. /**
  1242. * Sets the audio input device to the one with the label or id that is
  1243. * passed.
  1244. *
  1245. * @param {string} label - The label of the new device.
  1246. * @param {string} deviceId - The id of the new device.
  1247. * @returns {Promise}
  1248. */
  1249. setAudioInputDevice(label, deviceId) {
  1250. return setAudioInputDevice(this._transport, label, deviceId);
  1251. }
  1252. /**
  1253. * Sets the audio output device to the one with the label or id that is
  1254. * passed.
  1255. *
  1256. * @param {string} label - The label of the new device.
  1257. * @param {string} deviceId - The id of the new device.
  1258. * @returns {Promise}
  1259. */
  1260. setAudioOutputDevice(label, deviceId) {
  1261. return setAudioOutputDevice(this._transport, label, deviceId);
  1262. }
  1263. /**
  1264. * Displays the given participant on the large video. If no participant id is specified,
  1265. * dominant and pinned speakers will be taken into consideration while selecting the
  1266. * the large video participant.
  1267. *
  1268. * @param {string} participantId - Jid of the participant to be displayed on the large video.
  1269. * @param {string} [videoType] - Indicates the type of video to be set when multistream support is enabled.
  1270. * Accepts "camera" or "desktop" values. Default is "camera". Any invalid values will be ignored and default will
  1271. * be used.
  1272. * @returns {void}
  1273. */
  1274. setLargeVideoParticipant(participantId, videoType) {
  1275. this.executeCommand('setLargeVideoParticipant', participantId, videoType);
  1276. }
  1277. /**
  1278. * Sets the video input device to the one with the label or id that is
  1279. * passed.
  1280. *
  1281. * @param {string} label - The label of the new device.
  1282. * @param {string} deviceId - The id of the new device.
  1283. * @returns {Promise}
  1284. */
  1285. setVideoInputDevice(label, deviceId) {
  1286. return setVideoInputDevice(this._transport, label, deviceId);
  1287. }
  1288. /**
  1289. * Starts a file recording or streaming session depending on the passed on params.
  1290. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  1291. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  1292. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  1293. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  1294. * No other params should be passed.
  1295. *
  1296. * @param {Object} options - An object with config options to pass along.
  1297. * @param { string } options.mode - Recording mode, either `file` or `stream`.
  1298. * @param { string } options.dropboxToken - Dropbox oauth2 token.
  1299. * @param { boolean } options.shouldShare - Whether the recording should be shared with the participants or not.
  1300. * Only applies to certain jitsi meet deploys.
  1301. * @param { string } options.rtmpStreamKey - The RTMP stream key.
  1302. * @param { string } options.rtmpBroadcastID - The RTMP broadcast ID.
  1303. * @param { string } options.youtubeStreamKey - The youtube stream key.
  1304. * @param { string } options.youtubeBroadcastID - The youtube broadcast ID.
  1305. * @returns {void}
  1306. */
  1307. startRecording(options) {
  1308. this.executeCommand('startRecording', options);
  1309. }
  1310. /**
  1311. * Stops a recording or streaming session that is in progress.
  1312. *
  1313. * @param {string} mode - `file` or `stream`.
  1314. * @returns {void}
  1315. */
  1316. stopRecording(mode) {
  1317. this.executeCommand('stopRecording', mode);
  1318. }
  1319. /**
  1320. * Sets e2ee enabled/disabled.
  1321. *
  1322. * @param {boolean} enabled - The new value for e2ee enabled.
  1323. * @returns {void}
  1324. */
  1325. toggleE2EE(enabled) {
  1326. this.executeCommand('toggleE2EE', enabled);
  1327. }
  1328. /**
  1329. * Sets the key and keyIndex for e2ee.
  1330. *
  1331. * @param {Object} keyInfo - Json containing key information.
  1332. * @param {CryptoKey} [keyInfo.encryptionKey] - The encryption key.
  1333. * @param {number} [keyInfo.index] - The index of the encryption key.
  1334. * @returns {void}
  1335. */
  1336. async setMediaEncryptionKey(keyInfo) {
  1337. const { key, index } = keyInfo;
  1338. if (key) {
  1339. const exportedKey = await crypto.subtle.exportKey('raw', key);
  1340. this.executeCommand('setMediaEncryptionKey', JSON.stringify({
  1341. exportedKey: Array.from(new Uint8Array(exportedKey)),
  1342. index }));
  1343. } else {
  1344. this.executeCommand('setMediaEncryptionKey', JSON.stringify({
  1345. exportedKey: false,
  1346. index }));
  1347. }
  1348. }
  1349. }