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 51KB

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