Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

external_api.js 39KB

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