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

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