You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

external_api.js 49KB

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