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.

actions.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // @flow
  2. import {
  3. hideNotification,
  4. showErrorNotification,
  5. showNotification
  6. } from '../notifications';
  7. import {
  8. CLEAR_RECORDING_SESSIONS,
  9. RECORDING_SESSION_UPDATED,
  10. SET_PENDING_RECORDING_NOTIFICATION_UID
  11. } from './actionTypes';
  12. /**
  13. * Clears the data of every recording sessions.
  14. *
  15. * @returns {{
  16. * type: CLEAR_RECORDING_SESSIONS
  17. * }}
  18. */
  19. export function clearRecordingSessions() {
  20. return {
  21. type: CLEAR_RECORDING_SESSIONS
  22. };
  23. }
  24. /**
  25. * Signals that the pending recording notification should be removed from the
  26. * screen.
  27. *
  28. * @returns {Function}
  29. */
  30. export function hidePendingRecordingNotification() {
  31. return (dispatch: Function, getState: Function) => {
  32. const { pendingNotificationUid } = getState()['features/recording'];
  33. if (pendingNotificationUid) {
  34. dispatch(hideNotification(pendingNotificationUid));
  35. dispatch(setPendingRecordingNotificationUid());
  36. }
  37. };
  38. }
  39. /**
  40. * Sets UID of the the pending recording notification to use it when hinding
  41. * the notification is necessary, or unsets it when
  42. * undefined (or no param) is passed.
  43. *
  44. * @param {?number} uid - The UID of the notification.
  45. * redux.
  46. * @returns {{
  47. * type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  48. * uid: number
  49. * }}
  50. */
  51. export function setPendingRecordingNotificationUid(uid: ?number) {
  52. return {
  53. type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  54. uid
  55. };
  56. }
  57. /**
  58. * Signals that the pending recording notification should be shown on the
  59. * screen.
  60. *
  61. * @returns {Function}
  62. */
  63. export function showPendingRecordingNotification() {
  64. return (dispatch: Function) => {
  65. const showNotificationAction = showNotification({
  66. descriptionKey: 'recording.pending',
  67. isDismissAllowed: false,
  68. titleKey: 'dialog.recording'
  69. });
  70. dispatch(showNotificationAction);
  71. dispatch(setPendingRecordingNotificationUid(
  72. showNotificationAction.uid));
  73. };
  74. }
  75. /**
  76. * Signals that the recording error notification should be shown.
  77. *
  78. * @param {Object} props - The Props needed to render the notification.
  79. * @returns {showErrorNotification}
  80. */
  81. export function showRecordingError(props: Object) {
  82. return showErrorNotification(props);
  83. }
  84. /**
  85. * Signals that the stopped recording notification should be shown on the
  86. * screen for a given period.
  87. *
  88. * @returns {showNotification}
  89. */
  90. export function showStoppedRecordingNotification() {
  91. return showNotification({
  92. descriptionKey: 'recording.off',
  93. titleKey: 'dialog.recording'
  94. }, 2500);
  95. }
  96. /**
  97. * Updates the known state for a given recording session.
  98. *
  99. * @param {Object} session - The new state to merge with the existing state in
  100. * redux.
  101. * @returns {{
  102. * type: RECORDING_SESSION_UPDATED,
  103. * sessionData: Object
  104. * }}
  105. */
  106. export function updateRecordingSessionData(session: Object) {
  107. return {
  108. type: RECORDING_SESSION_UPDATED,
  109. sessionData: {
  110. error: session.getError(),
  111. id: session.getID(),
  112. liveStreamViewURL: session.getLiveStreamViewURL(),
  113. mode: session.getMode(),
  114. status: session.getStatus()
  115. }
  116. };
  117. }