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

actions.any.js 10KB

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