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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008
  1. // @flow
  2. import Logger from '@jitsi/logger';
  3. import { createApiEvent } from '../../react/features/analytics/AnalyticsEvents';
  4. import { sendAnalytics } from '../../react/features/analytics/functions';
  5. import {
  6. approveParticipantAudio,
  7. approveParticipantVideo,
  8. rejectParticipantAudio,
  9. rejectParticipantVideo,
  10. requestDisableAudioModeration,
  11. requestDisableVideoModeration,
  12. requestEnableAudioModeration,
  13. requestEnableVideoModeration
  14. } from '../../react/features/av-moderation/actions';
  15. import { isEnabledFromState } from '../../react/features/av-moderation/functions';
  16. import {
  17. endConference,
  18. sendTones,
  19. setFollowMe,
  20. setLocalSubject,
  21. setPassword,
  22. setSubject
  23. } from '../../react/features/base/conference/actions';
  24. import { getCurrentConference } from '../../react/features/base/conference/functions';
  25. import { overwriteConfig } from '../../react/features/base/config/actions';
  26. import { getWhitelistedJSON } from '../../react/features/base/config/functions.any';
  27. import { toggleDialog } from '../../react/features/base/dialog/actions';
  28. import { isSupportedBrowser } from '../../react/features/base/environment/environment';
  29. import { parseJWTFromURLParams } from '../../react/features/base/jwt/functions';
  30. import JitsiMeetJS, { JitsiRecordingConstants } from '../../react/features/base/lib-jitsi-meet';
  31. import { MEDIA_TYPE, VIDEO_TYPE } from '../../react/features/base/media/constants';
  32. import {
  33. grantModerator,
  34. kickParticipant,
  35. overwriteParticipantsNames,
  36. pinParticipant,
  37. raiseHand
  38. } from '../../react/features/base/participants/actions';
  39. import { LOCAL_PARTICIPANT_DEFAULT_ID } from '../../react/features/base/participants/constants';
  40. import {
  41. getLocalParticipant,
  42. getParticipantById,
  43. getScreenshareParticipantIds,
  44. getVirtualScreenshareParticipantByOwnerId,
  45. hasRaisedHand,
  46. isLocalParticipantModerator,
  47. isParticipantModerator
  48. } from '../../react/features/base/participants/functions';
  49. import { updateSettings } from '../../react/features/base/settings/actions';
  50. import { getDisplayName } from '../../react/features/base/settings/functions.web';
  51. import { toggleCamera } from '../../react/features/base/tracks/actions.any';
  52. import { isToggleCameraEnabled } from '../../react/features/base/tracks/functions';
  53. import {
  54. autoAssignToBreakoutRooms,
  55. closeBreakoutRoom,
  56. createBreakoutRoom,
  57. moveToRoom,
  58. removeBreakoutRoom,
  59. sendParticipantToRoom
  60. } from '../../react/features/breakout-rooms/actions';
  61. import { getBreakoutRooms, getRoomsInfo } from '../../react/features/breakout-rooms/functions';
  62. import {
  63. sendMessage,
  64. setPrivateMessageRecipient,
  65. toggleChat
  66. } from '../../react/features/chat/actions';
  67. import { openChat } from '../../react/features/chat/actions.web';
  68. import {
  69. processExternalDeviceRequest
  70. } from '../../react/features/device-selection/functions';
  71. import { appendSuffix } from '../../react/features/display-name/functions';
  72. import { isEnabled as isDropboxEnabled } from '../../react/features/dropbox/functions';
  73. import { setMediaEncryptionKey, toggleE2EE } from '../../react/features/e2ee/actions';
  74. import {
  75. addStageParticipant,
  76. resizeFilmStrip,
  77. setVolume,
  78. togglePinStageParticipant
  79. } from '../../react/features/filmstrip/actions.web';
  80. import { getPinnedActiveParticipants, isStageFilmstripAvailable } from '../../react/features/filmstrip/functions.web';
  81. import { invite } from '../../react/features/invite/actions.any';
  82. import {
  83. selectParticipantInLargeVideo
  84. } from '../../react/features/large-video/actions.any';
  85. import {
  86. captureLargeVideoScreenshot,
  87. resizeLargeVideo
  88. } from '../../react/features/large-video/actions.web';
  89. import { answerKnockingParticipant, toggleLobbyMode } from '../../react/features/lobby/actions';
  90. import { setNoiseSuppressionEnabled } from '../../react/features/noise-suppression/actions';
  91. import { hideNotification, showNotification } from '../../react/features/notifications/actions';
  92. import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../../react/features/notifications/constants';
  93. import {
  94. close as closeParticipantsPane,
  95. open as openParticipantsPane
  96. } from '../../react/features/participants-pane/actions';
  97. import { getParticipantsPaneOpen, isForceMuted } from '../../react/features/participants-pane/functions';
  98. import { startLocalVideoRecording, stopLocalVideoRecording } from '../../react/features/recording/actions.any';
  99. import { RECORDING_TYPES } from '../../react/features/recording/constants';
  100. import { getActiveSession, supportsLocalRecording } from '../../react/features/recording/functions';
  101. import { startAudioScreenShareFlow, startScreenShareFlow } from '../../react/features/screen-share/actions';
  102. import { isScreenAudioSupported } from '../../react/features/screen-share/functions';
  103. import { toggleScreenshotCaptureSummary } from '../../react/features/screenshot-capture/actions';
  104. import { isScreenshotCaptureEnabled } from '../../react/features/screenshot-capture/functions';
  105. import SettingsDialog from '../../react/features/settings/components/web/SettingsDialog';
  106. import { SETTINGS_TABS } from '../../react/features/settings/constants';
  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/actions.any';
  112. import { muteAllParticipants } from '../../react/features/video-menu/actions';
  113. import { setVideoQuality } from '../../react/features/video-quality/actions';
  114. import { getJitsiMeetTransport } from '../transport';
  115. import { API_ID, ENDPOINT_TEXT_MESSAGE_NAME } from './constants';
  116. const logger = Logger.getLogger(__filename);
  117. declare var APP: Object;
  118. /**
  119. * List of the available commands.
  120. */
  121. let commands = {};
  122. /**
  123. * The transport instance used for communication with external apps.
  124. *
  125. * @type {Transport}
  126. */
  127. const transport = getJitsiMeetTransport();
  128. /**
  129. * The current audio availability.
  130. *
  131. * @type {boolean}
  132. */
  133. let audioAvailable = true;
  134. /**
  135. * The current video availability.
  136. *
  137. * @type {boolean}
  138. */
  139. let videoAvailable = true;
  140. /**
  141. * Initializes supported commands.
  142. *
  143. * @returns {void}
  144. */
  145. function initCommands() {
  146. commands = {
  147. 'add-breakout-room': name => {
  148. if (!isLocalParticipantModerator(APP.store.getState())) {
  149. logger.error('Missing moderator rights to add breakout rooms');
  150. return;
  151. }
  152. APP.store.dispatch(createBreakoutRoom(name));
  153. },
  154. 'answer-knocking-participant': (id, approved) => {
  155. APP.store.dispatch(answerKnockingParticipant(id, approved));
  156. },
  157. 'approve-video': participantId => {
  158. if (!isLocalParticipantModerator(APP.store.getState())) {
  159. return;
  160. }
  161. APP.store.dispatch(approveParticipantVideo(participantId));
  162. },
  163. 'ask-to-unmute': participantId => {
  164. if (!isLocalParticipantModerator(APP.store.getState())) {
  165. return;
  166. }
  167. APP.store.dispatch(approveParticipantAudio(participantId));
  168. },
  169. 'auto-assign-to-breakout-rooms': () => {
  170. if (!isLocalParticipantModerator(APP.store.getState())) {
  171. logger.error('Missing moderator rights to auto-assign participants to breakout rooms');
  172. return;
  173. }
  174. APP.store.dispatch(autoAssignToBreakoutRooms());
  175. },
  176. 'grant-moderator': participantId => {
  177. if (!isLocalParticipantModerator(APP.store.getState())) {
  178. logger.error('Missing moderator rights to grant moderator right to another participant');
  179. return;
  180. }
  181. APP.store.dispatch(grantModerator(participantId));
  182. },
  183. 'display-name': displayName => {
  184. sendAnalytics(createApiEvent('display.name.changed'));
  185. APP.conference.changeLocalDisplayName(displayName);
  186. },
  187. 'local-subject': localSubject => {
  188. sendAnalytics(createApiEvent('local.subject.changed'));
  189. APP.store.dispatch(setLocalSubject(localSubject));
  190. },
  191. 'mute-everyone': mediaType => {
  192. const muteMediaType = mediaType ? mediaType : MEDIA_TYPE.AUDIO;
  193. sendAnalytics(createApiEvent('muted-everyone'));
  194. const localParticipant = getLocalParticipant(APP.store.getState());
  195. const exclude = [];
  196. if (localParticipant && isParticipantModerator(localParticipant)) {
  197. exclude.push(localParticipant.id);
  198. }
  199. APP.store.dispatch(muteAllParticipants(exclude, muteMediaType));
  200. },
  201. 'toggle-lobby': isLobbyEnabled => {
  202. APP.store.dispatch(toggleLobbyMode(isLobbyEnabled));
  203. },
  204. 'password': password => {
  205. const { conference, passwordRequired }
  206. = APP.store.getState()['features/base/conference'];
  207. if (passwordRequired) {
  208. sendAnalytics(createApiEvent('submit.password'));
  209. APP.store.dispatch(setPassword(
  210. passwordRequired,
  211. passwordRequired.join,
  212. password
  213. ));
  214. } else {
  215. sendAnalytics(createApiEvent('password.changed'));
  216. APP.store.dispatch(setPassword(
  217. conference,
  218. conference.lock,
  219. password
  220. ));
  221. }
  222. },
  223. 'pin-participant': (id, videoType) => {
  224. logger.debug('Pin participant command received');
  225. const state = APP.store.getState();
  226. // if id not provided, unpin everybody.
  227. if (!id) {
  228. if (isStageFilmstripAvailable(state)) {
  229. const pinnedParticipants = getPinnedActiveParticipants(state);
  230. pinnedParticipants?.forEach(p => {
  231. APP.store.dispatch(togglePinStageParticipant(p.participantId));
  232. });
  233. } else {
  234. APP.store.dispatch(pinParticipant());
  235. }
  236. return;
  237. }
  238. const participant = videoType === VIDEO_TYPE.DESKTOP
  239. ? getVirtualScreenshareParticipantByOwnerId(state, id) : getParticipantById(state, id);
  240. if (!participant) {
  241. logger.warn('Trying to pin a non-existing participant with pin-participant command.');
  242. return;
  243. }
  244. sendAnalytics(createApiEvent('participant.pinned'));
  245. const participantId = participant.id;
  246. if (isStageFilmstripAvailable(state)) {
  247. APP.store.dispatch(addStageParticipant(participantId, true));
  248. } else {
  249. APP.store.dispatch(pinParticipant(participantId));
  250. }
  251. },
  252. 'proxy-connection-event': event => {
  253. APP.conference.onProxyConnectionEvent(event);
  254. },
  255. 'reject-participant': (participantId, mediaType) => {
  256. if (!isLocalParticipantModerator(APP.store.getState())) {
  257. return;
  258. }
  259. const reject = mediaType === MEDIA_TYPE.VIDEO ? rejectParticipantVideo : rejectParticipantAudio;
  260. APP.store.dispatch(reject(participantId));
  261. },
  262. 'remove-breakout-room': breakoutRoomJid => {
  263. if (!isLocalParticipantModerator(APP.store.getState())) {
  264. logger.error('Missing moderator rights to remove breakout rooms');
  265. return;
  266. }
  267. APP.store.dispatch(removeBreakoutRoom(breakoutRoomJid));
  268. },
  269. 'resize-large-video': (width, height) => {
  270. logger.debug('Resize large video command received');
  271. sendAnalytics(createApiEvent('largevideo.resized'));
  272. APP.store.dispatch(resizeLargeVideo(width, height));
  273. },
  274. 'send-tones': (options = {}) => {
  275. const { duration, tones, pause } = options;
  276. APP.store.dispatch(sendTones(tones, duration, pause));
  277. },
  278. 'set-follow-me': value => {
  279. logger.debug('Set follow me command received');
  280. if (value) {
  281. sendAnalytics(createApiEvent('follow.me.set'));
  282. } else {
  283. sendAnalytics(createApiEvent('follow.me.unset'));
  284. }
  285. APP.store.dispatch(setFollowMe(value));
  286. },
  287. 'set-large-video-participant': (participantId, videoType) => {
  288. logger.debug('Set large video participant command received');
  289. if (!participantId) {
  290. sendAnalytics(createApiEvent('largevideo.participant.set'));
  291. APP.store.dispatch(selectParticipantInLargeVideo());
  292. return;
  293. }
  294. const state = APP.store.getState();
  295. const participant = videoType === VIDEO_TYPE.DESKTOP
  296. ? getVirtualScreenshareParticipantByOwnerId(state, participantId)
  297. : getParticipantById(state, participantId);
  298. if (!participant) {
  299. logger.warn('Trying to select a non-existing participant with set-large-video-participant command.');
  300. return;
  301. }
  302. sendAnalytics(createApiEvent('largevideo.participant.set'));
  303. APP.store.dispatch(selectParticipantInLargeVideo(participant.id));
  304. },
  305. 'set-participant-volume': (participantId, volume) => {
  306. APP.store.dispatch(setVolume(participantId, volume));
  307. },
  308. 'subject': subject => {
  309. sendAnalytics(createApiEvent('subject.changed'));
  310. APP.store.dispatch(setSubject(subject));
  311. },
  312. 'submit-feedback': feedback => {
  313. sendAnalytics(createApiEvent('submit.feedback'));
  314. APP.conference.submitFeedback(feedback.score, feedback.message);
  315. },
  316. 'toggle-audio': () => {
  317. sendAnalytics(createApiEvent('toggle-audio'));
  318. logger.log('Audio toggle: API command received');
  319. APP.conference.toggleAudioMuted(false /* no UI */);
  320. },
  321. 'toggle-video': () => {
  322. sendAnalytics(createApiEvent('toggle-video'));
  323. logger.log('Video toggle: API command received');
  324. APP.conference.toggleVideoMuted(false /* no UI */, true /* ensure track */);
  325. },
  326. 'toggle-film-strip': () => {
  327. sendAnalytics(createApiEvent('film.strip.toggled'));
  328. APP.UI.toggleFilmstrip();
  329. },
  330. /*
  331. * @param {Object} options - Additional details of how to perform
  332. * the action.
  333. * @param {number} options.width - width value for film strip.
  334. */
  335. 'resize-film-strip': (options = {}) => {
  336. sendAnalytics(createApiEvent('film.strip.resize'));
  337. APP.store.dispatch(resizeFilmStrip(options.width));
  338. },
  339. 'toggle-camera': () => {
  340. if (!isToggleCameraEnabled(APP.store.getState())) {
  341. return;
  342. }
  343. APP.store.dispatch(toggleCamera());
  344. },
  345. 'toggle-camera-mirror': () => {
  346. const state = APP.store.getState();
  347. const { localFlipX: currentFlipX } = state['features/base/settings'];
  348. APP.store.dispatch(updateSettings({ localFlipX: !currentFlipX }));
  349. },
  350. 'toggle-chat': () => {
  351. sendAnalytics(createApiEvent('chat.toggled'));
  352. APP.store.dispatch(toggleChat());
  353. },
  354. 'toggle-moderation': (enabled, mediaType) => {
  355. const state = APP.store.getState();
  356. if (!isLocalParticipantModerator(state)) {
  357. return;
  358. }
  359. const enable = mediaType === MEDIA_TYPE.VIDEO
  360. ? requestEnableVideoModeration : requestEnableAudioModeration;
  361. const disable = mediaType === MEDIA_TYPE.VIDEO
  362. ? requestDisableVideoModeration : requestDisableAudioModeration;
  363. if (enabled) {
  364. APP.store.dispatch(enable());
  365. } else {
  366. APP.store.dispatch(disable());
  367. }
  368. },
  369. 'toggle-participants-pane': enabled => {
  370. const toggleParticipantsPane = enabled
  371. ? openParticipantsPane : closeParticipantsPane;
  372. APP.store.dispatch(toggleParticipantsPane());
  373. },
  374. 'toggle-raise-hand': () => {
  375. const localParticipant = getLocalParticipant(APP.store.getState());
  376. if (!localParticipant) {
  377. return;
  378. }
  379. const raisedHand = hasRaisedHand(localParticipant);
  380. sendAnalytics(createApiEvent('raise-hand.toggled'));
  381. APP.store.dispatch(raiseHand(!raisedHand));
  382. },
  383. 'toggle-share-audio': () => {
  384. sendAnalytics(createApiEvent('audio.screen.sharing.toggled'));
  385. if (isScreenAudioSupported()) {
  386. APP.store.dispatch(startAudioScreenShareFlow());
  387. return;
  388. }
  389. logger.error('Audio screen sharing is not supported by the current platform!');
  390. },
  391. /**
  392. * Callback to invoke when the "toggle-share-screen" command is received.
  393. *
  394. * @param {Object} options - Additional details of how to perform
  395. * the action. Note this parameter is undocumented and experimental.
  396. * @param {boolean} options.enable - Whether trying to enable screen
  397. * sharing or to turn it off.
  398. * @returns {void}
  399. */
  400. 'toggle-share-screen': (options = {}) => {
  401. sendAnalytics(createApiEvent('screen.sharing.toggled'));
  402. toggleScreenSharing(options.enable);
  403. },
  404. 'set-noise-suppression-enabled': (options = {}) => {
  405. APP.store.dispatch(setNoiseSuppressionEnabled(options.enabled));
  406. },
  407. 'toggle-subtitles': () => {
  408. APP.store.dispatch(toggleRequestingSubtitles());
  409. },
  410. 'set-subtitles': enabled => {
  411. APP.store.dispatch(setRequestingSubtitles(enabled));
  412. },
  413. 'toggle-tile-view': () => {
  414. sendAnalytics(createApiEvent('tile-view.toggled'));
  415. APP.store.dispatch(toggleTileView());
  416. },
  417. 'set-tile-view': enabled => {
  418. APP.store.dispatch(setTileView(enabled));
  419. },
  420. 'video-hangup': (showFeedbackDialog = true) => {
  421. sendAnalytics(createApiEvent('video.hangup'));
  422. APP.conference.hangup(showFeedbackDialog);
  423. },
  424. 'email': email => {
  425. sendAnalytics(createApiEvent('email.changed'));
  426. APP.conference.changeLocalEmail(email);
  427. },
  428. 'avatar-url': avatarUrl => {
  429. sendAnalytics(createApiEvent('avatar.url.changed'));
  430. APP.conference.changeLocalAvatarUrl(avatarUrl);
  431. },
  432. 'send-chat-message': (message, to, ignorePrivacy = false) => {
  433. logger.debug('Send chat message command received');
  434. if (to) {
  435. const participant = getParticipantById(APP.store.getState(), to);
  436. if (participant) {
  437. APP.store.dispatch(setPrivateMessageRecipient(participant));
  438. } else {
  439. logger.error(`Participant with id ${to} not found!`);
  440. return;
  441. }
  442. } else {
  443. APP.store.dispatch(setPrivateMessageRecipient());
  444. }
  445. APP.store.dispatch(sendMessage(message, ignorePrivacy));
  446. },
  447. 'send-endpoint-text-message': (to, text) => {
  448. logger.debug('Send endpoint message command received');
  449. try {
  450. APP.conference.sendEndpointMessage(to, {
  451. name: ENDPOINT_TEXT_MESSAGE_NAME,
  452. text
  453. });
  454. } catch (err) {
  455. logger.error('Failed sending endpoint text message', err);
  456. }
  457. },
  458. 'overwrite-names': participantList => {
  459. logger.debug('Overwrite names command received');
  460. APP.store.dispatch(overwriteParticipantsNames(participantList));
  461. },
  462. 'toggle-e2ee': enabled => {
  463. logger.debug('Toggle E2EE key command received');
  464. APP.store.dispatch(toggleE2EE(enabled));
  465. },
  466. 'set-media-encryption-key': keyInfo => {
  467. APP.store.dispatch(setMediaEncryptionKey(JSON.parse(keyInfo)));
  468. },
  469. 'set-video-quality': frameHeight => {
  470. logger.debug('Set video quality command received');
  471. sendAnalytics(createApiEvent('set.video.quality'));
  472. APP.store.dispatch(setVideoQuality(frameHeight));
  473. },
  474. 'start-share-video': url => {
  475. logger.debug('Share video command received');
  476. sendAnalytics(createApiEvent('share.video.start'));
  477. const id = extractYoutubeIdOrURL(url);
  478. if (id) {
  479. APP.store.dispatch(playSharedVideo(id));
  480. }
  481. },
  482. 'stop-share-video': () => {
  483. logger.debug('Share video command received');
  484. sendAnalytics(createApiEvent('share.video.stop'));
  485. APP.store.dispatch(stopSharedVideo());
  486. },
  487. /**
  488. * Shows a custom in-meeting notification.
  489. *
  490. * @param { string } arg.title - Notification title.
  491. * @param { string } arg.description - Notification description.
  492. * @param { string } arg.uid - Optional unique identifier for the notification.
  493. * @param { string } arg.type - Notification type, either `error`, `info`, `normal`, `success` or `warning`.
  494. * Defaults to "normal" if not provided.
  495. * @param { string } arg.timeout - Timeout type, either `short`, `medium`, `long` or `sticky`.
  496. * Defaults to "short" if not provided.
  497. * @returns {void}
  498. */
  499. 'show-notification': ({
  500. title,
  501. description,
  502. uid,
  503. type = NOTIFICATION_TYPE.NORMAL,
  504. timeout = NOTIFICATION_TIMEOUT_TYPE.SHORT
  505. }) => {
  506. const validTypes = Object.values(NOTIFICATION_TYPE);
  507. const validTimeouts = Object.values(NOTIFICATION_TIMEOUT_TYPE);
  508. if (!validTypes.includes(type)) {
  509. logger.error(`Invalid notification type "${type}". Expecting one of ${validTypes}`);
  510. return;
  511. }
  512. if (!validTimeouts.includes(timeout)) {
  513. logger.error(`Invalid notification timeout "${timeout}". Expecting one of ${validTimeouts}`);
  514. return;
  515. }
  516. APP.store.dispatch(showNotification({
  517. uid,
  518. title,
  519. description,
  520. appearance: type
  521. }, timeout));
  522. },
  523. /**
  524. * Removes a notification given a unique identifier.
  525. *
  526. * @param { string } uid - Unique identifier for the notification to be removed.
  527. * @returns {void}
  528. */
  529. 'hide-notification': uid => {
  530. APP.store.dispatch(hideNotification(uid));
  531. },
  532. /**
  533. * Starts a file recording or streaming session depending on the passed on params.
  534. * For RTMP streams, `rtmpStreamKey` must be passed on. `rtmpBroadcastID` is optional.
  535. * For youtube streams, `youtubeStreamKey` must be passed on. `youtubeBroadcastID` is optional.
  536. * For dropbox recording, recording `mode` should be `file` and a dropbox oauth2 token must be provided.
  537. * For file recording, recording `mode` should be `file` and optionally `shouldShare` could be passed on.
  538. * For local recording, recording `mode` should be `local` and optionally `onlySelf` could be passed on.
  539. * No other params should be passed.
  540. *
  541. * @param { string } arg.mode - Recording mode, either `local`, `file` or `stream`.
  542. * @param { string } arg.dropboxToken - Dropbox oauth2 token.
  543. * @param { boolean } arg.onlySelf - Whether to only record the local streams.
  544. * @param { string } arg.rtmpStreamKey - The RTMP stream key.
  545. * @param { string } arg.rtmpBroadcastID - The RTMP broadcast ID.
  546. * @param { boolean } arg.shouldShare - Whether the recording should be shared with the participants or not.
  547. * Only applies to certain jitsi meet deploys.
  548. * @param { string } arg.youtubeStreamKey - The youtube stream key.
  549. * @param { string } arg.youtubeBroadcastID - The youtube broadcast ID.
  550. * @returns {void}
  551. */
  552. 'start-recording': ({
  553. mode,
  554. dropboxToken,
  555. onlySelf,
  556. shouldShare,
  557. rtmpStreamKey,
  558. rtmpBroadcastID,
  559. youtubeStreamKey,
  560. youtubeBroadcastID
  561. }) => {
  562. const state = APP.store.getState();
  563. const conference = getCurrentConference(state);
  564. if (!conference) {
  565. logger.error('Conference is not defined');
  566. return;
  567. }
  568. if (dropboxToken && !isDropboxEnabled(state)) {
  569. logger.error('Failed starting recording: dropbox is not enabled on this deployment');
  570. return;
  571. }
  572. if (mode === JitsiRecordingConstants.mode.STREAM && !(youtubeStreamKey || rtmpStreamKey)) {
  573. logger.error('Failed starting recording: missing youtube or RTMP stream key');
  574. return;
  575. }
  576. if (mode === 'local') {
  577. const { localRecording } = state['features/base/config'];
  578. if (!localRecording?.disable && supportsLocalRecording()) {
  579. APP.store.dispatch(startLocalVideoRecording(onlySelf));
  580. } else {
  581. logger.error('Failed starting recording: local recording is either disabled or not supported');
  582. }
  583. return;
  584. }
  585. let recordingConfig;
  586. if (mode === JitsiRecordingConstants.mode.FILE) {
  587. const { recordingService } = state['features/base/config'];
  588. if (!recordingService.enabled && !dropboxToken) {
  589. logger.error('Failed starting recording: the recording service is not enabled');
  590. return;
  591. }
  592. if (dropboxToken) {
  593. recordingConfig = {
  594. mode: JitsiRecordingConstants.mode.FILE,
  595. appData: JSON.stringify({
  596. 'file_recording_metadata': {
  597. 'upload_credentials': {
  598. 'service_name': RECORDING_TYPES.DROPBOX,
  599. 'token': dropboxToken
  600. }
  601. }
  602. })
  603. };
  604. } else {
  605. recordingConfig = {
  606. mode: JitsiRecordingConstants.mode.FILE,
  607. appData: JSON.stringify({
  608. 'file_recording_metadata': {
  609. 'share': shouldShare
  610. }
  611. })
  612. };
  613. }
  614. } else if (mode === JitsiRecordingConstants.mode.STREAM) {
  615. recordingConfig = {
  616. broadcastId: youtubeBroadcastID || rtmpBroadcastID,
  617. mode: JitsiRecordingConstants.mode.STREAM,
  618. streamId: youtubeStreamKey || rtmpStreamKey
  619. };
  620. } else {
  621. logger.error('Invalid recording mode provided');
  622. return;
  623. }
  624. if (isScreenshotCaptureEnabled(state, true, false)) {
  625. APP.store.dispatch(toggleScreenshotCaptureSummary(true));
  626. }
  627. conference.startRecording(recordingConfig);
  628. },
  629. /**
  630. * Stops a recording or streaming in progress.
  631. *
  632. * @param {string} mode - `local`, `file` or `stream`.
  633. * @returns {void}
  634. */
  635. 'stop-recording': mode => {
  636. const state = APP.store.getState();
  637. const conference = getCurrentConference(state);
  638. if (!conference) {
  639. logger.error('Conference is not defined');
  640. return;
  641. }
  642. if (mode === 'local') {
  643. APP.store.dispatch(stopLocalVideoRecording());
  644. return;
  645. }
  646. if (![ JitsiRecordingConstants.mode.FILE, JitsiRecordingConstants.mode.STREAM ].includes(mode)) {
  647. logger.error('Invalid recording mode provided!');
  648. return;
  649. }
  650. const activeSession = getActiveSession(state, mode);
  651. if (activeSession && activeSession.id) {
  652. APP.store.dispatch(toggleScreenshotCaptureSummary(false));
  653. conference.stopRecording(activeSession.id);
  654. } else {
  655. logger.error('No recording or streaming session found');
  656. }
  657. },
  658. 'initiate-private-chat': participantId => {
  659. const state = APP.store.getState();
  660. const participant = getParticipantById(state, participantId);
  661. if (participant) {
  662. const { isOpen: isChatOpen } = state['features/chat'];
  663. if (!isChatOpen) {
  664. APP.store.dispatch(toggleChat());
  665. }
  666. APP.store.dispatch(openChat(participant));
  667. } else {
  668. logger.error('No participant found for the given participantId');
  669. }
  670. },
  671. 'cancel-private-chat': () => {
  672. APP.store.dispatch(setPrivateMessageRecipient());
  673. },
  674. 'close-breakout-room': roomId => {
  675. if (!isLocalParticipantModerator(APP.store.getState())) {
  676. logger.error('Missing moderator rights to close breakout rooms');
  677. return;
  678. }
  679. APP.store.dispatch(closeBreakoutRoom(roomId));
  680. },
  681. 'join-breakout-room': roomId => {
  682. APP.store.dispatch(moveToRoom(roomId));
  683. },
  684. 'send-participant-to-room': (participantId, roomId) => {
  685. if (!isLocalParticipantModerator(APP.store.getState())) {
  686. logger.error('Missing moderator rights to send participants to rooms');
  687. return;
  688. }
  689. APP.store.dispatch(sendParticipantToRoom(participantId, roomId));
  690. },
  691. 'kick-participant': participantId => {
  692. APP.store.dispatch(kickParticipant(participantId));
  693. },
  694. 'overwrite-config': config => {
  695. const whitelistedConfig = getWhitelistedJSON('config', config);
  696. APP.store.dispatch(overwriteConfig(whitelistedConfig));
  697. },
  698. 'toggle-virtual-background': () => {
  699. APP.store.dispatch(toggleDialog(SettingsDialog, {
  700. defaultTab: SETTINGS_TABS.VIRTUAL_BACKGROUND }));
  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();