Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

API.js 41KB

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