您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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