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.

MessageHandler.js 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* global APP */
  2. import { showErrorNotification, showWarningNotification } from '../../../react/features/notifications/actions';
  3. import { NOTIFICATION_TIMEOUT_TYPE } from '../../../react/features/notifications/constants';
  4. const messageHandler = {
  5. /**
  6. * Opens new popup window for given <tt>url</tt> centered over current
  7. * window.
  8. *
  9. * @param url the URL to be displayed in the popup window
  10. * @param w the width of the popup window
  11. * @param h the height of the popup window
  12. * @param onPopupClosed optional callback function called when popup window
  13. * has been closed.
  14. *
  15. * @returns {object} popup window object if opened successfully or undefined
  16. * in case we failed to open it(popup blocked)
  17. */
  18. // eslint-disable-next-line max-params
  19. openCenteredPopup(url, w, h, onPopupClosed) {
  20. const l = window.screenX + (window.innerWidth / 2) - (w / 2);
  21. const t = window.screenY + (window.innerHeight / 2) - (h / 2);
  22. const popup = window.open(
  23. url, '_blank',
  24. String(`top=${t}, left=${l}, width=${w}, height=${h}`));
  25. if (popup && onPopupClosed) {
  26. const pollTimer = window.setInterval(() => {
  27. if (popup.closed !== false) {
  28. window.clearInterval(pollTimer);
  29. onPopupClosed();
  30. }
  31. }, 200);
  32. }
  33. return popup;
  34. },
  35. /**
  36. * Shows an error dialog to the user.
  37. *
  38. * @param {object} props - The properties to pass to the
  39. * showErrorNotification action.
  40. */
  41. showError(props) {
  42. APP.store.dispatch(showErrorNotification(props, NOTIFICATION_TIMEOUT_TYPE.LONG));
  43. },
  44. /**
  45. * Shows a warning dialog to the user.
  46. *
  47. * @param {object} props - The properties to pass to the
  48. * showWarningNotification action.
  49. */
  50. showWarning(props) {
  51. APP.store.dispatch(showWarningNotification(props, NOTIFICATION_TIMEOUT_TYPE.LONG));
  52. }
  53. };
  54. export default messageHandler;