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.

API.js 54KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710
  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. * Disposes the allocated resources.
  1546. *
  1547. * @returns {void}
  1548. */
  1549. dispose() {
  1550. if (this._enabled) {
  1551. this._enabled = false;
  1552. }
  1553. }
  1554. }
  1555. export default new API();