您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  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 a participant is knocking in the lobby.
  1331. *
  1332. * @param {Object} participant - Participant data such as id and name.
  1333. * @returns {void}
  1334. */
  1335. notifyKnockingParticipant(participant: Object) {
  1336. this._sendEvent({
  1337. name: 'knocking-participant',
  1338. participant
  1339. });
  1340. }
  1341. /**
  1342. * Notify external application (if API is enabled) that an error occured.
  1343. *
  1344. * @param {Object} error - The error.
  1345. * @returns {void}
  1346. */
  1347. notifyError(error: Object) {
  1348. this._sendEvent({
  1349. name: 'error-occurred',
  1350. error
  1351. });
  1352. }
  1353. /**
  1354. * Notify external application ( if API is enabled) that a toolbar button was clicked.
  1355. *
  1356. * @param {string} key - The key of the toolbar button.
  1357. * @returns {void}
  1358. */
  1359. notifyToolbarButtonClicked(key: string) {
  1360. this._sendEvent({
  1361. name: 'toolbar-button-clicked',
  1362. key
  1363. });
  1364. }
  1365. /**
  1366. * Notify external application (if API is enabled) wether the used browser is supported or not.
  1367. *
  1368. * @param {boolean} supported - If browser is supported or not.
  1369. * @returns {void}
  1370. */
  1371. notifyBrowserSupport(supported: boolean) {
  1372. this._sendEvent({
  1373. name: 'browser-support',
  1374. supported
  1375. });
  1376. }
  1377. /**
  1378. * Disposes the allocated resources.
  1379. *
  1380. * @returns {void}
  1381. */
  1382. dispose() {
  1383. if (this._enabled) {
  1384. this._enabled = false;
  1385. }
  1386. }
  1387. }
  1388. export default new API();