You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

API.js 68KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131
  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. try {
  1011. transport.sendEvent(event);
  1012. } catch (error) {
  1013. logger.error('Failed to send and IFrame API event', error);
  1014. }
  1015. }
  1016. }
  1017. /**
  1018. * Notify external application (if API is enabled) that the chat state has been updated.
  1019. *
  1020. * @param {number} unreadCount - The unread messages counter.
  1021. * @param {boolean} isOpen - True if the chat panel is open.
  1022. * @returns {void}
  1023. */
  1024. notifyChatUpdated(unreadCount, isOpen) {
  1025. this._sendEvent({
  1026. name: 'chat-updated',
  1027. unreadCount,
  1028. isOpen
  1029. });
  1030. }
  1031. /**
  1032. * Notify external application (if API is enabled) that message was sent.
  1033. *
  1034. * @param {string} message - Message body.
  1035. * @param {boolean} privateMessage - True if the message was a private message.
  1036. * @returns {void}
  1037. */
  1038. notifySendingChatMessage(message, privateMessage) {
  1039. this._sendEvent({
  1040. name: 'outgoing-message',
  1041. message,
  1042. privateMessage
  1043. });
  1044. }
  1045. /**
  1046. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  1047. *
  1048. * @param {MouseEvent} event - The mousemove event.
  1049. * @returns {void}
  1050. */
  1051. notifyMouseEnter(event) {
  1052. this._sendEvent({
  1053. name: 'mouse-enter',
  1054. event: sanitizeMouseEvent(event)
  1055. });
  1056. }
  1057. /**
  1058. * Notify external application (if API is enabled) that the mouse has entered inside the iframe.
  1059. *
  1060. * @param {MouseEvent} event - The mousemove event.
  1061. * @returns {void}
  1062. */
  1063. notifyMouseLeave(event) {
  1064. this._sendEvent({
  1065. name: 'mouse-leave',
  1066. event: sanitizeMouseEvent(event)
  1067. });
  1068. }
  1069. /**
  1070. * Notify external application (if API is enabled) that the mouse has moved inside the iframe.
  1071. *
  1072. * @param {MouseEvent} event - The mousemove event.
  1073. * @returns {void}
  1074. */
  1075. notifyMouseMove(event) {
  1076. this._sendEvent({
  1077. name: 'mouse-move',
  1078. event: sanitizeMouseEvent(event)
  1079. });
  1080. }
  1081. /**
  1082. * Notify the external application that the moderation status has changed.
  1083. *
  1084. * @param {string} mediaType - Media type for which the moderation changed.
  1085. * @param {boolean} enabled - Whether or not the new moderation status is enabled.
  1086. * @returns {void}
  1087. */
  1088. notifyModerationChanged(mediaType, enabled) {
  1089. this._sendEvent({
  1090. name: 'moderation-status-changed',
  1091. mediaType,
  1092. enabled
  1093. });
  1094. }
  1095. /**
  1096. * Notify the external application that a participant was approved on moderation.
  1097. *
  1098. * @param {string} participantId - The ID of the participant that got approved.
  1099. * @param {string} mediaType - Media type for which the participant was approved.
  1100. * @returns {void}
  1101. */
  1102. notifyParticipantApproved(participantId, mediaType) {
  1103. this._sendEvent({
  1104. name: 'moderation-participant-approved',
  1105. id: participantId,
  1106. mediaType
  1107. });
  1108. }
  1109. /**
  1110. * Notify the external application that a participant was rejected on moderation.
  1111. *
  1112. * @param {string} participantId - The ID of the participant that got rejected.
  1113. * @param {string} mediaType - Media type for which the participant was rejected.
  1114. * @returns {void}
  1115. */
  1116. notifyParticipantRejected(participantId, mediaType) {
  1117. this._sendEvent({
  1118. name: 'moderation-participant-rejected',
  1119. id: participantId,
  1120. mediaType
  1121. });
  1122. }
  1123. /**
  1124. * Notify the external app that a notification has been triggered.
  1125. *
  1126. * @param {string} title - The notification title.
  1127. * @param {string} description - The notification description.
  1128. *
  1129. * @returns {void}
  1130. */
  1131. notifyNotificationTriggered(title, description) {
  1132. this._sendEvent({
  1133. description,
  1134. name: 'notification-triggered',
  1135. title
  1136. });
  1137. }
  1138. /**
  1139. * Notify external application that the video quality setting has changed.
  1140. *
  1141. * @param {number} videoQuality - The video quality. The number represents the maximum height of the video streams.
  1142. * @returns {void}
  1143. */
  1144. notifyVideoQualityChanged(videoQuality) {
  1145. this._sendEvent({
  1146. name: 'video-quality-changed',
  1147. videoQuality
  1148. });
  1149. }
  1150. /**
  1151. * Notify external application (if API is enabled) that message was
  1152. * received.
  1153. *
  1154. * @param {Object} options - Object with the message properties.
  1155. * @returns {void}
  1156. */
  1157. notifyReceivedChatMessage(
  1158. { body, id, nick, privateMessage, ts } = {}) {
  1159. if (APP.conference.isLocalId(id)) {
  1160. return;
  1161. }
  1162. this._sendEvent({
  1163. name: 'incoming-message',
  1164. from: id,
  1165. message: body,
  1166. nick,
  1167. privateMessage,
  1168. stamp: ts
  1169. });
  1170. }
  1171. /**
  1172. * Notify external application (if API is enabled) that user joined the
  1173. * conference.
  1174. *
  1175. * @param {string} id - User id.
  1176. * @param {Object} props - The display name of the user.
  1177. * @returns {void}
  1178. */
  1179. notifyUserJoined(id, props) {
  1180. this._sendEvent({
  1181. name: 'participant-joined',
  1182. id,
  1183. ...props
  1184. });
  1185. }
  1186. /**
  1187. * Notify external application (if API is enabled) that user left the
  1188. * conference.
  1189. *
  1190. * @param {string} id - User id.
  1191. * @returns {void}
  1192. */
  1193. notifyUserLeft(id) {
  1194. this._sendEvent({
  1195. name: 'participant-left',
  1196. id
  1197. });
  1198. }
  1199. /**
  1200. * Notify external application (if API is enabled) that the user role
  1201. * has changed.
  1202. *
  1203. * @param {string} id - User id.
  1204. * @param {string} role - The new user role.
  1205. * @returns {void}
  1206. */
  1207. notifyUserRoleChanged(id, role) {
  1208. this._sendEvent({
  1209. name: 'participant-role-changed',
  1210. id,
  1211. role
  1212. });
  1213. }
  1214. /**
  1215. * Notify external application (if API is enabled) that user changed their
  1216. * avatar.
  1217. *
  1218. * @param {string} id - User id.
  1219. * @param {string} avatarURL - The new avatar URL of the participant.
  1220. * @returns {void}
  1221. */
  1222. notifyAvatarChanged(id, avatarURL) {
  1223. this._sendEvent({
  1224. name: 'avatar-changed',
  1225. avatarURL,
  1226. id
  1227. });
  1228. }
  1229. /**
  1230. * Notify external application (if API is enabled) that user received
  1231. * a text message through datachannels.
  1232. *
  1233. * @param {Object} data - The event data.
  1234. * @returns {void}
  1235. */
  1236. notifyEndpointTextMessageReceived(data) {
  1237. this._sendEvent({
  1238. name: 'endpoint-text-message-received',
  1239. data
  1240. });
  1241. }
  1242. /**
  1243. * Notify external application (if API is enabled) that some face landmark data is available.
  1244. *
  1245. * @param {Object | undefined} faceBox - Detected face(s) bounding box (left, right, width).
  1246. * @param {string} faceExpression - Detected face expression.
  1247. * @returns {void}
  1248. */
  1249. notifyFaceLandmarkDetected(faceBox, faceExpression) {
  1250. this._sendEvent({
  1251. name: 'face-landmark-detected',
  1252. faceBox,
  1253. faceExpression
  1254. });
  1255. }
  1256. /**
  1257. * Notify external application (if API is enabled) that the list of sharing participants changed.
  1258. *
  1259. * @param {Object} data - The event data.
  1260. * @returns {void}
  1261. */
  1262. notifySharingParticipantsChanged(data) {
  1263. this._sendEvent({
  1264. name: 'content-sharing-participants-changed',
  1265. data
  1266. });
  1267. }
  1268. /**
  1269. * Notify external application (if API is enabled) that the device list has
  1270. * changed.
  1271. *
  1272. * @param {Object} devices - The new device list.
  1273. * @returns {void}
  1274. */
  1275. notifyDeviceListChanged(devices) {
  1276. this._sendEvent({
  1277. name: 'device-list-changed',
  1278. devices
  1279. });
  1280. }
  1281. /**
  1282. * Notify external application (if API is enabled) that user changed their
  1283. * nickname.
  1284. *
  1285. * @param {string} id - User id.
  1286. * @param {string} displayname - User nickname.
  1287. * @param {string} formattedDisplayName - The display name shown in Jitsi
  1288. * meet's UI for the user.
  1289. * @returns {void}
  1290. */
  1291. notifyDisplayNameChanged(
  1292. id,
  1293. { displayName, formattedDisplayName }) {
  1294. this._sendEvent({
  1295. name: 'display-name-change',
  1296. displayname: displayName,
  1297. formattedDisplayName,
  1298. id
  1299. });
  1300. }
  1301. /**
  1302. * Notify external application (if API is enabled) that user changed their
  1303. * email.
  1304. *
  1305. * @param {string} id - User id.
  1306. * @param {string} email - The new email of the participant.
  1307. * @returns {void}
  1308. */
  1309. notifyEmailChanged(
  1310. id,
  1311. { email }) {
  1312. this._sendEvent({
  1313. name: 'email-change',
  1314. email,
  1315. id
  1316. });
  1317. }
  1318. /**
  1319. * Notify external application (if API is enabled) that the an error has been logged.
  1320. *
  1321. * @param {string} logLevel - The message log level.
  1322. * @param {Array<string>} args - Array of strings composing the log message.
  1323. * @returns {void}
  1324. */
  1325. notifyLog(logLevel, args = []) {
  1326. if (!Array.isArray(args)) {
  1327. logger.error('notifyLog received wrong argument types!');
  1328. return;
  1329. }
  1330. // Trying to convert arguments to strings. Otherwise in order to send the event the arguments will be formatted
  1331. // with JSON.stringify which can throw an error because of circular objects and we will lose the whole log.
  1332. const formattedArguments = [];
  1333. args.forEach(arg => {
  1334. let formattedArgument = '';
  1335. if (arg instanceof Error) {
  1336. formattedArgument += `${arg.toString()}: ${arg.stack}`;
  1337. } else if (typeof arg === 'object') {
  1338. // NOTE: The non-enumerable properties of the objects wouldn't be included in the string after
  1339. // JSON.strigify. For example Map instance will be translated to '{}'. So I think we have to eventually
  1340. // do something better for parsing the arguments. But since this option for strigify is part of the
  1341. // public interface and I think it could be useful in some cases I will it for now.
  1342. try {
  1343. formattedArgument += JSON.stringify(arg);
  1344. } catch (error) {
  1345. formattedArgument += arg;
  1346. }
  1347. } else {
  1348. formattedArgument += arg;
  1349. }
  1350. formattedArguments.push(formattedArgument);
  1351. });
  1352. this._sendEvent({
  1353. name: 'log',
  1354. logLevel,
  1355. args: formattedArguments
  1356. });
  1357. }
  1358. /**
  1359. * Notify external application (if API is enabled) that the conference has
  1360. * been joined.
  1361. *
  1362. * @param {string} roomName - The room name.
  1363. * @param {string} id - The id of the local user.
  1364. * @param {Object} props - The display name, the avatar URL of the local
  1365. * user and the type of the room.
  1366. * @returns {void}
  1367. */
  1368. notifyConferenceJoined(roomName, id, props) {
  1369. this._sendEvent({
  1370. name: 'video-conference-joined',
  1371. roomName,
  1372. id,
  1373. ...props
  1374. });
  1375. }
  1376. /**
  1377. * Notify external application (if API is enabled) that local user has left the conference.
  1378. *
  1379. * @param {string} roomName - User id.
  1380. * @returns {void}
  1381. */
  1382. notifyConferenceLeft(roomName) {
  1383. this._sendEvent({
  1384. name: 'video-conference-left',
  1385. roomName
  1386. });
  1387. }
  1388. /**
  1389. * Notify external application that the data channel has been closed.
  1390. *
  1391. * @param {number} code - The close code.
  1392. * @param {string} reason - The close reason.
  1393. *
  1394. * @returns {void}
  1395. */
  1396. notifyDataChannelClosed(code, reason) {
  1397. this._sendEvent({
  1398. name: 'data-channel-closed',
  1399. code,
  1400. reason
  1401. });
  1402. }
  1403. /**
  1404. * Notify external application that the data channel has been opened.
  1405. *
  1406. * @returns {void}
  1407. */
  1408. notifyDataChannelOpened() {
  1409. this._sendEvent({ name: 'data-channel-opened' });
  1410. }
  1411. /**
  1412. * Notify external application (if API is enabled) that we are ready to be
  1413. * closed.
  1414. *
  1415. * @returns {void}
  1416. */
  1417. notifyReadyToClose() {
  1418. this._sendEvent({ name: 'video-ready-to-close' });
  1419. }
  1420. /**
  1421. * Notify external application (if API is enabled) that a suspend event in host computer.
  1422. *
  1423. * @returns {void}
  1424. */
  1425. notifySuspendDetected() {
  1426. this._sendEvent({ name: 'suspend-detected' });
  1427. }
  1428. /**
  1429. * Notify external application (if API is enabled) for audio muted status
  1430. * changed.
  1431. *
  1432. * @param {boolean} muted - The new muted status.
  1433. * @returns {void}
  1434. */
  1435. notifyAudioMutedStatusChanged(muted) {
  1436. this._sendEvent({
  1437. name: 'audio-mute-status-changed',
  1438. muted
  1439. });
  1440. }
  1441. /**
  1442. * Notify external application (if API is enabled) for video muted status
  1443. * changed.
  1444. *
  1445. * @param {boolean} muted - The new muted status.
  1446. * @returns {void}
  1447. */
  1448. notifyVideoMutedStatusChanged(muted) {
  1449. this._sendEvent({
  1450. name: 'video-mute-status-changed',
  1451. muted
  1452. });
  1453. }
  1454. /**
  1455. * Notify external application (if API is enabled) for audio availability
  1456. * changed.
  1457. *
  1458. * @param {boolean} available - True if available and false otherwise.
  1459. * @returns {void}
  1460. */
  1461. notifyAudioAvailabilityChanged(available) {
  1462. audioAvailable = available;
  1463. this._sendEvent({
  1464. name: 'audio-availability-changed',
  1465. available
  1466. });
  1467. }
  1468. /**
  1469. * Notify external application (if API is enabled) for video available
  1470. * status changed.
  1471. *
  1472. * @param {boolean} available - True if available and false otherwise.
  1473. * @returns {void}
  1474. */
  1475. notifyVideoAvailabilityChanged(available) {
  1476. videoAvailable = available;
  1477. this._sendEvent({
  1478. name: 'video-availability-changed',
  1479. available
  1480. });
  1481. }
  1482. /**
  1483. * Notify external application (if API is enabled) that the on stage
  1484. * participant has changed.
  1485. *
  1486. * @param {string} id - User id of the new on stage participant.
  1487. * @returns {void}
  1488. */
  1489. notifyOnStageParticipantChanged(id) {
  1490. this._sendEvent({
  1491. name: 'on-stage-participant-changed',
  1492. id
  1493. });
  1494. }
  1495. /**
  1496. * Notify external application (if API is enabled) that the prejoin video
  1497. * visibility had changed.
  1498. *
  1499. * @param {boolean} isVisible - Whether the prejoin video is visible.
  1500. * @returns {void}
  1501. */
  1502. notifyPrejoinVideoVisibilityChanged(isVisible) {
  1503. this._sendEvent({
  1504. name: 'on-prejoin-video-changed',
  1505. isVisible
  1506. });
  1507. }
  1508. /**
  1509. * Notify external application (if API is enabled) that the prejoin
  1510. * screen was loaded.
  1511. *
  1512. * @returns {void}
  1513. */
  1514. notifyPrejoinLoaded() {
  1515. const state = APP.store.getState();
  1516. const { defaultLocalDisplayName } = state['features/base/config'];
  1517. const displayName = getDisplayName(state);
  1518. this._sendEvent({
  1519. name: 'prejoin-screen-loaded',
  1520. id: LOCAL_PARTICIPANT_DEFAULT_ID,
  1521. displayName,
  1522. formattedDisplayName: appendSuffix(displayName, defaultLocalDisplayName)
  1523. });
  1524. }
  1525. /**
  1526. * Notify external application of an unexpected camera-related error having
  1527. * occurred.
  1528. *
  1529. * @param {string} type - The type of the camera error.
  1530. * @param {string} message - Additional information about the error.
  1531. * @returns {void}
  1532. */
  1533. notifyOnCameraError(type, message) {
  1534. this._sendEvent({
  1535. name: 'camera-error',
  1536. type,
  1537. message
  1538. });
  1539. }
  1540. /**
  1541. * Notify external application of an unexpected mic-related error having
  1542. * occurred.
  1543. *
  1544. * @param {string} type - The type of the mic error.
  1545. * @param {string} message - Additional information about the error.
  1546. * @returns {void}
  1547. */
  1548. notifyOnMicError(type, message) {
  1549. this._sendEvent({
  1550. name: 'mic-error',
  1551. type,
  1552. message
  1553. });
  1554. }
  1555. /**
  1556. * Notify external application (if API is enabled) that conference feedback
  1557. * has been submitted. Intended to be used in conjunction with the
  1558. * submit-feedback command to get notified if feedback was submitted.
  1559. *
  1560. * @param {string} error - A failure message, if any.
  1561. * @returns {void}
  1562. */
  1563. notifyFeedbackSubmitted(error) {
  1564. this._sendEvent({
  1565. name: 'feedback-submitted',
  1566. error
  1567. });
  1568. }
  1569. /**
  1570. * Notify external application (if API is enabled) that the feedback prompt
  1571. * has been displayed.
  1572. *
  1573. * @returns {void}
  1574. */
  1575. notifyFeedbackPromptDisplayed() {
  1576. this._sendEvent({ name: 'feedback-prompt-displayed' });
  1577. }
  1578. /**
  1579. * Notify external application (if API is enabled) that the display
  1580. * configuration of the filmstrip has been changed.
  1581. *
  1582. * @param {boolean} visible - Whether or not the filmstrip has been set to
  1583. * be displayed or hidden.
  1584. * @returns {void}
  1585. */
  1586. notifyFilmstripDisplayChanged(visible) {
  1587. this._sendEvent({
  1588. name: 'filmstrip-display-changed',
  1589. visible
  1590. });
  1591. }
  1592. /**
  1593. * Notify external application of a participant, remote or local, being
  1594. * removed from the conference by another participant.
  1595. *
  1596. * @param {string} kicked - The ID of the participant removed from the
  1597. * conference.
  1598. * @param {string} kicker - The ID of the participant that removed the
  1599. * other participant.
  1600. * @returns {void}
  1601. */
  1602. notifyKickedOut(kicked, kicker) {
  1603. this._sendEvent({
  1604. name: 'participant-kicked-out',
  1605. kicked,
  1606. kicker
  1607. });
  1608. }
  1609. /**
  1610. * Notify external application of the current meeting requiring a password
  1611. * to join.
  1612. *
  1613. * @returns {void}
  1614. */
  1615. notifyOnPasswordRequired() {
  1616. this._sendEvent({ name: 'password-required' });
  1617. }
  1618. /**
  1619. * Notify external application (if API is enabled) that the screen sharing
  1620. * has been turned on/off.
  1621. *
  1622. * @param {boolean} on - True if screen sharing is enabled.
  1623. * @param {Object} details - Additional information about the screen
  1624. * sharing.
  1625. * @param {string} details.sourceType - Type of device or window the screen
  1626. * share is capturing.
  1627. * @returns {void}
  1628. */
  1629. notifyScreenSharingStatusChanged(on, details) {
  1630. this._sendEvent({
  1631. name: 'screen-sharing-status-changed',
  1632. on,
  1633. details
  1634. });
  1635. }
  1636. /**
  1637. * Notify external application (if API is enabled) that the dominant speaker
  1638. * has been turned on/off.
  1639. *
  1640. * @param {string} id - Id of the dominant participant.
  1641. * @returns {void}
  1642. */
  1643. notifyDominantSpeakerChanged(id) {
  1644. this._sendEvent({
  1645. name: 'dominant-speaker-changed',
  1646. id
  1647. });
  1648. }
  1649. /**
  1650. * Notify external application (if API is enabled) that the conference
  1651. * changed their subject.
  1652. *
  1653. * @param {string} subject - Conference subject.
  1654. * @returns {void}
  1655. */
  1656. notifySubjectChanged(subject) {
  1657. this._sendEvent({
  1658. name: 'subject-change',
  1659. subject
  1660. });
  1661. }
  1662. /**
  1663. * Notify external application (if API is enabled) that tile view has been
  1664. * entered or exited.
  1665. *
  1666. * @param {string} enabled - True if tile view is currently displayed, false
  1667. * otherwise.
  1668. * @returns {void}
  1669. */
  1670. notifyTileViewChanged(enabled) {
  1671. this._sendEvent({
  1672. name: 'tile-view-changed',
  1673. enabled
  1674. });
  1675. }
  1676. /**
  1677. * Notify external application (if API is enabled) that the localStorage has changed.
  1678. *
  1679. * @param {string} localStorageContent - The new localStorageContent.
  1680. * @returns {void}
  1681. */
  1682. notifyLocalStorageChanged(localStorageContent) {
  1683. this._sendEvent({
  1684. name: 'local-storage-changed',
  1685. localStorageContent
  1686. });
  1687. }
  1688. /**
  1689. * Notify external application (if API is enabled) that user updated their hand raised.
  1690. *
  1691. * @param {string} id - User id.
  1692. * @param {boolean} handRaised - Whether user has raised hand.
  1693. * @returns {void}
  1694. */
  1695. notifyRaiseHandUpdated(id, handRaised) {
  1696. this._sendEvent({
  1697. name: 'raise-hand-updated',
  1698. handRaised,
  1699. id
  1700. });
  1701. }
  1702. /**
  1703. * Notify external application (if API is enabled) that recording has started or stopped.
  1704. *
  1705. * @param {boolean} on - True if recording is on, false otherwise.
  1706. * @param {string} mode - Stream or file or local.
  1707. * @param {string} error - Error type or null if success.
  1708. * @returns {void}
  1709. */
  1710. notifyRecordingStatusChanged(on, mode, error) {
  1711. this._sendEvent({
  1712. name: 'recording-status-changed',
  1713. on,
  1714. mode,
  1715. error
  1716. });
  1717. }
  1718. /**
  1719. * Notify external application (if API is enabled) that the current recording link is
  1720. * available.
  1721. *
  1722. * @param {string} link - The recording download link.
  1723. * @param {number} ttl - The recording download link time to live.
  1724. * @returns {void}
  1725. */
  1726. notifyRecordingLinkAvailable(link, ttl) {
  1727. this._sendEvent({
  1728. name: 'recording-link-available',
  1729. link,
  1730. ttl
  1731. });
  1732. }
  1733. /**
  1734. * Notify external application (if API is enabled) that a participant is knocking in the lobby.
  1735. *
  1736. * @param {Object} participant - Participant data such as id and name.
  1737. * @returns {void}
  1738. */
  1739. notifyKnockingParticipant(participant) {
  1740. this._sendEvent({
  1741. name: 'knocking-participant',
  1742. participant
  1743. });
  1744. }
  1745. /**
  1746. * Notify external application (if API is enabled) that an error occurred.
  1747. *
  1748. * @param {Object} error - The error.
  1749. * @returns {void}
  1750. */
  1751. notifyError(error) {
  1752. this._sendEvent({
  1753. name: 'error-occurred',
  1754. error
  1755. });
  1756. }
  1757. /**
  1758. * Notify external application ( if API is enabled) that a toolbar button was clicked.
  1759. *
  1760. * @param {string} key - The key of the toolbar button.
  1761. * @param {boolean} preventExecution - Whether execution of the button click was prevented or not.
  1762. * @returns {void}
  1763. */
  1764. notifyToolbarButtonClicked(key, preventExecution) {
  1765. this._sendEvent({
  1766. name: 'toolbar-button-clicked',
  1767. key,
  1768. preventExecution
  1769. });
  1770. }
  1771. /**
  1772. * Notify external application (if API is enabled) whether the used browser is supported or not.
  1773. *
  1774. * @param {boolean} supported - If browser is supported or not.
  1775. * @returns {void}
  1776. */
  1777. notifyBrowserSupport(supported) {
  1778. this._sendEvent({
  1779. name: 'browser-support',
  1780. supported
  1781. });
  1782. }
  1783. /**
  1784. * Notify external application that the breakout rooms changed.
  1785. *
  1786. * @param {Array} rooms - Array containing the breakout rooms and main room.
  1787. * @returns {void}
  1788. */
  1789. notifyBreakoutRoomsUpdated(rooms) {
  1790. this._sendEvent({
  1791. name: 'breakout-rooms-updated',
  1792. rooms
  1793. });
  1794. }
  1795. /**
  1796. * Notify the external application that the state of the participants pane changed.
  1797. *
  1798. * @param {boolean} open - Whether the panel is open or not.
  1799. * @returns {void}
  1800. */
  1801. notifyParticipantsPaneToggled(open) {
  1802. this._sendEvent({
  1803. name: 'participants-pane-toggled',
  1804. open
  1805. });
  1806. }
  1807. /**
  1808. * Notify the external application that the audio or video is being shared by a participant.
  1809. *
  1810. * @param {string} mediaType - Whether the content which is being shared is audio or video.
  1811. * @param {string} value - Whether the sharing is playing, pause or stop (on audio there is only playing and stop).
  1812. * @param {string} participantId - Participant id of the participant which started or ended
  1813. * the video or audio sharing.
  1814. * @returns {void}
  1815. */
  1816. notifyAudioOrVideoSharingToggled(mediaType, value, participantId) {
  1817. this._sendEvent({
  1818. name: 'audio-or-video-sharing-toggled',
  1819. mediaType,
  1820. value,
  1821. participantId
  1822. });
  1823. }
  1824. /**
  1825. * Notify the external application that a PeerConnection lost connectivity. This event is fired only if
  1826. * a PC `failed` but connectivity to the rtcstats server is still maintained signaling that there is a
  1827. * problem establishing a link between the app and the JVB server or the remote peer in case of P2P.
  1828. * Will only fire if rtcstats is enabled.
  1829. *
  1830. * @param {boolean} isP2P - Type of PC.
  1831. * @param {boolean} wasConnected - Was this connection previously connected. If it was it could mean
  1832. * that connectivity was disrupted, if not it most likely means that the app could not reach
  1833. * the JVB server, or the other peer in case of P2P.
  1834. *
  1835. * @returns {void}
  1836. */
  1837. notifyPeerConnectionFailure(isP2P, wasConnected) {
  1838. this._sendEvent({
  1839. name: 'peer-connection-failure',
  1840. isP2P,
  1841. wasConnected
  1842. });
  1843. }
  1844. /**
  1845. * Notify external application ( if API is enabled) that a participant menu button was clicked.
  1846. *
  1847. * @param {string} key - The key of the participant menu button.
  1848. * @param {string} participantId - The ID of the participant for whom the participant menu button was clicked.
  1849. * @param {boolean} preventExecution - Whether execution of the button click was prevented or not.
  1850. * @returns {void}
  1851. */
  1852. notifyParticipantMenuButtonClicked(key, participantId, preventExecution) {
  1853. this._sendEvent({
  1854. name: 'participant-menu-button-clicked',
  1855. key,
  1856. participantId,
  1857. preventExecution
  1858. });
  1859. }
  1860. /**
  1861. * Notify external application (if API is enabled) if whiteboard state is
  1862. * changed.
  1863. *
  1864. * @param {WhiteboardStatus} status - The new whiteboard status.
  1865. * @returns {void}
  1866. */
  1867. notifyWhiteboardStatusChanged(status) {
  1868. this._sendEvent({
  1869. name: 'whiteboard-status-changed',
  1870. status
  1871. });
  1872. }
  1873. /**
  1874. * Notify external application (if API is enabled) if non participant message
  1875. * is received.
  1876. *
  1877. * @param {string} id - The resource id of the sender.
  1878. * @param {Object} json - The json carried by the message.
  1879. * @returns {void}
  1880. */
  1881. notifyNonParticipantMessageReceived(id, json) {
  1882. this._sendEvent({
  1883. name: 'non-participant-message-received',
  1884. id,
  1885. message: json
  1886. });
  1887. }
  1888. /**
  1889. * Notify the external application (if API is enabled) if the connection type changed.
  1890. *
  1891. * @param {boolean} isP2p - Whether the new connection is P2P.
  1892. * @returns {void}
  1893. */
  1894. notifyP2pStatusChanged(isP2p) {
  1895. this._sendEvent({
  1896. name: 'p2p-status-changed',
  1897. isP2p
  1898. });
  1899. }
  1900. /**
  1901. * Notify the external application (if API is enabled) when the compute pressure changed.
  1902. *
  1903. * @param {Array} records - The new pressure records.
  1904. * @returns {void}
  1905. */
  1906. notifyComputePressureChanged(records) {
  1907. this._sendEvent({
  1908. name: 'compute-pressure-changed',
  1909. records
  1910. });
  1911. }
  1912. /**
  1913. * Disposes the allocated resources.
  1914. *
  1915. * @returns {void}
  1916. */
  1917. dispose() {
  1918. if (this._enabled) {
  1919. this._enabled = false;
  1920. }
  1921. }
  1922. }
  1923. export default new API();