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 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { IStore } from '../app/types';
  2. import { getCurrentConference } from '../base/conference/functions';
  3. import { openDialog } from '../base/dialog/actions';
  4. import { getLocalParticipant } from '../base/participants/functions';
  5. import { RESET_SHARED_VIDEO_STATUS, SET_SHARED_VIDEO_STATUS } from './actionTypes';
  6. // eslint-disable-next-line lines-around-comment
  7. // @ts-ignore
  8. import { SharedVideoDialog } from './components';
  9. /**
  10. * Resets the status of the shared video.
  11. *
  12. * @returns {{
  13. * type: SET_SHARED_VIDEO_STATUS,
  14. * }}
  15. */
  16. export function resetSharedVideoStatus() {
  17. return {
  18. type: RESET_SHARED_VIDEO_STATUS
  19. };
  20. }
  21. /**
  22. * Updates the current known status of the shared video.
  23. *
  24. * @param {Object} options - The options.
  25. * @param {boolean} options.muted - Is video muted.
  26. * @param {boolean} options.ownerId - Participant ID of the owner.
  27. * @param {boolean} options.status - Sharing status.
  28. * @param {boolean} options.time - Playback timestamp.
  29. * @param {boolean} options.videoUrl - URL of the shared video.
  30. *
  31. * @returns {{
  32. * type: SET_SHARED_VIDEO_STATUS,
  33. * muted: boolean,
  34. * ownerId: string,
  35. * status: string,
  36. * time: number,
  37. * videoUrl: string,
  38. * }}
  39. */
  40. export function setSharedVideoStatus({ videoUrl, status, time, ownerId, muted }: {
  41. muted?: boolean; ownerId?: string; status: string; time: number; videoUrl: string;
  42. }) {
  43. return {
  44. type: SET_SHARED_VIDEO_STATUS,
  45. ownerId,
  46. status,
  47. time,
  48. videoUrl,
  49. muted
  50. };
  51. }
  52. /**
  53. * Displays the dialog for entering the video link.
  54. *
  55. * @param {Function} onPostSubmit - The function to be invoked when a valid link is entered.
  56. * @returns {Function}
  57. */
  58. export function showSharedVideoDialog(onPostSubmit: Function) {
  59. return openDialog(SharedVideoDialog, { onPostSubmit });
  60. }
  61. /**
  62. *
  63. * Stops playing a shared video.
  64. *
  65. * @returns {Function}
  66. */
  67. export function stopSharedVideo() {
  68. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  69. const state = getState();
  70. const { ownerId } = state['features/shared-video'];
  71. const localParticipant = getLocalParticipant(state);
  72. if (ownerId === localParticipant?.id) {
  73. dispatch(resetSharedVideoStatus());
  74. }
  75. };
  76. }
  77. /**
  78. *
  79. * Plays a shared video.
  80. *
  81. * @param {string} videoUrl - The video url to be played.
  82. *
  83. * @returns {Function}
  84. */
  85. export function playSharedVideo(videoUrl: string) {
  86. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  87. const conference = getCurrentConference(getState());
  88. if (conference) {
  89. const localParticipant = getLocalParticipant(getState());
  90. dispatch(setSharedVideoStatus({
  91. videoUrl,
  92. status: 'start',
  93. time: 0,
  94. ownerId: localParticipant?.id
  95. }));
  96. }
  97. };
  98. }
  99. /**
  100. *
  101. * Stops playing a shared video.
  102. *
  103. * @returns {Function}
  104. */
  105. export function toggleSharedVideo() {
  106. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  107. const state = getState();
  108. const { status = '' } = state['features/shared-video'];
  109. if ([ 'playing', 'start', 'pause' ].includes(status)) {
  110. dispatch(stopSharedVideo());
  111. } else {
  112. dispatch(showSharedVideoDialog((id: string) => dispatch(playSharedVideo(id))));
  113. }
  114. };
  115. }