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

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