Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

actions.any.js 9.1KB

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