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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196
  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. * @param {boolean} transcription - True if a transcription is being recorded, false otherwise.
  1728. * @returns {void}
  1729. */
  1730. notifyRecordingStatusChanged(on, mode, error, transcription) {
  1731. this._sendEvent({
  1732. name: 'recording-status-changed',
  1733. on,
  1734. mode,
  1735. error,
  1736. transcription
  1737. });
  1738. }
  1739. /**
  1740. * Notify external application (if API is enabled) that the current recording link is
  1741. * available.
  1742. *
  1743. * @param {string} link - The recording download link.
  1744. * @param {number} ttl - The recording download link time to live.
  1745. * @returns {void}
  1746. */
  1747. notifyRecordingLinkAvailable(link, ttl) {
  1748. this._sendEvent({
  1749. name: 'recording-link-available',
  1750. link,
  1751. ttl
  1752. });
  1753. }
  1754. /**
  1755. * Notify external application (if API is enabled) that a participant is knocking in the lobby.
  1756. *
  1757. * @param {Object} participant - Participant data such as id and name.
  1758. * @returns {void}
  1759. */
  1760. notifyKnockingParticipant(participant) {
  1761. this._sendEvent({
  1762. name: 'knocking-participant',
  1763. participant
  1764. });
  1765. }
  1766. /**
  1767. * Notify external application (if API is enabled) that an error occurred.
  1768. *
  1769. * @param {Object} error - The error.
  1770. * @returns {void}
  1771. */
  1772. notifyError(error) {
  1773. this._sendEvent({
  1774. name: 'error-occurred',
  1775. error
  1776. });
  1777. }
  1778. /**
  1779. * Notify external application ( if API is enabled) that a toolbar button was clicked.
  1780. *
  1781. * @param {string} key - The key of the toolbar button.
  1782. * @param {boolean} preventExecution - Whether execution of the button click was prevented or not.
  1783. * @returns {void}
  1784. */
  1785. notifyToolbarButtonClicked(key, preventExecution) {
  1786. this._sendEvent({
  1787. name: 'toolbar-button-clicked',
  1788. key,
  1789. preventExecution
  1790. });
  1791. }
  1792. /**
  1793. * Notify external application (if API is enabled) that transcribing has started or stopped.
  1794. *
  1795. * @param {boolean} on - True if transcribing is on, false otherwise.
  1796. * @returns {void}
  1797. */
  1798. notifyTranscribingStatusChanged(on) {
  1799. this._sendEvent({
  1800. name: 'transcribing-status-changed',
  1801. on
  1802. });
  1803. }
  1804. /**
  1805. * Notify external application (if API is enabled) that the user received
  1806. * a transcription chunk.
  1807. *
  1808. * @param {Object} data - The event data.
  1809. * @returns {void}
  1810. */
  1811. notifyTranscriptionChunkReceived(data) {
  1812. this._sendEvent({
  1813. name: 'transcription-chunk-received',
  1814. data
  1815. });
  1816. }
  1817. /**
  1818. * Notify external application (if API is enabled) whether the used browser is supported or not.
  1819. *
  1820. * @param {boolean} supported - If browser is supported or not.
  1821. * @returns {void}
  1822. */
  1823. notifyBrowserSupport(supported) {
  1824. this._sendEvent({
  1825. name: 'browser-support',
  1826. supported
  1827. });
  1828. }
  1829. /**
  1830. * Notify external application that the breakout rooms changed.
  1831. *
  1832. * @param {Array} rooms - Array containing the breakout rooms and main room.
  1833. * @returns {void}
  1834. */
  1835. notifyBreakoutRoomsUpdated(rooms) {
  1836. this._sendEvent({
  1837. name: 'breakout-rooms-updated',
  1838. rooms
  1839. });
  1840. }
  1841. /**
  1842. * Notify the external application that the state of the participants pane changed.
  1843. *
  1844. * @param {boolean} open - Whether the panel is open or not.
  1845. * @returns {void}
  1846. */
  1847. notifyParticipantsPaneToggled(open) {
  1848. this._sendEvent({
  1849. name: 'participants-pane-toggled',
  1850. open
  1851. });
  1852. }
  1853. /**
  1854. * Notify the external application that the audio or video is being shared by a participant.
  1855. *
  1856. * @param {string} mediaType - Whether the content which is being shared is audio or video.
  1857. * @param {string} value - Whether the sharing is playing, pause or stop (on audio there is only playing and stop).
  1858. * @param {string} participantId - Participant id of the participant which started or ended
  1859. * the video or audio sharing.
  1860. * @returns {void}
  1861. */
  1862. notifyAudioOrVideoSharingToggled(mediaType, value, participantId) {
  1863. this._sendEvent({
  1864. name: 'audio-or-video-sharing-toggled',
  1865. mediaType,
  1866. value,
  1867. participantId
  1868. });
  1869. }
  1870. /**
  1871. * Notify the external application that a PeerConnection lost connectivity. This event is fired only if
  1872. * a PC `failed` but connectivity to the rtcstats server is still maintained signaling that there is a
  1873. * problem establishing a link between the app and the JVB server or the remote peer in case of P2P.
  1874. * Will only fire if rtcstats is enabled.
  1875. *
  1876. * @param {boolean} isP2P - Type of PC.
  1877. * @param {boolean} wasConnected - Was this connection previously connected. If it was it could mean
  1878. * that connectivity was disrupted, if not it most likely means that the app could not reach
  1879. * the JVB server, or the other peer in case of P2P.
  1880. *
  1881. * @returns {void}
  1882. */
  1883. notifyPeerConnectionFailure(isP2P, wasConnected) {
  1884. this._sendEvent({
  1885. name: 'peer-connection-failure',
  1886. isP2P,
  1887. wasConnected
  1888. });
  1889. }
  1890. /**
  1891. * Notify external application ( if API is enabled) that a participant menu button was clicked.
  1892. *
  1893. * @param {string} key - The key of the participant menu button.
  1894. * @param {string} participantId - The ID of the participant for whom the participant menu button was clicked.
  1895. * @param {boolean} preventExecution - Whether execution of the button click was prevented or not.
  1896. * @returns {void}
  1897. */
  1898. notifyParticipantMenuButtonClicked(key, participantId, preventExecution) {
  1899. this._sendEvent({
  1900. name: 'participant-menu-button-clicked',
  1901. key,
  1902. participantId,
  1903. preventExecution
  1904. });
  1905. }
  1906. /**
  1907. * Notify external application (if API is enabled) if whiteboard state is
  1908. * changed.
  1909. *
  1910. * @param {WhiteboardStatus} status - The new whiteboard status.
  1911. * @returns {void}
  1912. */
  1913. notifyWhiteboardStatusChanged(status) {
  1914. this._sendEvent({
  1915. name: 'whiteboard-status-changed',
  1916. status
  1917. });
  1918. }
  1919. /**
  1920. * Notify external application (if API is enabled) if non participant message
  1921. * is received.
  1922. *
  1923. * @param {string} id - The resource id of the sender.
  1924. * @param {Object} json - The json carried by the message.
  1925. * @returns {void}
  1926. */
  1927. notifyNonParticipantMessageReceived(id, json) {
  1928. this._sendEvent({
  1929. name: 'non-participant-message-received',
  1930. id,
  1931. message: json
  1932. });
  1933. }
  1934. /**
  1935. * Notify external application (if API is enabled) the conference
  1936. * start time.
  1937. *
  1938. * @param {number} timestamp - Timestamp conference was created.
  1939. * @returns {void}
  1940. */
  1941. notifyConferenceCreatedTimestamp(timestamp) {
  1942. this._sendEvent({
  1943. name: 'conference-created-timestamp',
  1944. timestamp
  1945. });
  1946. }
  1947. /**
  1948. * Notify the external application (if API is enabled) if the connection type changed.
  1949. *
  1950. * @param {boolean} isP2p - Whether the new connection is P2P.
  1951. * @returns {void}
  1952. */
  1953. notifyP2pStatusChanged(isP2p) {
  1954. this._sendEvent({
  1955. name: 'p2p-status-changed',
  1956. isP2p
  1957. });
  1958. }
  1959. /**
  1960. * Notify the external application (if API is enabled) when the compute pressure changed.
  1961. *
  1962. * @param {Array} records - The new pressure records.
  1963. * @returns {void}
  1964. */
  1965. notifyComputePressureChanged(records) {
  1966. this._sendEvent({
  1967. name: 'compute-pressure-changed',
  1968. records
  1969. });
  1970. }
  1971. /**
  1972. * Disposes the allocated resources.
  1973. *
  1974. * @returns {void}
  1975. */
  1976. dispose() {
  1977. if (this._enabled) {
  1978. this._enabled = false;
  1979. }
  1980. }
  1981. }
  1982. export default new API();