選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

API.js 76KB

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