您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

external_api.js 49KB

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