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

API.js 73KB

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