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

API.js 64KB

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