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 47KB

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