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.

API.js 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  1. // @flow
  2. import Logger from 'jitsi-meet-logger';
  3. import {
  4. createApiEvent,
  5. sendAnalytics
  6. } from '../../react/features/analytics';
  7. import {
  8. approveParticipantAudio,
  9. approveParticipantVideo,
  10. rejectParticipantAudio,
  11. rejectParticipantVideo,
  12. requestDisableAudioModeration,
  13. requestDisableVideoModeration,
  14. requestEnableAudioModeration,
  15. requestEnableVideoModeration
  16. } from '../../react/features/av-moderation/actions';
  17. import { isEnabledFromState } from '../../react/features/av-moderation/functions';
  18. import {
  19. getCurrentConference,
  20. sendTones,
  21. setFollowMe,
  22. setPassword,
  23. setSubject
  24. } from '../../react/features/base/conference';
  25. import { overwriteConfig, getWhitelistedJSON } from '../../react/features/base/config';
  26. import { toggleDialog } from '../../react/features/base/dialog/actions';
  27. import { isSupportedBrowser } from '../../react/features/base/environment';
  28. import { parseJWTFromURLParams } from '../../react/features/base/jwt';
  29. import JitsiMeetJS, { JitsiRecordingConstants } from '../../react/features/base/lib-jitsi-meet';
  30. import { MEDIA_TYPE } from '../../react/features/base/media';
  31. import {
  32. getLocalParticipant,
  33. getParticipantById,
  34. pinParticipant,
  35. kickParticipant,
  36. raiseHand,
  37. isParticipantModerator,
  38. isLocalParticipantModerator
  39. } from '../../react/features/base/participants';
  40. import { updateSettings } from '../../react/features/base/settings';
  41. import { isToggleCameraEnabled, toggleCamera } from '../../react/features/base/tracks';
  42. import {
  43. sendMessage,
  44. setPrivateMessageRecipient,
  45. toggleChat
  46. } from '../../react/features/chat/actions';
  47. import { openChat } from '../../react/features/chat/actions.web';
  48. import {
  49. processExternalDeviceRequest
  50. } from '../../react/features/device-selection/functions';
  51. import { isEnabled as isDropboxEnabled } from '../../react/features/dropbox';
  52. import { toggleE2EE } from '../../react/features/e2ee/actions';
  53. import { setVolume } from '../../react/features/filmstrip';
  54. import { invite } from '../../react/features/invite';
  55. import {
  56. selectParticipantInLargeVideo
  57. } from '../../react/features/large-video/actions.any';
  58. import {
  59. captureLargeVideoScreenshot,
  60. resizeLargeVideo
  61. } from '../../react/features/large-video/actions.web';
  62. import { toggleLobbyMode } from '../../react/features/lobby/actions';
  63. import { isForceMuted } from '../../react/features/participants-pane/functions';
  64. import { RECORDING_TYPES } from '../../react/features/recording/constants';
  65. import { getActiveSession } from '../../react/features/recording/functions';
  66. import { isScreenAudioSupported } from '../../react/features/screen-share';
  67. import { startScreenShareFlow, startAudioScreenShareFlow } from '../../react/features/screen-share/actions';
  68. import { playSharedVideo, stopSharedVideo } from '../../react/features/shared-video/actions.any';
  69. import { toggleTileView, setTileView } from '../../react/features/video-layout';
  70. import { muteAllParticipants } from '../../react/features/video-menu/actions';
  71. import { setVideoQuality } from '../../react/features/video-quality';
  72. import VirtualBackgroundDialog from '../../react/features/virtual-background/components/VirtualBackgroundDialog';
  73. import { getJitsiMeetTransport } from '../transport';
  74. import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';
  75. const logger = Logger.getLogger(__filename);
  76. declare var APP: Object;
  77. /**
  78. * List of the available commands.
  79. */
  80. let commands = {};
  81. /**
  82. * The transport instance used for communication with external apps.
  83. *
  84. * @type {Transport}
  85. */
  86. const transport = getJitsiMeetTransport();
  87. /**
  88. * The current audio availability.
  89. *
  90. * @type {boolean}
  91. */
  92. let audioAvailable = true;
  93. /**
  94. * The current video availability.
  95. *
  96. * @type {boolean}
  97. */
  98. let videoAvailable = true;
  99. /**
  100. * Initializes supported commands.
  101. *
  102. * @returns {void}
  103. */
  104. function initCommands() {
  105. commands = {
  106. 'approve-video': participantId => {
  107. if (!isLocalParticipantModerator(APP.store.getState())) {
  108. return;
  109. }
  110. APP.store.dispatch(approveParticipantVideo(participantId));
  111. },
  112. 'ask-to-unmute': participantId => {
  113. if (!isLocalParticipantModerator(APP.store.getState())) {
  114. return;
  115. }
  116. APP.store.dispatch(approveParticipantAudio(participantId));
  117. },
  118. 'display-name': displayName => {
  119. sendAnalytics(createApiEvent('display.name.changed'));
  120. APP.conference.changeLocalDisplayName(displayName);
  121. },
  122. 'mute-everyone': mediaType => {
  123. const muteMediaType = mediaType ? mediaType : MEDIA_TYPE.AUDIO;
  124. sendAnalytics(createApiEvent('muted-everyone'));
  125. const localParticipant = getLocalParticipant(APP.store.getState());
  126. const exclude = [];
  127. if (localParticipant && isParticipantModerator(localParticipant)) {
  128. exclude.push(localParticipant.id);
  129. }
  130. APP.store.dispatch(muteAllParticipants(exclude, muteMediaType));
  131. },
  132. 'toggle-lobby': isLobbyEnabled => {
  133. APP.store.dispatch(toggleLobbyMode(isLobbyEnabled));
  134. },
  135. 'password': password => {
  136. const { conference, passwordRequired }
  137. = APP.store.getState()['features/base/conference'];
  138. if (passwordRequired) {
  139. sendAnalytics(createApiEvent('submit.password'));
  140. APP.store.dispatch(setPassword(
  141. passwordRequired,
  142. passwordRequired.join,
  143. password
  144. ));
  145. } else {
  146. sendAnalytics(createApiEvent('password.changed'));
  147. APP.store.dispatch(setPassword(
  148. conference,
  149. conference.lock,
  150. password
  151. ));
  152. }
  153. },
  154. 'pin-participant': id => {
  155. logger.debug('Pin participant command received');
  156. sendAnalytics(createApiEvent('participant.pinned'));
  157. APP.store.dispatch(pinParticipant(id));
  158. },
  159. 'proxy-connection-event': event => {
  160. APP.conference.onProxyConnectionEvent(event);
  161. },
  162. 'reject-participant': (participantId, mediaType) => {
  163. if (!isLocalParticipantModerator(APP.store.getState())) {
  164. return;
  165. }
  166. const reject = mediaType === MEDIA_TYPE.VIDEO ? rejectParticipantVideo : rejectParticipantAudio;
  167. APP.store.dispatch(reject(participantId));
  168. },
  169. 'resize-large-video': (width, height) => {
  170. logger.debug('Resize large video command received');
  171. sendAnalytics(createApiEvent('largevideo.resized'));
  172. APP.store.dispatch(resizeLargeVideo(width, height));
  173. },
  174. 'send-tones': (options = {}) => {
  175. const { duration, tones, pause } = options;
  176. APP.store.dispatch(sendTones(tones, duration, pause));
  177. },
  178. 'set-follow-me': value => {
  179. logger.debug('Set follow me command received');
  180. if (value) {
  181. sendAnalytics(createApiEvent('follow.me.set'));
  182. } else {
  183. sendAnalytics(createApiEvent('follow.me.unset'));
  184. }
  185. APP.store.dispatch(setFollowMe(value));
  186. },
  187. 'set-large-video-participant': participantId => {
  188. logger.debug('Set large video participant command received');
  189. sendAnalytics(createApiEvent('largevideo.participant.set'));
  190. APP.store.dispatch(selectParticipantInLargeVideo(participantId));
  191. },
  192. 'set-participant-volume': (participantId, volume) => {
  193. APP.store.dispatch(setVolume(participantId, volume));
  194. },
  195. 'subject': subject => {
  196. sendAnalytics(createApiEvent('subject.changed'));
  197. APP.store.dispatch(setSubject(subject));
  198. },
  199. 'submit-feedback': feedback => {
  200. sendAnalytics(createApiEvent('submit.feedback'));
  201. APP.conference.submitFeedback(feedback.score, feedback.message);
  202. },
  203. 'toggle-audio': () => {
  204. sendAnalytics(createApiEvent('toggle-audio'));
  205. logger.log('Audio toggle: API command received');
  206. APP.conference.toggleAudioMuted(false /* no UI */);
  207. },
  208. 'toggle-video': () => {
  209. sendAnalytics(createApiEvent('toggle-video'));
  210. logger.log('Video toggle: API command received');
  211. APP.conference.toggleVideoMuted(false /* no UI */);
  212. },
  213. 'toggle-film-strip': () => {
  214. sendAnalytics(createApiEvent('film.strip.toggled'));
  215. APP.UI.toggleFilmstrip();
  216. },
  217. 'toggle-camera': () => {
  218. if (!isToggleCameraEnabled(APP.store.getState())) {
  219. return;
  220. }
  221. APP.store.dispatch(toggleCamera());
  222. },
  223. 'toggle-camera-mirror': () => {
  224. const state = APP.store.getState();
  225. const { localFlipX: currentFlipX } = state['features/base/settings'];
  226. APP.store.dispatch(updateSettings({ localFlipX: !currentFlipX }));
  227. },
  228. 'toggle-chat': () => {
  229. sendAnalytics(createApiEvent('chat.toggled'));
  230. APP.store.dispatch(toggleChat());
  231. },
  232. 'toggle-moderation': (enabled, mediaType) => {
  233. const state = APP.store.getState();
  234. if (!isLocalParticipantModerator(state)) {
  235. return;
  236. }
  237. const enable = mediaType === MEDIA_TYPE.VIDEO
  238. ? requestEnableVideoModeration : requestEnableAudioModeration;
  239. const disable = mediaType === MEDIA_TYPE.VIDEO
  240. ? requestDisableVideoModeration : requestDisableAudioModeration;
  241. if (enabled) {
  242. APP.store.dispatch(enable());
  243. } else {
  244. APP.store.dispatch(disable());
  245. }
  246. },
  247. 'toggle-raise-hand': () => {
  248. const localParticipant = getLocalParticipant(APP.store.getState());
  249. if (!localParticipant) {
  250. return;
  251. }
  252. const { raisedHand } = localParticipant;
  253. sendAnalytics(createApiEvent('raise-hand.toggled'));
  254. APP.store.dispatch(raiseHand(!raisedHand));
  255. },
  256. 'toggle-share-audio': () => {
  257. sendAnalytics(createApiEvent('audio.screen.sharing.toggled'));
  258. if (isScreenAudioSupported()) {
  259. APP.store.dispatch(startAudioScreenShareFlow());
  260. return;
  261. }
  262. logger.error('Audio screen sharing is not supported by the current platform!');
  263. },
  264. /**
  265. * Callback to invoke when the "toggle-share-screen" command is received.
  266. *
  267. * @param {Object} options - Additional details of how to perform
  268. * the action. Note this parameter is undocumented and experimental.
  269. * @param {boolean} options.enable - Whether trying to enable screen
  270. * sharing or to turn it off.
  271. * @returns {void}
  272. */
  273. 'toggle-share-screen': (options = {}) => {
  274. sendAnalytics(createApiEvent('screen.sharing.toggled'));
  275. toggleScreenSharing(options.enable);
  276. },
  277. 'toggle-tile-view': () => {
  278. sendAnalytics(createApiEvent('tile-view.toggled'));
  279. APP.store.dispatch(toggleTileView());
  280. },
  281. 'set-tile-view': enabled => {
  282. APP.store.dispatch(setTileView(enabled));
  283. },
  284. 'video-hangup': (showFeedbackDialog = true) => {
  285. sendAnalytics(createApiEvent('video.hangup'));
  286. APP.conference.hangup(showFeedbackDialog);
  287. },
  288. 'email': email => {
  289. sendAnalytics(createApiEvent('email.changed'));
  290. APP.conference.changeLocalEmail(email);
  291. },
  292. 'avatar-url': avatarUrl => {
  293. sendAnalytics(createApiEvent('avatar.url.changed'));
  294. APP.conference.changeLocalAvatarUrl(avatarUrl);
  295. },
  296. 'send-chat-message': (message, to, ignorePrivacy = false) => {
  297. logger.debug('Send chat message command received');
  298. if (to) {
  299. const participant = getParticipantById(APP.store.getState(), to);
  300. if (participant) {
  301. APP.store.dispatch(setPrivateMessageRecipient(participant));
  302. } else {
  303. logger.error(`Participant with id ${to} not found!`);
  304. return;
  305. }
  306. } else {
  307. APP.store.dispatch(setPrivateMessageRecipient());
  308. }
  309. APP.store.dispatch(sendMessage(message, ignorePrivacy));
  310. },
  311. 'send-endpoint-text-message': (to, text) => {
  312. logger.debug('Send endpoint message command received');
  313. try {
  314. APP.conference.sendEndpointMessage(to, {
  315. name: ENDPOINT_TEXT_MESSAGE_NAME,
  316. text
  317. });
  318. } catch (err) {
  319. logger.error('Failed sending endpoint text message', err);
  320. }
  321. },
  322. 'toggle-e2ee': enabled => {
  323. logger.debug('Toggle E2EE key command received');
  324. APP.store.dispatch(toggleE2EE(enabled));
  325. },
  326. 'set-video-quality': frameHeight => {
  327. logger.debug('Set video quality command received');
  328. sendAnalytics(createApiEvent('set.video.quality'));
  329. APP.store.dispatch(setVideoQuality(frameHeight));
  330. },
  331. 'start-share-video': url => {
  332. logger.debug('Share video command received');
  333. sendAnalytics(createApiEvent('share.video.start'));
  334. APP.store.dispatch(playSharedVideo(url));
  335. },
  336. 'stop-share-video': () => {
  337. logger.debug('Share video command received');
  338. sendAnalytics(createApiEvent('share.video.stop'));
  339. APP.store.dispatch(stopSharedVideo());
  340. },
  341. /**
  342. * Starts a file recording or streaming session depending on the passed on params.
  343. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  344. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  345. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  346. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  347. * No other params should be passed.
  348. *
  349. * @param { string } arg.mode - Recording mode, either `file` or `stream`.
  350. * @param { string } arg.dropboxToken - Dropbox oauth2 token.
  351. * @param { string } arg.rtmpStreamKey - The RTMP stream key.
  352. * @param { string } arg.rtmpBroadcastID - The RTMP braodcast ID.
  353. * @param { boolean } arg.shouldShare - Whether the recording should be shared with the participants or not.
  354. * Only applies to certain jitsi meet deploys.
  355. * @param { string } arg.youtubeStreamKey - The youtube stream key.
  356. * @param { string } arg.youtubeBroadcastID - The youtube broacast ID.
  357. * @returns {void}
  358. */
  359. 'start-recording': ({
  360. mode,
  361. dropboxToken,
  362. shouldShare,
  363. rtmpStreamKey,
  364. rtmpBroadcastID,
  365. youtubeStreamKey,
  366. youtubeBroadcastID
  367. }) => {
  368. const state = APP.store.getState();
  369. const conference = getCurrentConference(state);
  370. if (!conference) {
  371. logger.error('Conference is not defined');
  372. return;
  373. }
  374. if (dropboxToken && !isDropboxEnabled(state)) {
  375. logger.error('Failed starting recording: dropbox is not enabled on this deployment');
  376. return;
  377. }
  378. if (mode === JitsiRecordingConstants.mode.STREAM && !(youtubeStreamKey || rtmpStreamKey)) {
  379. logger.error('Failed starting recording: missing youtube or RTMP stream key');
  380. return;
  381. }
  382. let recordingConfig;
  383. if (mode === JitsiRecordingConstants.mode.FILE) {
  384. if (dropboxToken) {
  385. recordingConfig = {
  386. mode: JitsiRecordingConstants.mode.FILE,
  387. appData: JSON.stringify({
  388. 'file_recording_metadata': {
  389. 'upload_credentials': {
  390. 'service_name': RECORDING_TYPES.DROPBOX,
  391. 'token': dropboxToken
  392. }
  393. }
  394. })
  395. };
  396. } else {
  397. recordingConfig = {
  398. mode: JitsiRecordingConstants.mode.FILE,
  399. appData: JSON.stringify({
  400. 'file_recording_metadata': {
  401. 'share': shouldShare
  402. }
  403. })
  404. };
  405. }
  406. } else if (mode === JitsiRecordingConstants.mode.STREAM) {
  407. recordingConfig = {
  408. broadcastId: youtubeBroadcastID || rtmpBroadcastID,
  409. mode: JitsiRecordingConstants.mode.STREAM,
  410. streamId: youtubeStreamKey || rtmpStreamKey
  411. };
  412. } else {
  413. logger.error('Invalid recording mode provided');
  414. return;
  415. }
  416. conference.startRecording(recordingConfig);
  417. },
  418. /**
  419. * Stops a recording or streaming in progress.
  420. *
  421. * @param {string} mode - `file` or `stream`.
  422. * @returns {void}
  423. */
  424. 'stop-recording': mode => {
  425. const state = APP.store.getState();
  426. const conference = getCurrentConference(state);
  427. if (!conference) {
  428. logger.error('Conference is not defined');
  429. return;
  430. }
  431. if (![ JitsiRecordingConstants.mode.FILE, JitsiRecordingConstants.mode.STREAM ].includes(mode)) {
  432. logger.error('Invalid recording mode provided!');
  433. return;
  434. }
  435. const activeSession = getActiveSession(state, mode);
  436. if (activeSession && activeSession.id) {
  437. conference.stopRecording(activeSession.id);
  438. } else {
  439. logger.error('No recording or streaming session found');
  440. }
  441. },
  442. 'initiate-private-chat': participantId => {
  443. const state = APP.store.getState();
  444. const participant = getParticipantById(state, participantId);
  445. if (participant) {
  446. const { isOpen: isChatOpen } = state['features/chat'];
  447. if (!isChatOpen) {
  448. APP.store.dispatch(toggleChat());
  449. }
  450. APP.store.dispatch(openChat(participant));
  451. } else {
  452. logger.error('No participant found for the given participantId');
  453. }
  454. },
  455. 'cancel-private-chat': () => {
  456. APP.store.dispatch(setPrivateMessageRecipient());
  457. },
  458. 'kick-participant': participantId => {
  459. APP.store.dispatch(kickParticipant(participantId));
  460. },
  461. 'overwrite-config': config => {
  462. const whitelistedConfig = getWhitelistedJSON('config', config);
  463. APP.store.dispatch(overwriteConfig(whitelistedConfig));
  464. },
  465. 'toggle-virtual-background': () => {
  466. APP.store.dispatch(toggleDialog(VirtualBackgroundDialog));
  467. }
  468. };
  469. transport.on('event', ({ data, name }) => {
  470. if (name && commands[name]) {
  471. commands[name](...data);
  472. return true;
  473. }
  474. return false;
  475. });
  476. transport.on('request', (request, callback) => {
  477. const { dispatch, getState } = APP.store;
  478. if (processExternalDeviceRequest(dispatch, getState, request, callback)) {
  479. return true;
  480. }
  481. const { name } = request;
  482. switch (name) {
  483. case 'capture-largevideo-screenshot' :
  484. APP.store.dispatch(captureLargeVideoScreenshot())
  485. .then(dataURL => {
  486. let error;
  487. if (!dataURL) {
  488. error = new Error('No large video found!');
  489. }
  490. callback({
  491. error,
  492. dataURL
  493. });
  494. });
  495. break;
  496. case 'deployment-info':
  497. callback(APP.store.getState()['features/base/config'].deploymentInfo);
  498. break;
  499. case 'invite': {
  500. const { invitees } = request;
  501. if (!Array.isArray(invitees) || invitees.length === 0) {
  502. callback({
  503. error: new Error('Unexpected format of invitees')
  504. });
  505. break;
  506. }
  507. // The store should be already available because API.init is called
  508. // on appWillMount action.
  509. APP.store.dispatch(
  510. invite(invitees, true))
  511. .then(failedInvitees => {
  512. let error;
  513. let result;
  514. if (failedInvitees.length) {
  515. error = new Error('One or more invites failed!');
  516. } else {
  517. result = true;
  518. }
  519. callback({
  520. error,
  521. result
  522. });
  523. });
  524. break;
  525. }
  526. case 'is-audio-muted':
  527. callback(APP.conference.isLocalAudioMuted());
  528. break;
  529. case 'is-moderation-on': {
  530. const { mediaType } = request;
  531. const type = mediaType || MEDIA_TYPE.AUDIO;
  532. callback(isEnabledFromState(type, APP.store.getState()));
  533. break;
  534. }
  535. case 'is-participant-force-muted': {
  536. const state = APP.store.getState();
  537. const { participantId, mediaType } = request;
  538. const type = mediaType || MEDIA_TYPE.AUDIO;
  539. const participant = getParticipantById(state, participantId);
  540. callback(isForceMuted(participant, type, state));
  541. break;
  542. }
  543. case 'is-video-muted':
  544. callback(APP.conference.isLocalVideoMuted());
  545. break;
  546. case 'is-audio-available':
  547. callback(audioAvailable);
  548. break;
  549. case 'is-video-available':
  550. callback(videoAvailable);
  551. break;
  552. case 'is-sharing-screen':
  553. callback(Boolean(APP.conference.isSharingScreen));
  554. break;
  555. case 'get-content-sharing-participants': {
  556. const tracks = getState()['features/base/tracks'];
  557. const sharingParticipantIds = tracks.filter(tr => tr.videoType === 'desktop').map(t => t.participantId);
  558. callback({
  559. sharingParticipantIds
  560. });
  561. break;
  562. }
  563. case 'get-livestream-url': {
  564. const state = APP.store.getState();
  565. const conference = getCurrentConference(state);
  566. let livestreamUrl;
  567. if (conference) {
  568. const activeSession = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
  569. livestreamUrl = activeSession?.liveStreamViewURL;
  570. } else {
  571. logger.error('Conference is not defined');
  572. }
  573. callback({
  574. livestreamUrl
  575. });
  576. break;
  577. }
  578. case 'get-custom-avatar-backgrounds' : {
  579. callback({
  580. avatarBackgrounds: APP.store.getState()['features/dynamic-branding'].avatarBackgrounds
  581. });
  582. break;
  583. }
  584. default:
  585. return false;
  586. }
  587. return true;
  588. });
  589. }
  590. /**
  591. * Check whether the API should be enabled or not.
  592. *
  593. * @returns {boolean}
  594. */
  595. function shouldBeEnabled() {
  596. return (
  597. typeof API_ID === 'number'
  598. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  599. // the location/URL because then it is very likely that the Jitsi
  600. // Meet (Web) app is being used by an external/wrapping (Web) app
  601. // and, consequently, the latter will need to communicate with the
  602. // former. (The described logic is merely a heuristic though.)
  603. || parseJWTFromURLParams());
  604. }
  605. /**
  606. * Executes on toggle-share-screen command.
  607. *
  608. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  609. * disable screensharing. If not defined, the application will automatically
  610. * attempt to toggle between enabled and disabled. This boolean is useful for
  611. * explicitly setting desired screensharing state.
  612. * @returns {void}
  613. */
  614. function toggleScreenSharing(enable) {
  615. if (JitsiMeetJS.isDesktopSharingEnabled()) {
  616. APP.store.dispatch(startScreenShareFlow(enable));
  617. }
  618. }
  619. /**
  620. * Removes sensitive data from a mouse event.
  621. *
  622. * @param {MouseEvent} event - The mouse event to sanitize.
  623. * @returns {Object}
  624. */
  625. function sanitizeMouseEvent(event: MouseEvent) {
  626. const {
  627. clientX,
  628. clientY,
  629. movementX,
  630. movementY,
  631. offsetX,
  632. offsetY,
  633. pageX,
  634. pageY,
  635. x,
  636. y,
  637. screenX,
  638. screenY
  639. } = event;
  640. return {
  641. clientX,
  642. clientY,
  643. movementX,
  644. movementY,
  645. offsetX,
  646. offsetY,
  647. pageX,
  648. pageY,
  649. x,
  650. y,
  651. screenX,
  652. screenY
  653. };
  654. }
  655. /**
  656. * Implements API class that communicates with external API class and provides
  657. * interface to access Jitsi Meet features by external applications that embed
  658. * Jitsi Meet.
  659. */
  660. class API {
  661. _enabled: boolean;
  662. /**
  663. * Initializes the API. Setups message event listeners that will receive
  664. * information from external applications that embed Jitsi Meet. It also
  665. * sends a message to the external application that API is initialized.
  666. *
  667. * @param {Object} options - Optional parameters.
  668. * @returns {void}
  669. */
  670. init() {
  671. if (!shouldBeEnabled()) {
  672. return;
  673. }
  674. /**
  675. * Current status (enabled/disabled) of API.
  676. *
  677. * @private
  678. * @type {boolean}
  679. */
  680. this._enabled = true;
  681. initCommands();
  682. this.notifyBrowserSupport(isSupportedBrowser());
  683. }
  684. /**
  685. * Notify external application (if API is enabled) that the large video
  686. * visibility changed.
  687. *
  688. * @param {boolean} isHidden - True if the large video is hidden and false
  689. * otherwise.
  690. * @returns {void}
  691. */
  692. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  693. this._sendEvent({
  694. name: 'large-video-visibility-changed',
  695. isVisible: !isHidden
  696. });
  697. }
  698. /**
  699. * Notifies the external application (spot) that the local jitsi-participant
  700. * has a status update.
  701. *
  702. * @param {Object} event - The message to pass onto spot.
  703. * @returns {void}
  704. */
  705. sendProxyConnectionEvent(event: Object) {
  706. this._sendEvent({
  707. name: 'proxy-connection-event',
  708. ...event
  709. });
  710. }
  711. /**
  712. * Sends event to the external application.
  713. *
  714. * @param {Object} event - The event to be sent.
  715. * @returns {void}
  716. */
  717. _sendEvent(event: Object = {}) {
  718. if (this._enabled) {
  719. transport.sendEvent(event);
  720. }
  721. }
  722. /**
  723. * Notify external application (if API is enabled) that the chat state has been updated.
  724. *
  725. * @param {number} unreadCount - The unread messages counter.
  726. * @param {boolean} isOpen - True if the chat panel is open.
  727. * @returns {void}
  728. */
  729. notifyChatUpdated(unreadCount: number, isOpen: boolean) {
  730. this._sendEvent({
  731. name: 'chat-updated',
  732. unreadCount,
  733. isOpen
  734. });
  735. }
  736. /**
  737. * Notify external application (if API is enabled) that message was sent.
  738. *
  739. * @param {string} message - Message body.
  740. * @param {boolean} privateMessage - True if the message was a private message.
  741. * @returns {void}
  742. */
  743. notifySendingChatMessage(message: string, privateMessage: boolean) {
  744. this._sendEvent({
  745. name: 'outgoing-message',
  746. message,
  747. privateMessage
  748. });
  749. }
  750. /**
  751. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  752. *
  753. * @param {MouseEvent} event - The mousemove event.
  754. * @returns {void}
  755. */
  756. notifyMouseEnter(event: MouseEvent) {
  757. this._sendEvent({
  758. name: 'mouse-enter',
  759. event: sanitizeMouseEvent(event)
  760. });
  761. }
  762. /**
  763. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  764. *
  765. * @param {MouseEvent} event - The mousemove event.
  766. * @returns {void}
  767. */
  768. notifyMouseLeave(event: MouseEvent) {
  769. this._sendEvent({
  770. name: 'mouse-leave',
  771. event: sanitizeMouseEvent(event)
  772. });
  773. }
  774. /**
  775. * Notify external application (if API is enabled) that the mouse has moved inside the iframe.
  776. *
  777. * @param {MouseEvent} event - The mousemove event.
  778. * @returns {void}
  779. */
  780. notifyMouseMove(event: MouseEvent) {
  781. this._sendEvent({
  782. name: 'mouse-move',
  783. event: sanitizeMouseEvent(event)
  784. });
  785. }
  786. /**
  787. * Notify the external application that the moderation status has changed.
  788. *
  789. * @param {string} mediaType - Media type for which the moderation changed.
  790. * @param {boolean} enabled - Whether or not the new moderation status is enabled.
  791. * @returns {void}
  792. */
  793. notifyModerationChanged(mediaType: string, enabled: boolean) {
  794. this._sendEvent({
  795. name: 'moderation-status-changed',
  796. mediaType,
  797. enabled
  798. });
  799. }
  800. /**
  801. * Notify the external application that a participant was approved on moderation.
  802. *
  803. * @param {string} participantId - The ID of the participant that got approved.
  804. * @param {string} mediaType - Media type for which the participant was approved.
  805. * @returns {void}
  806. */
  807. notifyParticipantApproved(participantId: string, mediaType: string) {
  808. this._sendEvent({
  809. name: 'moderation-participant-approved',
  810. id: participantId,
  811. mediaType
  812. });
  813. }
  814. /**
  815. * Notify the external application that a participant was rejected on moderation.
  816. *
  817. * @param {string} participantId - The ID of the participant that got rejected.
  818. * @param {string} mediaType - Media type for which the participant was rejected.
  819. * @returns {void}
  820. */
  821. notifyParticipantRejected(participantId: string, mediaType: string) {
  822. this._sendEvent({
  823. name: 'moderation-participant-rejected',
  824. id: participantId,
  825. mediaType
  826. });
  827. }
  828. /**
  829. * Notify external application that the video quality setting has changed.
  830. *
  831. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  832. * @returns {void}
  833. */
  834. notifyVideoQualityChanged(videoQuality: number) {
  835. this._sendEvent({
  836. name: 'video-quality-changed',
  837. videoQuality
  838. });
  839. }
  840. /**
  841. * Notify external application (if API is enabled) that message was
  842. * received.
  843. *
  844. * @param {Object} options - Object with the message properties.
  845. * @returns {void}
  846. */
  847. notifyReceivedChatMessage(
  848. { body, id, nick, privateMessage, ts }: {
  849. body: *, id: string, nick: string, privateMessage: boolean, ts: *
  850. } = {}) {
  851. if (APP.conference.isLocalId(id)) {
  852. return;
  853. }
  854. this._sendEvent({
  855. name: 'incoming-message',
  856. from: id,
  857. message: body,
  858. nick,
  859. privateMessage,
  860. stamp: ts
  861. });
  862. }
  863. /**
  864. * Notify external application (if API is enabled) that user joined the
  865. * conference.
  866. *
  867. * @param {string} id - User id.
  868. * @param {Object} props - The display name of the user.
  869. * @returns {void}
  870. */
  871. notifyUserJoined(id: string, props: Object) {
  872. this._sendEvent({
  873. name: 'participant-joined',
  874. id,
  875. ...props
  876. });
  877. }
  878. /**
  879. * Notify external application (if API is enabled) that user left the
  880. * conference.
  881. *
  882. * @param {string} id - User id.
  883. * @returns {void}
  884. */
  885. notifyUserLeft(id: string) {
  886. this._sendEvent({
  887. name: 'participant-left',
  888. id
  889. });
  890. }
  891. /**
  892. * Notify external application (if API is enabled) that the user role
  893. * has changed.
  894. *
  895. * @param {string} id - User id.
  896. * @param {string} role - The new user role.
  897. * @returns {void}
  898. */
  899. notifyUserRoleChanged(id: string, role: string) {
  900. this._sendEvent({
  901. name: 'participant-role-changed',
  902. id,
  903. role
  904. });
  905. }
  906. /**
  907. * Notify external application (if API is enabled) that user changed their
  908. * avatar.
  909. *
  910. * @param {string} id - User id.
  911. * @param {string} avatarURL - The new avatar URL of the participant.
  912. * @returns {void}
  913. */
  914. notifyAvatarChanged(id: string, avatarURL: string) {
  915. this._sendEvent({
  916. name: 'avatar-changed',
  917. avatarURL,
  918. id
  919. });
  920. }
  921. /**
  922. * Notify external application (if API is enabled) that user received
  923. * a text message through datachannels.
  924. *
  925. * @param {Object} data - The event data.
  926. * @returns {void}
  927. */
  928. notifyEndpointTextMessageReceived(data: Object) {
  929. this._sendEvent({
  930. name: 'endpoint-text-message-received',
  931. data
  932. });
  933. }
  934. /**
  935. * Notify external application (if API is enabled) that the list of sharing participants changed.
  936. *
  937. * @param {Object} data - The event data.
  938. * @returns {void}
  939. */
  940. notifySharingParticipantsChanged(data: Object) {
  941. this._sendEvent({
  942. name: 'content-sharing-participants-changed',
  943. data
  944. });
  945. }
  946. /**
  947. * Notify external application (if API is enabled) that the device list has
  948. * changed.
  949. *
  950. * @param {Object} devices - The new device list.
  951. * @returns {void}
  952. */
  953. notifyDeviceListChanged(devices: Object) {
  954. this._sendEvent({
  955. name: 'device-list-changed',
  956. devices
  957. });
  958. }
  959. /**
  960. * Notify external application (if API is enabled) that user changed their
  961. * nickname.
  962. *
  963. * @param {string} id - User id.
  964. * @param {string} displayname - User nickname.
  965. * @param {string} formattedDisplayName - The display name shown in Jitsi
  966. * meet's UI for the user.
  967. * @returns {void}
  968. */
  969. notifyDisplayNameChanged(
  970. id: string,
  971. { displayName, formattedDisplayName }: Object) {
  972. this._sendEvent({
  973. name: 'display-name-change',
  974. displayname: displayName,
  975. formattedDisplayName,
  976. id
  977. });
  978. }
  979. /**
  980. * Notify external application (if API is enabled) that user changed their
  981. * email.
  982. *
  983. * @param {string} id - User id.
  984. * @param {string} email - The new email of the participant.
  985. * @returns {void}
  986. */
  987. notifyEmailChanged(
  988. id: string,
  989. { email }: Object) {
  990. this._sendEvent({
  991. name: 'email-change',
  992. email,
  993. id
  994. });
  995. }
  996. /**
  997. * Notify external application (if API is enabled) that the an error has been logged.
  998. *
  999. * @param {string} logLevel - The message log level.
  1000. * @param {Array} args - Array of strings composing the log message.
  1001. * @returns {void}
  1002. */
  1003. notifyLog(logLevel: string, args: Array<string>) {
  1004. this._sendEvent({
  1005. name: 'log',
  1006. logLevel,
  1007. args
  1008. });
  1009. }
  1010. /**
  1011. * Notify external application (if API is enabled) that the conference has
  1012. * been joined.
  1013. *
  1014. * @param {string} roomName - The room name.
  1015. * @param {string} id - The id of the local user.
  1016. * @param {Object} props - The display name and avatar URL of the local
  1017. * user.
  1018. * @returns {void}
  1019. */
  1020. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  1021. this._sendEvent({
  1022. name: 'video-conference-joined',
  1023. roomName,
  1024. id,
  1025. ...props
  1026. });
  1027. }
  1028. /**
  1029. * Notify external application (if API is enabled) that local user has left the conference.
  1030. *
  1031. * @param {string} roomName - User id.
  1032. * @returns {void}
  1033. */
  1034. notifyConferenceLeft(roomName: string) {
  1035. this._sendEvent({
  1036. name: 'video-conference-left',
  1037. roomName
  1038. });
  1039. }
  1040. /**
  1041. * Notify external application that the data channel has been opened.
  1042. *
  1043. * @returns {void}
  1044. */
  1045. notifyDataChannelOpened() {
  1046. this._sendEvent({ name: 'data-channel-opened' });
  1047. }
  1048. /**
  1049. * Notify external application (if API is enabled) that we are ready to be
  1050. * closed.
  1051. *
  1052. * @returns {void}
  1053. */
  1054. notifyReadyToClose() {
  1055. this._sendEvent({ name: 'video-ready-to-close' });
  1056. }
  1057. /**
  1058. * Notify external application (if API is enabled) that a suspend event in host computer.
  1059. *
  1060. * @returns {void}
  1061. */
  1062. notifySuspendDetected() {
  1063. this._sendEvent({ name: 'suspend-detected' });
  1064. }
  1065. /**
  1066. * Notify external application (if API is enabled) for audio muted status
  1067. * changed.
  1068. *
  1069. * @param {boolean} muted - The new muted status.
  1070. * @returns {void}
  1071. */
  1072. notifyAudioMutedStatusChanged(muted: boolean) {
  1073. this._sendEvent({
  1074. name: 'audio-mute-status-changed',
  1075. muted
  1076. });
  1077. }
  1078. /**
  1079. * Notify external application (if API is enabled) for video muted status
  1080. * changed.
  1081. *
  1082. * @param {boolean} muted - The new muted status.
  1083. * @returns {void}
  1084. */
  1085. notifyVideoMutedStatusChanged(muted: boolean) {
  1086. this._sendEvent({
  1087. name: 'video-mute-status-changed',
  1088. muted
  1089. });
  1090. }
  1091. /**
  1092. * Notify external application (if API is enabled) for audio availability
  1093. * changed.
  1094. *
  1095. * @param {boolean} available - True if available and false otherwise.
  1096. * @returns {void}
  1097. */
  1098. notifyAudioAvailabilityChanged(available: boolean) {
  1099. audioAvailable = available;
  1100. this._sendEvent({
  1101. name: 'audio-availability-changed',
  1102. available
  1103. });
  1104. }
  1105. /**
  1106. * Notify external application (if API is enabled) for video available
  1107. * status changed.
  1108. *
  1109. * @param {boolean} available - True if available and false otherwise.
  1110. * @returns {void}
  1111. */
  1112. notifyVideoAvailabilityChanged(available: boolean) {
  1113. videoAvailable = available;
  1114. this._sendEvent({
  1115. name: 'video-availability-changed',
  1116. available
  1117. });
  1118. }
  1119. /**
  1120. * Notify external application (if API is enabled) that the on stage
  1121. * participant has changed.
  1122. *
  1123. * @param {string} id - User id of the new on stage participant.
  1124. * @returns {void}
  1125. */
  1126. notifyOnStageParticipantChanged(id: string) {
  1127. this._sendEvent({
  1128. name: 'on-stage-participant-changed',
  1129. id
  1130. });
  1131. }
  1132. /**
  1133. * Notify external application of an unexpected camera-related error having
  1134. * occurred.
  1135. *
  1136. * @param {string} type - The type of the camera error.
  1137. * @param {string} message - Additional information about the error.
  1138. * @returns {void}
  1139. */
  1140. notifyOnCameraError(type: string, message: string) {
  1141. this._sendEvent({
  1142. name: 'camera-error',
  1143. type,
  1144. message
  1145. });
  1146. }
  1147. /**
  1148. * Notify external application of an unexpected mic-related error having
  1149. * occurred.
  1150. *
  1151. * @param {string} type - The type of the mic error.
  1152. * @param {string} message - Additional information about the error.
  1153. * @returns {void}
  1154. */
  1155. notifyOnMicError(type: string, message: string) {
  1156. this._sendEvent({
  1157. name: 'mic-error',
  1158. type,
  1159. message
  1160. });
  1161. }
  1162. /**
  1163. * Notify external application (if API is enabled) that conference feedback
  1164. * has been submitted. Intended to be used in conjunction with the
  1165. * submit-feedback command to get notified if feedback was submitted.
  1166. *
  1167. * @param {string} error - A failure message, if any.
  1168. * @returns {void}
  1169. */
  1170. notifyFeedbackSubmitted(error: string) {
  1171. this._sendEvent({
  1172. name: 'feedback-submitted',
  1173. error
  1174. });
  1175. }
  1176. /**
  1177. * Notify external application (if API is enabled) that the feedback prompt
  1178. * has been displayed.
  1179. *
  1180. * @returns {void}
  1181. */
  1182. notifyFeedbackPromptDisplayed() {
  1183. this._sendEvent({ name: 'feedback-prompt-displayed' });
  1184. }
  1185. /**
  1186. * Notify external application (if API is enabled) that the display
  1187. * configuration of the filmstrip has been changed.
  1188. *
  1189. * @param {boolean} visible - Whether or not the filmstrip has been set to
  1190. * be displayed or hidden.
  1191. * @returns {void}
  1192. */
  1193. notifyFilmstripDisplayChanged(visible: boolean) {
  1194. this._sendEvent({
  1195. name: 'filmstrip-display-changed',
  1196. visible
  1197. });
  1198. }
  1199. /**
  1200. * Notify external application of a participant, remote or local, being
  1201. * removed from the conference by another participant.
  1202. *
  1203. * @param {string} kicked - The ID of the participant removed from the
  1204. * conference.
  1205. * @param {string} kicker - The ID of the participant that removed the
  1206. * other participant.
  1207. * @returns {void}
  1208. */
  1209. notifyKickedOut(kicked: Object, kicker: Object) {
  1210. this._sendEvent({
  1211. name: 'participant-kicked-out',
  1212. kicked,
  1213. kicker
  1214. });
  1215. }
  1216. /**
  1217. * Notify external application of the current meeting requiring a password
  1218. * to join.
  1219. *
  1220. * @returns {void}
  1221. */
  1222. notifyOnPasswordRequired() {
  1223. this._sendEvent({ name: 'password-required' });
  1224. }
  1225. /**
  1226. * Notify external application (if API is enabled) that the screen sharing
  1227. * has been turned on/off.
  1228. *
  1229. * @param {boolean} on - True if screen sharing is enabled.
  1230. * @param {Object} details - Additional information about the screen
  1231. * sharing.
  1232. * @param {string} details.sourceType - Type of device or window the screen
  1233. * share is capturing.
  1234. * @returns {void}
  1235. */
  1236. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  1237. this._sendEvent({
  1238. name: 'screen-sharing-status-changed',
  1239. on,
  1240. details
  1241. });
  1242. }
  1243. /**
  1244. * Notify external application (if API is enabled) that the dominant speaker
  1245. * has been turned on/off.
  1246. *
  1247. * @param {string} id - Id of the dominant participant.
  1248. * @returns {void}
  1249. */
  1250. notifyDominantSpeakerChanged(id: string) {
  1251. this._sendEvent({
  1252. name: 'dominant-speaker-changed',
  1253. id
  1254. });
  1255. }
  1256. /**
  1257. * Notify external application (if API is enabled) that the conference
  1258. * changed their subject.
  1259. *
  1260. * @param {string} subject - Conference subject.
  1261. * @returns {void}
  1262. */
  1263. notifySubjectChanged(subject: string) {
  1264. this._sendEvent({
  1265. name: 'subject-change',
  1266. subject
  1267. });
  1268. }
  1269. /**
  1270. * Notify external application (if API is enabled) that tile view has been
  1271. * entered or exited.
  1272. *
  1273. * @param {string} enabled - True if tile view is currently displayed, false
  1274. * otherwise.
  1275. * @returns {void}
  1276. */
  1277. notifyTileViewChanged(enabled: boolean) {
  1278. this._sendEvent({
  1279. name: 'tile-view-changed',
  1280. enabled
  1281. });
  1282. }
  1283. /**
  1284. * Notify external application (if API is enabled) that the localStorage has changed.
  1285. *
  1286. * @param {string} localStorageContent - The new localStorageContent.
  1287. * @returns {void}
  1288. */
  1289. notifyLocalStorageChanged(localStorageContent: string) {
  1290. this._sendEvent({
  1291. name: 'local-storage-changed',
  1292. localStorageContent
  1293. });
  1294. }
  1295. /**
  1296. * Notify external application (if API is enabled) that user updated their hand raised.
  1297. *
  1298. * @param {string} id - User id.
  1299. * @param {boolean} handRaised - Whether user has raised hand.
  1300. * @returns {void}
  1301. */
  1302. notifyRaiseHandUpdated(id: string, handRaised: boolean) {
  1303. this._sendEvent({
  1304. name: 'raise-hand-updated',
  1305. handRaised,
  1306. id
  1307. });
  1308. }
  1309. /**
  1310. * Notify external application (if API is enabled) that recording has started or stopped.
  1311. *
  1312. * @param {boolean} on - True if recording is on, false otherwise.
  1313. * @param {string} mode - Stream or file.
  1314. * @param {string} error - Error type or null if success.
  1315. * @returns {void}
  1316. */
  1317. notifyRecordingStatusChanged(on: boolean, mode: string, error?: string) {
  1318. this._sendEvent({
  1319. name: 'recording-status-changed',
  1320. on,
  1321. mode,
  1322. error
  1323. });
  1324. }
  1325. /**
  1326. * Notify external application (if API is enabled) that an error occured.
  1327. *
  1328. * @param {Object} error - The error.
  1329. * @returns {void}
  1330. */
  1331. notifyError(error: Object) {
  1332. this._sendEvent({
  1333. name: 'error-occurred',
  1334. error
  1335. });
  1336. }
  1337. /**
  1338. * Notify external application ( if API is enabled) that a toolbar button was clicked.
  1339. *
  1340. * @param {string} key - The key of the toolbar button.
  1341. * @returns {void}
  1342. */
  1343. notifyToolbarButtonClicked(key: string) {
  1344. this._sendEvent({
  1345. name: 'toolbar-button-clicked',
  1346. key
  1347. });
  1348. }
  1349. /**
  1350. * Notify external application (if API is enabled) wether the used browser is supported or not.
  1351. *
  1352. * @param {boolean} supported - If browser is supported or not.
  1353. * @returns {void}
  1354. */
  1355. notifyBrowserSupport(supported: boolean) {
  1356. this._sendEvent({
  1357. name: 'browser-support',
  1358. supported
  1359. });
  1360. }
  1361. /**
  1362. * Disposes the allocated resources.
  1363. *
  1364. * @returns {void}
  1365. */
  1366. dispose() {
  1367. if (this._enabled) {
  1368. this._enabled = false;
  1369. }
  1370. }
  1371. }
  1372. export default new API();