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

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