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

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