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.3KB

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