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

actions.any.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. // @flow
  2. import { getMeetingRegion, getRecordingSharingUrl } from '../base/config';
  3. import JitsiMeetJS, { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
  4. import { getLocalParticipant, getParticipantDisplayName } from '../base/participants';
  5. import { copyText } from '../base/util/helpers';
  6. import { getVpaasTenant, isVpaasMeeting } from '../jaas/functions';
  7. import {
  8. NOTIFICATION_TIMEOUT,
  9. hideNotification,
  10. showErrorNotification,
  11. showNotification
  12. } from '../notifications';
  13. import {
  14. CLEAR_RECORDING_SESSIONS,
  15. RECORDING_SESSION_UPDATED,
  16. SET_PENDING_RECORDING_NOTIFICATION_UID,
  17. SET_SELECTED_RECORDING_SERVICE,
  18. SET_STREAM_KEY
  19. } from './actionTypes';
  20. import { getRecordingLink, getResourceId, isSavingRecordingOnDropbox } from './functions';
  21. import logger from './logger';
  22. /**
  23. * Clears the data of every recording sessions.
  24. *
  25. * @returns {{
  26. * type: CLEAR_RECORDING_SESSIONS
  27. * }}
  28. */
  29. export function clearRecordingSessions() {
  30. return {
  31. type: CLEAR_RECORDING_SESSIONS
  32. };
  33. }
  34. /**
  35. * Signals that the pending recording notification should be removed from the
  36. * screen.
  37. *
  38. * @param {string} streamType - The type of the stream ({@code 'file'} or
  39. * {@code 'stream'}).
  40. * @returns {Function}
  41. */
  42. export function hidePendingRecordingNotification(streamType: string) {
  43. return (dispatch: Function, getState: Function) => {
  44. const { pendingNotificationUids } = getState()['features/recording'];
  45. const pendingNotificationUid = pendingNotificationUids[streamType];
  46. if (pendingNotificationUid) {
  47. dispatch(hideNotification(pendingNotificationUid));
  48. dispatch(
  49. _setPendingRecordingNotificationUid(
  50. undefined, streamType));
  51. }
  52. };
  53. }
  54. /**
  55. * Sets the stream key last used by the user for later reuse.
  56. *
  57. * @param {string} streamKey - The stream key to set.
  58. * @returns {{
  59. * type: SET_STREAM_KEY,
  60. * streamKey: string
  61. * }}
  62. */
  63. export function setLiveStreamKey(streamKey: string) {
  64. return {
  65. type: SET_STREAM_KEY,
  66. streamKey
  67. };
  68. }
  69. /**
  70. * Signals that the pending recording notification should be shown on the
  71. * screen.
  72. *
  73. * @param {string} streamType - The type of the stream ({@code file} or
  74. * {@code stream}).
  75. * @returns {Function}
  76. */
  77. export function showPendingRecordingNotification(streamType: string) {
  78. return async (dispatch: Function) => {
  79. const isLiveStreaming
  80. = streamType === JitsiMeetJS.constants.recording.mode.STREAM;
  81. const dialogProps = isLiveStreaming ? {
  82. descriptionKey: 'liveStreaming.pending',
  83. titleKey: 'dialog.liveStreaming'
  84. } : {
  85. descriptionKey: 'recording.pending',
  86. titleKey: 'dialog.recording'
  87. };
  88. const notification = await dispatch(showNotification({
  89. isDismissAllowed: false,
  90. ...dialogProps
  91. }));
  92. if (notification) {
  93. dispatch(_setPendingRecordingNotificationUid(notification.uid, streamType));
  94. }
  95. };
  96. }
  97. /**
  98. * Signals that the recording error notification should be shown.
  99. *
  100. * @param {Object} props - The Props needed to render the notification.
  101. * @returns {showErrorNotification}
  102. */
  103. export function showRecordingError(props: Object) {
  104. return showErrorNotification(props);
  105. }
  106. /**
  107. * Signals that the stopped recording notification should be shown on the
  108. * screen for a given period.
  109. *
  110. * @param {string} streamType - The type of the stream ({@code file} or
  111. * {@code stream}).
  112. * @param {string?} participantName - The participant name stopping the recording.
  113. * @returns {showNotification}
  114. */
  115. export function showStoppedRecordingNotification(streamType: string, participantName?: string) {
  116. const isLiveStreaming
  117. = streamType === JitsiMeetJS.constants.recording.mode.STREAM;
  118. const descriptionArguments = { name: participantName };
  119. const dialogProps = isLiveStreaming ? {
  120. descriptionKey: participantName ? 'liveStreaming.offBy' : 'liveStreaming.off',
  121. descriptionArguments,
  122. titleKey: 'dialog.liveStreaming'
  123. } : {
  124. descriptionKey: participantName ? 'recording.offBy' : 'recording.off',
  125. descriptionArguments,
  126. titleKey: 'dialog.recording'
  127. };
  128. return showNotification(dialogProps, NOTIFICATION_TIMEOUT);
  129. }
  130. /**
  131. * Signals that a started recording notification should be shown on the
  132. * screen for a given period.
  133. *
  134. * @param {string} mode - The type of the recording: Stream of File.
  135. * @param {string | Object } initiator - The participant who started recording.
  136. * @param {string} sessionId - The recording session id.
  137. * @returns {Function}
  138. */
  139. export function showStartedRecordingNotification(
  140. mode: string,
  141. initiator: Object | string,
  142. sessionId: string) {
  143. return async (dispatch: Function, getState: Function) => {
  144. const state = getState();
  145. const initiatorId = getResourceId(initiator);
  146. const participantName = getParticipantDisplayName(state, initiatorId);
  147. let dialogProps = {
  148. customActionNameKey: undefined,
  149. descriptionKey: participantName ? 'liveStreaming.onBy' : 'liveStreaming.on',
  150. descriptionArguments: { name: participantName },
  151. isDismissAllowed: true,
  152. titleKey: 'dialog.liveStreaming'
  153. };
  154. if (mode !== JitsiMeetJS.constants.recording.mode.STREAM) {
  155. const recordingSharingUrl = getRecordingSharingUrl(state);
  156. const iAmRecordingInitiator = getLocalParticipant(state).id === initiatorId;
  157. dialogProps = {
  158. customActionHandler: undefined,
  159. customActionNameKey: undefined,
  160. descriptionKey: participantName ? 'recording.onBy' : 'recording.on',
  161. descriptionArguments: { name: participantName },
  162. isDismissAllowed: true,
  163. titleKey: 'dialog.recording'
  164. };
  165. // fetch the recording link from the server for recording initiators in jaas meetings
  166. if (recordingSharingUrl
  167. && isVpaasMeeting(state)
  168. && iAmRecordingInitiator
  169. && !isSavingRecordingOnDropbox(state)) {
  170. const region = getMeetingRegion(state);
  171. const tenant = getVpaasTenant(state);
  172. try {
  173. const link = await getRecordingLink(recordingSharingUrl, sessionId, region, tenant);
  174. // add the option to copy recording link
  175. dialogProps.customActionNameKey = 'recording.copyLink';
  176. dialogProps.customActionHandler = () => copyText(link);
  177. dialogProps.titleKey = 'recording.on';
  178. dialogProps.descriptionKey = 'recording.linkGenerated';
  179. dialogProps.isDismissAllowed = false;
  180. } catch (err) {
  181. dispatch(showErrorNotification({
  182. titleKey: 'recording.errorFetchingLink'
  183. }));
  184. return logger.error('Could not fetch recording link', err);
  185. }
  186. }
  187. }
  188. dispatch(showNotification(dialogProps, NOTIFICATION_TIMEOUT));
  189. };
  190. }
  191. /**
  192. * Updates the known state for a given recording session.
  193. *
  194. * @param {Object} session - The new state to merge with the existing state in
  195. * redux.
  196. * @returns {{
  197. * type: RECORDING_SESSION_UPDATED,
  198. * sessionData: Object
  199. * }}
  200. */
  201. export function updateRecordingSessionData(session: Object) {
  202. const status = session.getStatus();
  203. const timestamp
  204. = status === JitsiRecordingConstants.status.ON
  205. ? Date.now() / 1000
  206. : undefined;
  207. return {
  208. type: RECORDING_SESSION_UPDATED,
  209. sessionData: {
  210. error: session.getError(),
  211. id: session.getID(),
  212. initiator: session.getInitiator(),
  213. liveStreamViewURL: session.getLiveStreamViewURL(),
  214. mode: session.getMode(),
  215. status,
  216. terminator: session.getTerminator(),
  217. timestamp
  218. }
  219. };
  220. }
  221. /**
  222. * Sets the selected recording service.
  223. *
  224. * @param {string} selectedRecordingService - The new selected recording service.
  225. * @returns {Object}
  226. */
  227. export function setSelectedRecordingService(selectedRecordingService: string) {
  228. return {
  229. type: SET_SELECTED_RECORDING_SERVICE,
  230. selectedRecordingService
  231. };
  232. }
  233. /**
  234. * Sets UID of the the pending streaming notification to use it when hinding
  235. * the notification is necessary, or unsets it when undefined (or no param) is
  236. * passed.
  237. *
  238. * @param {?number} uid - The UID of the notification.
  239. * @param {string} streamType - The type of the stream ({@code file} or
  240. * {@code stream}).
  241. * @returns {{
  242. * type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  243. * streamType: string,
  244. * uid: number
  245. * }}
  246. */
  247. function _setPendingRecordingNotificationUid(uid: ?number, streamType: string) {
  248. return {
  249. type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  250. streamType,
  251. uid
  252. };
  253. }