Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

API.js 63KB

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