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

API.js 52KB

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