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

external_api.js 37KB

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