您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

actions.any.js 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. * @param {string?} participantName - The participant name stopping the recording.
  106. * @returns {showNotification}
  107. */
  108. export function showStoppedRecordingNotification(streamType: string, participantName?: string) {
  109. const isLiveStreaming
  110. = streamType === JitsiMeetJS.constants.recording.mode.STREAM;
  111. const descriptionArguments = { name: participantName };
  112. const dialogProps = isLiveStreaming ? {
  113. descriptionKey: participantName ? 'liveStreaming.offBy' : 'liveStreaming.off',
  114. descriptionArguments,
  115. titleKey: 'dialog.liveStreaming'
  116. } : {
  117. descriptionKey: participantName ? 'recording.offBy' : 'recording.off',
  118. descriptionArguments,
  119. titleKey: 'dialog.recording'
  120. };
  121. return showNotification(dialogProps, NOTIFICATION_TIMEOUT);
  122. }
  123. /**
  124. * Signals that a started recording notification should be shown on the
  125. * screen for a given period.
  126. *
  127. * @param {string} streamType - The type of the stream ({@code file} or
  128. * {@code stream}).
  129. * @param {string} participantName - The participant name that started the recording.
  130. * @returns {showNotification}
  131. */
  132. export function showStartedRecordingNotification(streamType: string, participantName: string) {
  133. const isLiveStreaming
  134. = streamType === JitsiMeetJS.constants.recording.mode.STREAM;
  135. const descriptionArguments = { name: participantName };
  136. const dialogProps = isLiveStreaming ? {
  137. descriptionKey: participantName ? 'liveStreaming.onBy' : 'liveStreaming.on',
  138. descriptionArguments,
  139. titleKey: 'dialog.liveStreaming'
  140. } : {
  141. descriptionKey: participantName ? 'recording.onBy' : 'recording.on',
  142. descriptionArguments,
  143. titleKey: 'dialog.recording'
  144. };
  145. return showNotification(dialogProps, NOTIFICATION_TIMEOUT);
  146. }
  147. /**
  148. * Updates the known state for a given recording session.
  149. *
  150. * @param {Object} session - The new state to merge with the existing state in
  151. * redux.
  152. * @returns {{
  153. * type: RECORDING_SESSION_UPDATED,
  154. * sessionData: Object
  155. * }}
  156. */
  157. export function updateRecordingSessionData(session: Object) {
  158. const status = session.getStatus();
  159. const timestamp
  160. = status === JitsiRecordingConstants.status.ON
  161. ? Date.now() / 1000
  162. : undefined;
  163. return {
  164. type: RECORDING_SESSION_UPDATED,
  165. sessionData: {
  166. error: session.getError(),
  167. id: session.getID(),
  168. initiator: session.getInitiator(),
  169. liveStreamViewURL: session.getLiveStreamViewURL(),
  170. mode: session.getMode(),
  171. status,
  172. terminator: session.getTerminator(),
  173. timestamp
  174. }
  175. };
  176. }
  177. /**
  178. * Sets UID of the the pending streaming notification to use it when hinding
  179. * the notification is necessary, or unsets it when undefined (or no param) is
  180. * passed.
  181. *
  182. * @param {?number} uid - The UID of the notification.
  183. * @param {string} streamType - The type of the stream ({@code file} or
  184. * {@code stream}).
  185. * @returns {{
  186. * type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  187. * streamType: string,
  188. * uid: number
  189. * }}
  190. */
  191. function _setPendingRecordingNotificationUid(uid: ?number, streamType: string) {
  192. return {
  193. type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  194. streamType,
  195. uid
  196. };
  197. }