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 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // @flow
  2. import JitsiMeetJS, { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
  3. import {
  4. NOTIFICATION_TIMEOUT,
  5. hideNotification,
  6. showErrorNotification,
  7. showNotification
  8. } from '../notifications';
  9. import {
  10. CLEAR_RECORDING_SESSIONS,
  11. RECORDING_SESSION_UPDATED,
  12. SET_PENDING_RECORDING_NOTIFICATION_UID,
  13. SET_STREAM_KEY
  14. } from './actionTypes';
  15. /**
  16. * Clears the data of every recording sessions.
  17. *
  18. * @returns {{
  19. * type: CLEAR_RECORDING_SESSIONS
  20. * }}
  21. */
  22. export function clearRecordingSessions() {
  23. return {
  24. type: CLEAR_RECORDING_SESSIONS
  25. };
  26. }
  27. /**
  28. * Signals that the pending recording notification should be removed from the
  29. * screen.
  30. *
  31. * @param {string} streamType - The type of the stream ({@code 'file'} or
  32. * {@code 'stream'}).
  33. * @returns {Function}
  34. */
  35. export function hidePendingRecordingNotification(streamType: string) {
  36. return (dispatch: Function, getState: Function) => {
  37. const { pendingNotificationUids } = getState()['features/recording'];
  38. const pendingNotificationUid = pendingNotificationUids[streamType];
  39. if (pendingNotificationUid) {
  40. dispatch(hideNotification(pendingNotificationUid));
  41. dispatch(
  42. _setPendingRecordingNotificationUid(
  43. undefined, streamType));
  44. }
  45. };
  46. }
  47. /**
  48. * Sets the stream key last used by the user for later reuse.
  49. *
  50. * @param {string} streamKey - The stream key to set.
  51. * @returns {{
  52. * type: SET_STREAM_KEY,
  53. * streamKey: string
  54. * }}
  55. */
  56. export function setLiveStreamKey(streamKey: string) {
  57. return {
  58. type: SET_STREAM_KEY,
  59. streamKey
  60. };
  61. }
  62. /**
  63. * Signals that the pending recording notification should be shown on the
  64. * screen.
  65. *
  66. * @param {string} streamType - The type of the stream ({@code file} or
  67. * {@code stream}).
  68. * @returns {Function}
  69. */
  70. export function showPendingRecordingNotification(streamType: string) {
  71. return (dispatch: Function) => {
  72. const isLiveStreaming
  73. = streamType === JitsiMeetJS.constants.recording.mode.STREAM;
  74. const dialogProps = isLiveStreaming ? {
  75. descriptionKey: 'liveStreaming.pending',
  76. titleKey: 'dialog.liveStreaming'
  77. } : {
  78. descriptionKey: 'recording.pending',
  79. titleKey: 'dialog.recording'
  80. };
  81. const showNotificationAction = showNotification({
  82. isDismissAllowed: false,
  83. ...dialogProps
  84. });
  85. dispatch(showNotificationAction);
  86. dispatch(_setPendingRecordingNotificationUid(
  87. showNotificationAction.uid, streamType));
  88. };
  89. }
  90. /**
  91. * Signals that the recording error notification should be shown.
  92. *
  93. * @param {Object} props - The Props needed to render the notification.
  94. * @returns {showErrorNotification}
  95. */
  96. export function showRecordingError(props: Object) {
  97. return showErrorNotification(props);
  98. }
  99. /**
  100. * Signals that the stopped recording notification should be shown on the
  101. * screen for a given period.
  102. *
  103. * @param {string} streamType - The type of the stream ({@code file} or
  104. * {@code stream}).
  105. * @returns {showNotification}
  106. */
  107. export function showStoppedRecordingNotification(streamType: string) {
  108. const isLiveStreaming
  109. = streamType === JitsiMeetJS.constants.recording.mode.STREAM;
  110. const dialogProps = isLiveStreaming ? {
  111. descriptionKey: 'liveStreaming.off',
  112. titleKey: 'dialog.liveStreaming'
  113. } : {
  114. descriptionKey: 'recording.off',
  115. titleKey: 'dialog.recording'
  116. };
  117. return showNotification(dialogProps, NOTIFICATION_TIMEOUT);
  118. }
  119. /**
  120. * Updates the known state for a given recording session.
  121. *
  122. * @param {Object} session - The new state to merge with the existing state in
  123. * redux.
  124. * @returns {{
  125. * type: RECORDING_SESSION_UPDATED,
  126. * sessionData: Object
  127. * }}
  128. */
  129. export function updateRecordingSessionData(session: Object) {
  130. const status = session.getStatus();
  131. const timestamp
  132. = status === JitsiRecordingConstants.status.ON
  133. ? Date.now() / 1000
  134. : undefined;
  135. return {
  136. type: RECORDING_SESSION_UPDATED,
  137. sessionData: {
  138. error: session.getError(),
  139. id: session.getID(),
  140. liveStreamViewURL: session.getLiveStreamViewURL(),
  141. mode: session.getMode(),
  142. status,
  143. timestamp
  144. }
  145. };
  146. }
  147. /**
  148. * Sets UID of the the pending streaming notification to use it when hinding
  149. * the notification is necessary, or unsets it when undefined (or no param) is
  150. * passed.
  151. *
  152. * @param {?number} uid - The UID of the notification.
  153. * @param {string} streamType - The type of the stream ({@code file} or
  154. * {@code stream}).
  155. * @returns {{
  156. * type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  157. * streamType: string,
  158. * uid: number
  159. * }}
  160. */
  161. function _setPendingRecordingNotificationUid(uid: ?number, streamType: string) {
  162. return {
  163. type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  164. streamType,
  165. uid
  166. };
  167. }