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.ts 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. import { IStore } from '../app/types';
  2. import { getMeetingRegion, getRecordingSharingUrl } from '../base/config/functions';
  3. import JitsiMeetJS, { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
  4. import { getLocalParticipant, getParticipantDisplayName } from '../base/participants/functions';
  5. import { copyText } from '../base/util/copyText';
  6. import { getVpaasTenant, isVpaasMeeting } from '../jaas/functions';
  7. import {
  8. hideNotification,
  9. showErrorNotification,
  10. showNotification,
  11. showWarningNotification
  12. } from '../notifications/actions';
  13. import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
  14. import { INotificationProps } from '../notifications/types';
  15. import {
  16. CLEAR_RECORDING_SESSIONS,
  17. RECORDING_SESSION_UPDATED,
  18. SET_MEETING_HIGHLIGHT_BUTTON_STATE,
  19. SET_PENDING_RECORDING_NOTIFICATION_UID,
  20. SET_SELECTED_RECORDING_SERVICE,
  21. SET_STREAM_KEY,
  22. START_LOCAL_RECORDING,
  23. STOP_LOCAL_RECORDING
  24. } from './actionTypes';
  25. import {
  26. getRecordingLink,
  27. getResourceId,
  28. isSavingRecordingOnDropbox,
  29. sendMeetingHighlight
  30. } from './functions';
  31. import logger from './logger';
  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: IStore['dispatch'], getState: IStore['getState']) => {
  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: IStore['dispatch']) => {
  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: { getId: Function; } | 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. const notifyProps: {
  200. dialogProps: INotificationProps;
  201. type: string;
  202. } = {
  203. dialogProps: {
  204. descriptionKey: participantName ? 'liveStreaming.onBy' : 'liveStreaming.on',
  205. descriptionArguments: { name: participantName },
  206. titleKey: 'dialog.liveStreaming'
  207. },
  208. type: NOTIFICATION_TIMEOUT_TYPE.SHORT
  209. };
  210. if (mode !== JitsiMeetJS.constants.recording.mode.STREAM) {
  211. const recordingSharingUrl = getRecordingSharingUrl(state);
  212. const iAmRecordingInitiator = getLocalParticipant(state)?.id === initiatorId;
  213. notifyProps.dialogProps = {
  214. customActionHandler: undefined,
  215. customActionNameKey: undefined,
  216. descriptionKey: participantName ? 'recording.onBy' : 'recording.on',
  217. descriptionArguments: { name: participantName },
  218. titleKey: 'dialog.recording'
  219. };
  220. // fetch the recording link from the server for recording initiators in jaas meetings
  221. if (recordingSharingUrl
  222. && isVpaasMeeting(state)
  223. && iAmRecordingInitiator
  224. && !isSavingRecordingOnDropbox(state)) {
  225. const region = getMeetingRegion(state);
  226. const tenant = getVpaasTenant(state);
  227. try {
  228. const response = await getRecordingLink(recordingSharingUrl, sessionId, region, tenant);
  229. const { url: link, urlExpirationTimeMillis: ttl } = response;
  230. if (typeof APP === 'object') {
  231. APP.API.notifyRecordingLinkAvailable(link, ttl);
  232. }
  233. // add the option to copy recording link
  234. notifyProps.dialogProps = {
  235. ...notifyProps.dialogProps,
  236. customActionNameKey: [ 'recording.copyLink' ],
  237. customActionHandler: [ () => copyText(link) ],
  238. titleKey: 'recording.on',
  239. descriptionKey: 'recording.linkGenerated'
  240. };
  241. notifyProps.type = NOTIFICATION_TIMEOUT_TYPE.STICKY;
  242. } catch (err) {
  243. dispatch(showErrorNotification({
  244. titleKey: 'recording.errorFetchingLink'
  245. }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
  246. return logger.error('Could not fetch recording link', err);
  247. }
  248. }
  249. }
  250. dispatch(showNotification(notifyProps.dialogProps, notifyProps.type));
  251. };
  252. }
  253. /**
  254. * Updates the known state for a given recording session.
  255. *
  256. * @param {Object} session - The new state to merge with the existing state in
  257. * redux.
  258. * @returns {{
  259. * type: RECORDING_SESSION_UPDATED,
  260. * sessionData: Object
  261. * }}
  262. */
  263. export function updateRecordingSessionData(session: any) {
  264. const status = session.getStatus();
  265. const timestamp
  266. = status === JitsiRecordingConstants.status.ON
  267. ? Date.now() / 1000
  268. : undefined;
  269. return {
  270. type: RECORDING_SESSION_UPDATED,
  271. sessionData: {
  272. error: session.getError(),
  273. id: session.getID(),
  274. initiator: session.getInitiator(),
  275. liveStreamViewURL: session.getLiveStreamViewURL(),
  276. mode: session.getMode(),
  277. status,
  278. terminator: session.getTerminator(),
  279. timestamp
  280. }
  281. };
  282. }
  283. /**
  284. * Sets the selected recording service.
  285. *
  286. * @param {string} selectedRecordingService - The new selected recording service.
  287. * @returns {Object}
  288. */
  289. export function setSelectedRecordingService(selectedRecordingService: string) {
  290. return {
  291. type: SET_SELECTED_RECORDING_SERVICE,
  292. selectedRecordingService
  293. };
  294. }
  295. /**
  296. * Sets UID of the the pending streaming notification to use it when hinding
  297. * the notification is necessary, or unsets it when undefined (or no param) is
  298. * passed.
  299. *
  300. * @param {?number} uid - The UID of the notification.
  301. * @param {string} streamType - The type of the stream ({@code file} or
  302. * {@code stream}).
  303. * @returns {{
  304. * type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  305. * streamType: string,
  306. * uid: number
  307. * }}
  308. */
  309. function _setPendingRecordingNotificationUid(uid: string | undefined, streamType: string) {
  310. return {
  311. type: SET_PENDING_RECORDING_NOTIFICATION_UID,
  312. streamType,
  313. uid
  314. };
  315. }
  316. /**
  317. * Starts local recording.
  318. *
  319. * @param {boolean} onlySelf - Whether to only record the local streams.
  320. * @returns {Object}
  321. */
  322. export function startLocalVideoRecording(onlySelf?: boolean) {
  323. return {
  324. type: START_LOCAL_RECORDING,
  325. onlySelf
  326. };
  327. }
  328. /**
  329. * Stops local recording.
  330. *
  331. * @returns {Object}
  332. */
  333. export function stopLocalVideoRecording() {
  334. return {
  335. type: STOP_LOCAL_RECORDING
  336. };
  337. }