Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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