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

external_api.js 36KB

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