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 56KB

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