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.

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