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

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