Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

external_api.js 39KB

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