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.any.js 11KB

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