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

external_api.js 39KB

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