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

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