Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

API.js 54KB

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