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

external_api.js 49KB

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