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.

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