Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

external_api.js 37KB

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