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.

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