選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

API.js 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  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 'invite': {
  497. const { invitees } = request;
  498. if (!Array.isArray(invitees) || invitees.length === 0) {
  499. callback({
  500. error: new Error('Unexpected format of invitees')
  501. });
  502. break;
  503. }
  504. // The store should be already available because API.init is called
  505. // on appWillMount action.
  506. APP.store.dispatch(
  507. invite(invitees, true))
  508. .then(failedInvitees => {
  509. let error;
  510. let result;
  511. if (failedInvitees.length) {
  512. error = new Error('One or more invites failed!');
  513. } else {
  514. result = true;
  515. }
  516. callback({
  517. error,
  518. result
  519. });
  520. });
  521. break;
  522. }
  523. case 'is-audio-muted':
  524. callback(APP.conference.isLocalAudioMuted());
  525. break;
  526. case 'is-moderation-on': {
  527. const { mediaType } = request;
  528. const type = mediaType || MEDIA_TYPE.AUDIO;
  529. callback(isEnabledFromState(type, APP.store.getState()));
  530. break;
  531. }
  532. case 'is-participant-force-muted': {
  533. const state = APP.store.getState();
  534. const { participantId, mediaType } = request;
  535. const type = mediaType || MEDIA_TYPE.AUDIO;
  536. const participant = getParticipantById(state, participantId);
  537. callback(isForceMuted(participant, type, state));
  538. break;
  539. }
  540. case 'is-video-muted':
  541. callback(APP.conference.isLocalVideoMuted());
  542. break;
  543. case 'is-audio-available':
  544. callback(audioAvailable);
  545. break;
  546. case 'is-video-available':
  547. callback(videoAvailable);
  548. break;
  549. case 'is-sharing-screen':
  550. callback(Boolean(APP.conference.isSharingScreen));
  551. break;
  552. case 'get-content-sharing-participants': {
  553. const tracks = getState()['features/base/tracks'];
  554. const sharingParticipantIds = tracks.filter(tr => tr.videoType === 'desktop').map(t => t.participantId);
  555. callback({
  556. sharingParticipantIds
  557. });
  558. break;
  559. }
  560. case 'get-livestream-url': {
  561. const state = APP.store.getState();
  562. const conference = getCurrentConference(state);
  563. let livestreamUrl;
  564. if (conference) {
  565. const activeSession = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
  566. livestreamUrl = activeSession?.liveStreamViewURL;
  567. } else {
  568. logger.error('Conference is not defined');
  569. }
  570. callback({
  571. livestreamUrl
  572. });
  573. break;
  574. }
  575. case 'get-custom-avatar-backgrounds' : {
  576. callback({
  577. avatarBackgrounds: APP.store.getState()['features/dynamic-branding'].avatarBackgrounds
  578. });
  579. break;
  580. }
  581. default:
  582. return false;
  583. }
  584. return true;
  585. });
  586. }
  587. /**
  588. * Check whether the API should be enabled or not.
  589. *
  590. * @returns {boolean}
  591. */
  592. function shouldBeEnabled() {
  593. return (
  594. typeof API_ID === 'number'
  595. // XXX Enable the API when a JSON Web Token (JWT) is specified in
  596. // the location/URL because then it is very likely that the Jitsi
  597. // Meet (Web) app is being used by an external/wrapping (Web) app
  598. // and, consequently, the latter will need to communicate with the
  599. // former. (The described logic is merely a heuristic though.)
  600. || parseJWTFromURLParams());
  601. }
  602. /**
  603. * Executes on toggle-share-screen command.
  604. *
  605. * @param {boolean} [enable] - Whether this toggle is to explicitly enable or
  606. * disable screensharing. If not defined, the application will automatically
  607. * attempt to toggle between enabled and disabled. This boolean is useful for
  608. * explicitly setting desired screensharing state.
  609. * @returns {void}
  610. */
  611. function toggleScreenSharing(enable) {
  612. if (JitsiMeetJS.isDesktopSharingEnabled()) {
  613. APP.store.dispatch(startScreenShareFlow(enable));
  614. }
  615. }
  616. /**
  617. * Removes sensitive data from a mouse event.
  618. *
  619. * @param {MouseEvent} event - The mouse event to sanitize.
  620. * @returns {Object}
  621. */
  622. function sanitizeMouseEvent(event: MouseEvent) {
  623. const {
  624. clientX,
  625. clientY,
  626. movementX,
  627. movementY,
  628. offsetX,
  629. offsetY,
  630. pageX,
  631. pageY,
  632. x,
  633. y,
  634. screenX,
  635. screenY
  636. } = event;
  637. return {
  638. clientX,
  639. clientY,
  640. movementX,
  641. movementY,
  642. offsetX,
  643. offsetY,
  644. pageX,
  645. pageY,
  646. x,
  647. y,
  648. screenX,
  649. screenY
  650. };
  651. }
  652. /**
  653. * Implements API class that communicates with external API class and provides
  654. * interface to access Jitsi Meet features by external applications that embed
  655. * Jitsi Meet.
  656. */
  657. class API {
  658. _enabled: boolean;
  659. /**
  660. * Initializes the API. Setups message event listeners that will receive
  661. * information from external applications that embed Jitsi Meet. It also
  662. * sends a message to the external application that API is initialized.
  663. *
  664. * @param {Object} options - Optional parameters.
  665. * @returns {void}
  666. */
  667. init() {
  668. if (!shouldBeEnabled()) {
  669. return;
  670. }
  671. /**
  672. * Current status (enabled/disabled) of API.
  673. *
  674. * @private
  675. * @type {boolean}
  676. */
  677. this._enabled = true;
  678. initCommands();
  679. this.notifyBrowserSupport(isSupportedBrowser());
  680. }
  681. /**
  682. * Notify external application (if API is enabled) that the large video
  683. * visibility changed.
  684. *
  685. * @param {boolean} isHidden - True if the large video is hidden and false
  686. * otherwise.
  687. * @returns {void}
  688. */
  689. notifyLargeVideoVisibilityChanged(isHidden: boolean) {
  690. this._sendEvent({
  691. name: 'large-video-visibility-changed',
  692. isVisible: !isHidden
  693. });
  694. }
  695. /**
  696. * Notifies the external application (spot) that the local jitsi-participant
  697. * has a status update.
  698. *
  699. * @param {Object} event - The message to pass onto spot.
  700. * @returns {void}
  701. */
  702. sendProxyConnectionEvent(event: Object) {
  703. this._sendEvent({
  704. name: 'proxy-connection-event',
  705. ...event
  706. });
  707. }
  708. /**
  709. * Sends event to the external application.
  710. *
  711. * @param {Object} event - The event to be sent.
  712. * @returns {void}
  713. */
  714. _sendEvent(event: Object = {}) {
  715. if (this._enabled) {
  716. transport.sendEvent(event);
  717. }
  718. }
  719. /**
  720. * Notify external application (if API is enabled) that the chat state has been updated.
  721. *
  722. * @param {number} unreadCount - The unread messages counter.
  723. * @param {boolean} isOpen - True if the chat panel is open.
  724. * @returns {void}
  725. */
  726. notifyChatUpdated(unreadCount: number, isOpen: boolean) {
  727. this._sendEvent({
  728. name: 'chat-updated',
  729. unreadCount,
  730. isOpen
  731. });
  732. }
  733. /**
  734. * Notify external application (if API is enabled) that message was sent.
  735. *
  736. * @param {string} message - Message body.
  737. * @param {boolean} privateMessage - True if the message was a private message.
  738. * @returns {void}
  739. */
  740. notifySendingChatMessage(message: string, privateMessage: boolean) {
  741. this._sendEvent({
  742. name: 'outgoing-message',
  743. message,
  744. privateMessage
  745. });
  746. }
  747. /**
  748. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  749. *
  750. * @param {MouseEvent} event - The mousemove event.
  751. * @returns {void}
  752. */
  753. notifyMouseEnter(event: MouseEvent) {
  754. this._sendEvent({
  755. name: 'mouse-enter',
  756. event: sanitizeMouseEvent(event)
  757. });
  758. }
  759. /**
  760. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  761. *
  762. * @param {MouseEvent} event - The mousemove event.
  763. * @returns {void}
  764. */
  765. notifyMouseLeave(event: MouseEvent) {
  766. this._sendEvent({
  767. name: 'mouse-leave',
  768. event: sanitizeMouseEvent(event)
  769. });
  770. }
  771. /**
  772. * Notify external application (if API is enabled) that the mouse has moved inside the iframe.
  773. *
  774. * @param {MouseEvent} event - The mousemove event.
  775. * @returns {void}
  776. */
  777. notifyMouseMove(event: MouseEvent) {
  778. this._sendEvent({
  779. name: 'mouse-move',
  780. event: sanitizeMouseEvent(event)
  781. });
  782. }
  783. /**
  784. * Notify the external application that the moderation status has changed.
  785. *
  786. * @param {string} mediaType - Media type for which the moderation changed.
  787. * @param {boolean} enabled - Whether or not the new moderation status is enabled.
  788. * @returns {void}
  789. */
  790. notifyModerationChanged(mediaType: string, enabled: boolean) {
  791. this._sendEvent({
  792. name: 'moderation-status-changed',
  793. mediaType,
  794. enabled
  795. });
  796. }
  797. /**
  798. * Notify the external application that a participant was approved on moderation.
  799. *
  800. * @param {string} participantId - The ID of the participant that got approved.
  801. * @param {string} mediaType - Media type for which the participant was approved.
  802. * @returns {void}
  803. */
  804. notifyParticipantApproved(participantId: string, mediaType: string) {
  805. this._sendEvent({
  806. name: 'moderation-participant-approved',
  807. id: participantId,
  808. mediaType
  809. });
  810. }
  811. /**
  812. * Notify the external application that a participant was rejected on moderation.
  813. *
  814. * @param {string} participantId - The ID of the participant that got rejected.
  815. * @param {string} mediaType - Media type for which the participant was rejected.
  816. * @returns {void}
  817. */
  818. notifyParticipantRejected(participantId: string, mediaType: string) {
  819. this._sendEvent({
  820. name: 'moderation-participant-rejected',
  821. id: participantId,
  822. mediaType
  823. });
  824. }
  825. /**
  826. * Notify external application that the video quality setting has changed.
  827. *
  828. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  829. * @returns {void}
  830. */
  831. notifyVideoQualityChanged(videoQuality: number) {
  832. this._sendEvent({
  833. name: 'video-quality-changed',
  834. videoQuality
  835. });
  836. }
  837. /**
  838. * Notify external application (if API is enabled) that message was
  839. * received.
  840. *
  841. * @param {Object} options - Object with the message properties.
  842. * @returns {void}
  843. */
  844. notifyReceivedChatMessage(
  845. { body, id, nick, privateMessage, ts }: {
  846. body: *, id: string, nick: string, privateMessage: boolean, ts: *
  847. } = {}) {
  848. if (APP.conference.isLocalId(id)) {
  849. return;
  850. }
  851. this._sendEvent({
  852. name: 'incoming-message',
  853. from: id,
  854. message: body,
  855. nick,
  856. privateMessage,
  857. stamp: ts
  858. });
  859. }
  860. /**
  861. * Notify external application (if API is enabled) that user joined the
  862. * conference.
  863. *
  864. * @param {string} id - User id.
  865. * @param {Object} props - The display name of the user.
  866. * @returns {void}
  867. */
  868. notifyUserJoined(id: string, props: Object) {
  869. this._sendEvent({
  870. name: 'participant-joined',
  871. id,
  872. ...props
  873. });
  874. }
  875. /**
  876. * Notify external application (if API is enabled) that user left the
  877. * conference.
  878. *
  879. * @param {string} id - User id.
  880. * @returns {void}
  881. */
  882. notifyUserLeft(id: string) {
  883. this._sendEvent({
  884. name: 'participant-left',
  885. id
  886. });
  887. }
  888. /**
  889. * Notify external application (if API is enabled) that the user role
  890. * has changed.
  891. *
  892. * @param {string} id - User id.
  893. * @param {string} role - The new user role.
  894. * @returns {void}
  895. */
  896. notifyUserRoleChanged(id: string, role: string) {
  897. this._sendEvent({
  898. name: 'participant-role-changed',
  899. id,
  900. role
  901. });
  902. }
  903. /**
  904. * Notify external application (if API is enabled) that user changed their
  905. * avatar.
  906. *
  907. * @param {string} id - User id.
  908. * @param {string} avatarURL - The new avatar URL of the participant.
  909. * @returns {void}
  910. */
  911. notifyAvatarChanged(id: string, avatarURL: string) {
  912. this._sendEvent({
  913. name: 'avatar-changed',
  914. avatarURL,
  915. id
  916. });
  917. }
  918. /**
  919. * Notify external application (if API is enabled) that user received
  920. * a text message through datachannels.
  921. *
  922. * @param {Object} data - The event data.
  923. * @returns {void}
  924. */
  925. notifyEndpointTextMessageReceived(data: Object) {
  926. this._sendEvent({
  927. name: 'endpoint-text-message-received',
  928. data
  929. });
  930. }
  931. /**
  932. * Notify external application (if API is enabled) that the list of sharing participants changed.
  933. *
  934. * @param {Object} data - The event data.
  935. * @returns {void}
  936. */
  937. notifySharingParticipantsChanged(data: Object) {
  938. this._sendEvent({
  939. name: 'content-sharing-participants-changed',
  940. data
  941. });
  942. }
  943. /**
  944. * Notify external application (if API is enabled) that the device list has
  945. * changed.
  946. *
  947. * @param {Object} devices - The new device list.
  948. * @returns {void}
  949. */
  950. notifyDeviceListChanged(devices: Object) {
  951. this._sendEvent({
  952. name: 'device-list-changed',
  953. devices
  954. });
  955. }
  956. /**
  957. * Notify external application (if API is enabled) that user changed their
  958. * nickname.
  959. *
  960. * @param {string} id - User id.
  961. * @param {string} displayname - User nickname.
  962. * @param {string} formattedDisplayName - The display name shown in Jitsi
  963. * meet's UI for the user.
  964. * @returns {void}
  965. */
  966. notifyDisplayNameChanged(
  967. id: string,
  968. { displayName, formattedDisplayName }: Object) {
  969. this._sendEvent({
  970. name: 'display-name-change',
  971. displayname: displayName,
  972. formattedDisplayName,
  973. id
  974. });
  975. }
  976. /**
  977. * Notify external application (if API is enabled) that user changed their
  978. * email.
  979. *
  980. * @param {string} id - User id.
  981. * @param {string} email - The new email of the participant.
  982. * @returns {void}
  983. */
  984. notifyEmailChanged(
  985. id: string,
  986. { email }: Object) {
  987. this._sendEvent({
  988. name: 'email-change',
  989. email,
  990. id
  991. });
  992. }
  993. /**
  994. * Notify external application (if API is enabled) that the an error has been logged.
  995. *
  996. * @param {string} logLevel - The message log level.
  997. * @param {Array} args - Array of strings composing the log message.
  998. * @returns {void}
  999. */
  1000. notifyLog(logLevel: string, args: Array<string>) {
  1001. this._sendEvent({
  1002. name: 'log',
  1003. logLevel,
  1004. args
  1005. });
  1006. }
  1007. /**
  1008. * Notify external application (if API is enabled) that the conference has
  1009. * been joined.
  1010. *
  1011. * @param {string} roomName - The room name.
  1012. * @param {string} id - The id of the local user.
  1013. * @param {Object} props - The display name and avatar URL of the local
  1014. * user.
  1015. * @returns {void}
  1016. */
  1017. notifyConferenceJoined(roomName: string, id: string, props: Object) {
  1018. this._sendEvent({
  1019. name: 'video-conference-joined',
  1020. roomName,
  1021. id,
  1022. ...props
  1023. });
  1024. }
  1025. /**
  1026. * Notify external application (if API is enabled) that local user has left the conference.
  1027. *
  1028. * @param {string} roomName - User id.
  1029. * @returns {void}
  1030. */
  1031. notifyConferenceLeft(roomName: string) {
  1032. this._sendEvent({
  1033. name: 'video-conference-left',
  1034. roomName
  1035. });
  1036. }
  1037. /**
  1038. * Notify external application that the data channel has been opened.
  1039. *
  1040. * @returns {void}
  1041. */
  1042. notifyDataChannelOpened() {
  1043. this._sendEvent({ name: 'data-channel-opened' });
  1044. }
  1045. /**
  1046. * Notify external application (if API is enabled) that we are ready to be
  1047. * closed.
  1048. *
  1049. * @returns {void}
  1050. */
  1051. notifyReadyToClose() {
  1052. this._sendEvent({ name: 'video-ready-to-close' });
  1053. }
  1054. /**
  1055. * Notify external application (if API is enabled) that a suspend event in host computer.
  1056. *
  1057. * @returns {void}
  1058. */
  1059. notifySuspendDetected() {
  1060. this._sendEvent({ name: 'suspend-detected' });
  1061. }
  1062. /**
  1063. * Notify external application (if API is enabled) for audio muted status
  1064. * changed.
  1065. *
  1066. * @param {boolean} muted - The new muted status.
  1067. * @returns {void}
  1068. */
  1069. notifyAudioMutedStatusChanged(muted: boolean) {
  1070. this._sendEvent({
  1071. name: 'audio-mute-status-changed',
  1072. muted
  1073. });
  1074. }
  1075. /**
  1076. * Notify external application (if API is enabled) for video muted status
  1077. * changed.
  1078. *
  1079. * @param {boolean} muted - The new muted status.
  1080. * @returns {void}
  1081. */
  1082. notifyVideoMutedStatusChanged(muted: boolean) {
  1083. this._sendEvent({
  1084. name: 'video-mute-status-changed',
  1085. muted
  1086. });
  1087. }
  1088. /**
  1089. * Notify external application (if API is enabled) for audio availability
  1090. * changed.
  1091. *
  1092. * @param {boolean} available - True if available and false otherwise.
  1093. * @returns {void}
  1094. */
  1095. notifyAudioAvailabilityChanged(available: boolean) {
  1096. audioAvailable = available;
  1097. this._sendEvent({
  1098. name: 'audio-availability-changed',
  1099. available
  1100. });
  1101. }
  1102. /**
  1103. * Notify external application (if API is enabled) for video available
  1104. * status changed.
  1105. *
  1106. * @param {boolean} available - True if available and false otherwise.
  1107. * @returns {void}
  1108. */
  1109. notifyVideoAvailabilityChanged(available: boolean) {
  1110. videoAvailable = available;
  1111. this._sendEvent({
  1112. name: 'video-availability-changed',
  1113. available
  1114. });
  1115. }
  1116. /**
  1117. * Notify external application (if API is enabled) that the on stage
  1118. * participant has changed.
  1119. *
  1120. * @param {string} id - User id of the new on stage participant.
  1121. * @returns {void}
  1122. */
  1123. notifyOnStageParticipantChanged(id: string) {
  1124. this._sendEvent({
  1125. name: 'on-stage-participant-changed',
  1126. id
  1127. });
  1128. }
  1129. /**
  1130. * Notify external application of an unexpected camera-related error having
  1131. * occurred.
  1132. *
  1133. * @param {string} type - The type of the camera error.
  1134. * @param {string} message - Additional information about the error.
  1135. * @returns {void}
  1136. */
  1137. notifyOnCameraError(type: string, message: string) {
  1138. this._sendEvent({
  1139. name: 'camera-error',
  1140. type,
  1141. message
  1142. });
  1143. }
  1144. /**
  1145. * Notify external application of an unexpected mic-related error having
  1146. * occurred.
  1147. *
  1148. * @param {string} type - The type of the mic error.
  1149. * @param {string} message - Additional information about the error.
  1150. * @returns {void}
  1151. */
  1152. notifyOnMicError(type: string, message: string) {
  1153. this._sendEvent({
  1154. name: 'mic-error',
  1155. type,
  1156. message
  1157. });
  1158. }
  1159. /**
  1160. * Notify external application (if API is enabled) that conference feedback
  1161. * has been submitted. Intended to be used in conjunction with the
  1162. * submit-feedback command to get notified if feedback was submitted.
  1163. *
  1164. * @param {string} error - A failure message, if any.
  1165. * @returns {void}
  1166. */
  1167. notifyFeedbackSubmitted(error: string) {
  1168. this._sendEvent({
  1169. name: 'feedback-submitted',
  1170. error
  1171. });
  1172. }
  1173. /**
  1174. * Notify external application (if API is enabled) that the feedback prompt
  1175. * has been displayed.
  1176. *
  1177. * @returns {void}
  1178. */
  1179. notifyFeedbackPromptDisplayed() {
  1180. this._sendEvent({ name: 'feedback-prompt-displayed' });
  1181. }
  1182. /**
  1183. * Notify external application (if API is enabled) that the display
  1184. * configuration of the filmstrip has been changed.
  1185. *
  1186. * @param {boolean} visible - Whether or not the filmstrip has been set to
  1187. * be displayed or hidden.
  1188. * @returns {void}
  1189. */
  1190. notifyFilmstripDisplayChanged(visible: boolean) {
  1191. this._sendEvent({
  1192. name: 'filmstrip-display-changed',
  1193. visible
  1194. });
  1195. }
  1196. /**
  1197. * Notify external application of a participant, remote or local, being
  1198. * removed from the conference by another participant.
  1199. *
  1200. * @param {string} kicked - The ID of the participant removed from the
  1201. * conference.
  1202. * @param {string} kicker - The ID of the participant that removed the
  1203. * other participant.
  1204. * @returns {void}
  1205. */
  1206. notifyKickedOut(kicked: Object, kicker: Object) {
  1207. this._sendEvent({
  1208. name: 'participant-kicked-out',
  1209. kicked,
  1210. kicker
  1211. });
  1212. }
  1213. /**
  1214. * Notify external application of the current meeting requiring a password
  1215. * to join.
  1216. *
  1217. * @returns {void}
  1218. */
  1219. notifyOnPasswordRequired() {
  1220. this._sendEvent({ name: 'password-required' });
  1221. }
  1222. /**
  1223. * Notify external application (if API is enabled) that the screen sharing
  1224. * has been turned on/off.
  1225. *
  1226. * @param {boolean} on - True if screen sharing is enabled.
  1227. * @param {Object} details - Additional information about the screen
  1228. * sharing.
  1229. * @param {string} details.sourceType - Type of device or window the screen
  1230. * share is capturing.
  1231. * @returns {void}
  1232. */
  1233. notifyScreenSharingStatusChanged(on: boolean, details: Object) {
  1234. this._sendEvent({
  1235. name: 'screen-sharing-status-changed',
  1236. on,
  1237. details
  1238. });
  1239. }
  1240. /**
  1241. * Notify external application (if API is enabled) that the dominant speaker
  1242. * has been turned on/off.
  1243. *
  1244. * @param {string} id - Id of the dominant participant.
  1245. * @returns {void}
  1246. */
  1247. notifyDominantSpeakerChanged(id: string) {
  1248. this._sendEvent({
  1249. name: 'dominant-speaker-changed',
  1250. id
  1251. });
  1252. }
  1253. /**
  1254. * Notify external application (if API is enabled) that the conference
  1255. * changed their subject.
  1256. *
  1257. * @param {string} subject - Conference subject.
  1258. * @returns {void}
  1259. */
  1260. notifySubjectChanged(subject: string) {
  1261. this._sendEvent({
  1262. name: 'subject-change',
  1263. subject
  1264. });
  1265. }
  1266. /**
  1267. * Notify external application (if API is enabled) that tile view has been
  1268. * entered or exited.
  1269. *
  1270. * @param {string} enabled - True if tile view is currently displayed, false
  1271. * otherwise.
  1272. * @returns {void}
  1273. */
  1274. notifyTileViewChanged(enabled: boolean) {
  1275. this._sendEvent({
  1276. name: 'tile-view-changed',
  1277. enabled
  1278. });
  1279. }
  1280. /**
  1281. * Notify external application (if API is enabled) that the localStorage has changed.
  1282. *
  1283. * @param {string} localStorageContent - The new localStorageContent.
  1284. * @returns {void}
  1285. */
  1286. notifyLocalStorageChanged(localStorageContent: string) {
  1287. this._sendEvent({
  1288. name: 'local-storage-changed',
  1289. localStorageContent
  1290. });
  1291. }
  1292. /**
  1293. * Notify external application (if API is enabled) that user updated their hand raised.
  1294. *
  1295. * @param {string} id - User id.
  1296. * @param {boolean} handRaised - Whether user has raised hand.
  1297. * @returns {void}
  1298. */
  1299. notifyRaiseHandUpdated(id: string, handRaised: boolean) {
  1300. this._sendEvent({
  1301. name: 'raise-hand-updated',
  1302. handRaised,
  1303. id
  1304. });
  1305. }
  1306. /**
  1307. * Notify external application (if API is enabled) that recording has started or stopped.
  1308. *
  1309. * @param {boolean} on - True if recording is on, false otherwise.
  1310. * @param {string} mode - Stream or file.
  1311. * @param {string} error - Error type or null if success.
  1312. * @returns {void}
  1313. */
  1314. notifyRecordingStatusChanged(on: boolean, mode: string, error?: string) {
  1315. this._sendEvent({
  1316. name: 'recording-status-changed',
  1317. on,
  1318. mode,
  1319. error
  1320. });
  1321. }
  1322. /**
  1323. * Notify external application (if API is enabled) that an error occured.
  1324. *
  1325. * @param {Object} error - The error.
  1326. * @returns {void}
  1327. */
  1328. notifyError(error: Object) {
  1329. this._sendEvent({
  1330. name: 'error-occurred',
  1331. error
  1332. });
  1333. }
  1334. /**
  1335. * Notify external application ( if API is enabled) that a toolbar button was clicked.
  1336. *
  1337. * @param {string} key - The key of the toolbar button.
  1338. * @returns {void}
  1339. */
  1340. notifyToolbarButtonClicked(key: string) {
  1341. this._sendEvent({
  1342. name: 'toolbar-button-clicked',
  1343. key
  1344. });
  1345. }
  1346. /**
  1347. * Notify external application (if API is enabled) wether the used browser is supported or not.
  1348. *
  1349. * @param {boolean} supported - If browser is supported or not.
  1350. * @returns {void}
  1351. */
  1352. notifyBrowserSupport(supported: boolean) {
  1353. this._sendEvent({
  1354. name: 'browser-support',
  1355. supported
  1356. });
  1357. }
  1358. /**
  1359. * Disposes the allocated resources.
  1360. *
  1361. * @returns {void}
  1362. */
  1363. dispose() {
  1364. if (this._enabled) {
  1365. this._enabled = false;
  1366. }
  1367. }
  1368. }
  1369. export default new API();