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

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