You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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