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

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