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

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