Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. import i18n from 'i18next';
  2. import { batch } from 'react-redux';
  3. // @ts-expect-error
  4. import { API_ID } from '../../../modules/API/constants';
  5. import { appNavigate } from '../app/actions';
  6. import { redirectToStaticPage } from '../app/actions.any';
  7. import { IReduxState, IStore } from '../app/types';
  8. import {
  9. CONFERENCE_FAILED,
  10. CONFERENCE_JOINED,
  11. CONFERENCE_LEFT
  12. } from '../base/conference/actionTypes';
  13. import { getCurrentConference } from '../base/conference/functions';
  14. import { getURLWithoutParamsNormalized } from '../base/connection/utils';
  15. import { hideDialog } from '../base/dialog/actions';
  16. import { isDialogOpen } from '../base/dialog/functions';
  17. import { getLocalizedDateFormatter } from '../base/i18n/dateUtil';
  18. import { translateToHTML } from '../base/i18n/functions';
  19. import i18next from '../base/i18n/i18next';
  20. import { browser } from '../base/lib-jitsi-meet';
  21. import { pinParticipant, raiseHandClear } from '../base/participants/actions';
  22. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  23. import StateListenerRegistry from '../base/redux/StateListenerRegistry';
  24. import { SET_REDUCED_UI } from '../base/responsive-ui/actionTypes';
  25. import { BUTTON_TYPES } from '../base/ui/constants.any';
  26. import { inIframe } from '../base/util/iframeUtils';
  27. import { isCalendarEnabled } from '../calendar-sync/functions';
  28. import FeedbackDialog from '../feedback/components/FeedbackDialog';
  29. import { setFilmstripEnabled } from '../filmstrip/actions.any';
  30. import { isVpaasMeeting } from '../jaas/functions';
  31. import { hideNotification, showNotification, showWarningNotification } from '../notifications/actions';
  32. import {
  33. CALENDAR_NOTIFICATION_ID,
  34. NOTIFICATION_ICON,
  35. NOTIFICATION_TIMEOUT_TYPE
  36. } from '../notifications/constants';
  37. import { showSalesforceNotification } from '../salesforce/actions';
  38. import { setToolboxEnabled } from '../toolbox/actions.any';
  39. import { DISMISS_CALENDAR_NOTIFICATION } from './actionTypes';
  40. import { dismissCalendarNotification } from './actions';
  41. import { IFRAME_DISABLED_TIMEOUT_MINUTES, IFRAME_EMBED_ALLOWED_LOCATIONS } from './constants';
  42. let intervalID: any;
  43. MiddlewareRegistry.register(store => next => action => {
  44. const result = next(action);
  45. switch (action.type) {
  46. case CONFERENCE_JOINED: {
  47. _conferenceJoined(store);
  48. break;
  49. }
  50. case SET_REDUCED_UI: {
  51. _setReducedUI(store);
  52. break;
  53. }
  54. case DISMISS_CALENDAR_NOTIFICATION:
  55. case CONFERENCE_LEFT:
  56. case CONFERENCE_FAILED: {
  57. clearInterval(intervalID);
  58. intervalID = null;
  59. break;
  60. }
  61. }
  62. return result;
  63. });
  64. /**
  65. * Set up state change listener to perform maintenance tasks when the conference
  66. * is left or failed, close all dialogs and unpin any pinned participants.
  67. */
  68. StateListenerRegistry.register(
  69. state => getCurrentConference(state),
  70. (conference, { dispatch, getState }, prevConference) => {
  71. const { authRequired, membersOnly, passwordRequired }
  72. = getState()['features/base/conference'];
  73. if (conference !== prevConference) {
  74. // Unpin participant, in order to avoid the local participant
  75. // remaining pinned, since it's not destroyed across runs.
  76. dispatch(pinParticipant(null));
  77. // Clear raised hands.
  78. dispatch(raiseHandClear());
  79. // XXX I wonder if there is a better way to do this. At this stage
  80. // we do know what dialogs we want to keep but the list of those
  81. // we want to hide is a lot longer. Thus we take a bit of a shortcut
  82. // and explicitly check.
  83. if (typeof authRequired === 'undefined'
  84. && typeof passwordRequired === 'undefined'
  85. && typeof membersOnly === 'undefined'
  86. && !isDialogOpen(getState(), FeedbackDialog)) {
  87. // Conference changed, left or failed... and there is no
  88. // pending authentication, nor feedback request, so close any
  89. // dialog we might have open.
  90. dispatch(hideDialog());
  91. }
  92. }
  93. });
  94. /**
  95. * Configures the UI. In reduced UI mode some components will
  96. * be hidden if there is no space to render them.
  97. *
  98. * @param {Store} store - The redux store in which the specified {@code action}
  99. * is being dispatched.
  100. * @private
  101. * @returns {void}
  102. */
  103. function _setReducedUI({ dispatch, getState }: IStore) {
  104. const { reducedUI } = getState()['features/base/responsive-ui'];
  105. dispatch(setToolboxEnabled(!reducedUI));
  106. dispatch(setFilmstripEnabled(!reducedUI));
  107. }
  108. /**
  109. * Does extra sync up on properties that may need to be updated after the
  110. * conference was joined.
  111. *
  112. * @param {Store} store - The redux store in which the specified {@code action}
  113. * is being dispatched.
  114. * @private
  115. * @returns {void}
  116. */
  117. function _conferenceJoined({ dispatch, getState }: IStore) {
  118. _setReducedUI({
  119. dispatch,
  120. getState
  121. });
  122. if (!intervalID) {
  123. intervalID = setInterval(() =>
  124. _maybeDisplayCalendarNotification({
  125. dispatch,
  126. getState
  127. }), 10 * 1000);
  128. }
  129. dispatch(showSalesforceNotification());
  130. _checkIframe(getState(), dispatch);
  131. }
  132. /**
  133. * Additional checks for embedding in iframe.
  134. *
  135. * @param {IReduxState} state - The current state of the app.
  136. * @param {Function} dispatch - The Redux dispatch function.
  137. * @private
  138. * @returns {void}
  139. */
  140. function _checkIframe(state: IReduxState, dispatch: IStore['dispatch']) {
  141. let allowIframe = false;
  142. if (document.referrer === '' && browser.isElectron()) {
  143. // no iframe
  144. allowIframe = true;
  145. } else {
  146. try {
  147. allowIframe = IFRAME_EMBED_ALLOWED_LOCATIONS.includes(new URL(document.referrer).hostname);
  148. } catch (e) {
  149. // wrong URL in referrer
  150. }
  151. }
  152. if (inIframe() && state['features/base/config'].disableIframeAPI && !browser.isElectron()
  153. && !isVpaasMeeting(state) && !allowIframe) {
  154. // show sticky notification and redirect in 5 minutes
  155. const { locationURL } = state['features/base/connection'];
  156. let translationKey = 'notify.disabledIframe';
  157. const hostname = locationURL?.hostname ?? '';
  158. let domain = '';
  159. const mapping: Record<string, string> = {
  160. '8x8.vc': 'https://jaas.8x8.vc',
  161. 'meet.jit.si': 'https://jitsi.org/jaas'
  162. };
  163. const jaasDomain = mapping[hostname];
  164. if (jaasDomain) {
  165. translationKey = 'notify.disabledIframeSecondary';
  166. domain = hostname;
  167. }
  168. dispatch(showWarningNotification({
  169. description: translateToHTML(
  170. i18next.t.bind(i18next),
  171. translationKey,
  172. {
  173. domain,
  174. jaasDomain,
  175. timeout: IFRAME_DISABLED_TIMEOUT_MINUTES
  176. }
  177. )
  178. }, NOTIFICATION_TIMEOUT_TYPE.STICKY));
  179. setTimeout(() => {
  180. // redirect to the promotional page
  181. dispatch(redirectToStaticPage('static/close3.html', `#jitsi_meet_external_api_id=${API_ID}`));
  182. }, IFRAME_DISABLED_TIMEOUT_MINUTES * 60 * 1000);
  183. }
  184. }
  185. /**
  186. * Periodically checks if there is an event in the calendar for which we
  187. * need to show a notification.
  188. *
  189. * @param {Store} store - The redux store in which the specified {@code action}
  190. * is being dispatched.
  191. * @private
  192. * @returns {void}
  193. */
  194. function _maybeDisplayCalendarNotification({ dispatch, getState }: IStore) {
  195. const state = getState();
  196. const calendarEnabled = isCalendarEnabled(state);
  197. const { events: eventList } = state['features/calendar-sync'];
  198. const { locationURL } = state['features/base/connection'];
  199. const { reducedUI } = state['features/base/responsive-ui'];
  200. const currentConferenceURL
  201. = locationURL ? getURLWithoutParamsNormalized(locationURL) : '';
  202. const ALERT_MILLISECONDS = 5 * 60 * 1000;
  203. const now = Date.now();
  204. let eventToShow;
  205. if (!calendarEnabled && reducedUI) {
  206. return;
  207. }
  208. if (eventList?.length) {
  209. for (const event of eventList) {
  210. const eventURL
  211. = event?.url && getURLWithoutParamsNormalized(new URL(event.url));
  212. if (eventURL && eventURL !== currentConferenceURL) {
  213. // @ts-ignore
  214. if ((!eventToShow && event.startDate > now && event.startDate < now + ALERT_MILLISECONDS)
  215. // @ts-ignore
  216. || (event.startDate < now && event.endDate > now)) {
  217. eventToShow = event;
  218. }
  219. }
  220. }
  221. }
  222. _calendarNotification(
  223. {
  224. dispatch,
  225. getState
  226. }, eventToShow
  227. );
  228. }
  229. /**
  230. * Calendar notification.
  231. *
  232. * @param {Store} store - The redux store in which the specified {@code action}
  233. * is being dispatched.
  234. * @param {eventToShow} eventToShow - Next or ongoing event.
  235. * @private
  236. * @returns {void}
  237. */
  238. function _calendarNotification({ dispatch, getState }: IStore, eventToShow: any) {
  239. const state = getState();
  240. const { locationURL } = state['features/base/connection'];
  241. const currentConferenceURL
  242. = locationURL ? getURLWithoutParamsNormalized(locationURL) : '';
  243. const now = Date.now();
  244. if (!eventToShow) {
  245. return;
  246. }
  247. const customActionNameKey = [ 'notify.joinMeeting', 'notify.dontRemindMe' ];
  248. const customActionType = [ BUTTON_TYPES.PRIMARY, BUTTON_TYPES.DESTRUCTIVE ];
  249. const customActionHandler = [ () => batch(() => {
  250. dispatch(hideNotification(CALENDAR_NOTIFICATION_ID));
  251. if (eventToShow?.url && (eventToShow.url !== currentConferenceURL)) {
  252. dispatch(appNavigate(eventToShow.url));
  253. }
  254. }), () => dispatch(dismissCalendarNotification()) ];
  255. const description
  256. = getLocalizedDateFormatter(eventToShow.startDate).fromNow();
  257. const icon = NOTIFICATION_ICON.WARNING;
  258. const title = (eventToShow.startDate < now) && (eventToShow.endDate > now)
  259. ? `${i18n.t('calendarSync.ongoingMeeting')}: \n${eventToShow.title}`
  260. : `${i18n.t('calendarSync.nextMeeting')}: \n${eventToShow.title}`;
  261. const uid = CALENDAR_NOTIFICATION_ID;
  262. dispatch(showNotification({
  263. customActionHandler,
  264. customActionNameKey,
  265. customActionType,
  266. description,
  267. icon,
  268. title,
  269. uid
  270. }, NOTIFICATION_TIMEOUT_TYPE.STICKY));
  271. }