選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.any.ts 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import { IStore } from '../app/types';
  2. import { getCurrentConference } from '../base/conference/functions';
  3. import { hideDialog, openDialog } from '../base/dialog/actions';
  4. import { getLocalParticipant } from '../base/participants/functions';
  5. import {
  6. RESET_SHARED_VIDEO_STATUS,
  7. SET_ALLOWED_URL_DOMAINS,
  8. SET_CONFIRM_SHOW_VIDEO,
  9. SET_SHARED_VIDEO_STATUS
  10. } from './actionTypes';
  11. import { ShareVideoConfirmDialog, SharedVideoDialog } from './components';
  12. import { PLAYBACK_START, PLAYBACK_STATUSES } from './constants';
  13. import { isSharedVideoEnabled, sendShareVideoCommand } from './functions';
  14. /**
  15. * Marks that user confirmed or not to play video.
  16. *
  17. * @param {boolean} value - The value to set.
  18. * @returns {{
  19. * type: SET_CONFIRM_SHOW_VIDEO,
  20. * }}
  21. */
  22. export function setConfirmShowVideo(value: boolean) {
  23. return {
  24. type: SET_CONFIRM_SHOW_VIDEO,
  25. value
  26. };
  27. }
  28. /**
  29. * Resets the status of the shared video.
  30. *
  31. * @returns {{
  32. * type: SET_SHARED_VIDEO_STATUS,
  33. * }}
  34. */
  35. export function resetSharedVideoStatus() {
  36. return {
  37. type: RESET_SHARED_VIDEO_STATUS
  38. };
  39. }
  40. /**
  41. * Updates the current known status of the shared video.
  42. *
  43. * @param {Object} options - The options.
  44. * @param {boolean} options.muted - Is video muted.
  45. * @param {boolean} options.ownerId - Participant ID of the owner.
  46. * @param {boolean} options.status - Sharing status.
  47. * @param {boolean} options.time - Playback timestamp.
  48. * @param {boolean} options.videoUrl - URL of the shared video.
  49. *
  50. * @returns {{
  51. * type: SET_SHARED_VIDEO_STATUS,
  52. * muted: boolean,
  53. * ownerId: string,
  54. * status: string,
  55. * time: number,
  56. * videoUrl: string,
  57. * }}
  58. */
  59. export function setSharedVideoStatus({ videoUrl, status, time, ownerId, muted }: {
  60. muted?: boolean; ownerId?: string; status: string; time: number; videoUrl: string;
  61. }) {
  62. return {
  63. type: SET_SHARED_VIDEO_STATUS,
  64. ownerId,
  65. status,
  66. time,
  67. videoUrl,
  68. muted
  69. };
  70. }
  71. /**
  72. * Displays the dialog for entering the video link.
  73. *
  74. * @param {Function} onPostSubmit - The function to be invoked when a valid link is entered.
  75. * @returns {Function}
  76. */
  77. export function showSharedVideoDialog(onPostSubmit: Function) {
  78. return openDialog(SharedVideoDialog, { onPostSubmit });
  79. }
  80. /**
  81. *
  82. * Stops playing a shared video.
  83. *
  84. * @returns {Function}
  85. */
  86. export function stopSharedVideo() {
  87. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  88. const state = getState();
  89. const { ownerId } = state['features/shared-video'];
  90. const localParticipant = getLocalParticipant(state);
  91. if (ownerId === localParticipant?.id) {
  92. dispatch(resetSharedVideoStatus());
  93. }
  94. };
  95. }
  96. /**
  97. *
  98. * Plays a shared video.
  99. *
  100. * @param {string} videoUrl - The video url to be played.
  101. *
  102. * @returns {Function}
  103. */
  104. export function playSharedVideo(videoUrl: string) {
  105. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  106. if (!isSharedVideoEnabled(getState())) {
  107. return;
  108. }
  109. const conference = getCurrentConference(getState());
  110. if (conference) {
  111. const localParticipant = getLocalParticipant(getState());
  112. // we will send the command and will create local video fake participant
  113. // and start playing once we receive ourselves the command
  114. sendShareVideoCommand({
  115. conference,
  116. id: videoUrl,
  117. localParticipantId: localParticipant?.id,
  118. status: PLAYBACK_START,
  119. time: 0
  120. });
  121. }
  122. };
  123. }
  124. /**
  125. *
  126. * Stops playing a shared video.
  127. *
  128. * @returns {Function}
  129. */
  130. export function toggleSharedVideo() {
  131. return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
  132. const state = getState();
  133. const { status = '' } = state['features/shared-video'];
  134. if ([ PLAYBACK_STATUSES.PLAYING, PLAYBACK_START, PLAYBACK_STATUSES.PAUSED ].includes(status)) {
  135. dispatch(stopSharedVideo());
  136. } else {
  137. dispatch(showSharedVideoDialog((id: string) => dispatch(playSharedVideo(id))));
  138. }
  139. };
  140. }
  141. /**
  142. * Sets the allowed URL domains of the shared video.
  143. *
  144. * @param {Array<string>} allowedUrlDomains - The new whitelist to be set.
  145. * @returns {{
  146. * type: SET_ALLOWED_URL_DOMAINS,
  147. * allowedUrlDomains: Array<string>
  148. * }}
  149. */
  150. export function setAllowedUrlDomians(allowedUrlDomains: Array<string>) {
  151. return {
  152. type: SET_ALLOWED_URL_DOMAINS,
  153. allowedUrlDomains
  154. };
  155. }
  156. /**
  157. * Shows a confirmation dialog whether to play the external video link.
  158. *
  159. * @param {string} actor - The actor's name.
  160. * @param {Function} onSubmit - The function to execute when confirmed.
  161. *
  162. * @returns {Function}
  163. */
  164. export function showConfirmPlayingDialog(actor: String, onSubmit: Function) {
  165. return (dispatch: IStore['dispatch']) => {
  166. // shows only one dialog at a time
  167. dispatch(setConfirmShowVideo(false));
  168. dispatch(openDialog(ShareVideoConfirmDialog, {
  169. actorName: actor,
  170. onSubmit: () => {
  171. dispatch(setConfirmShowVideo(true));
  172. onSubmit();
  173. }
  174. }));
  175. };
  176. }
  177. /**
  178. * Hides the video play confirmation dialog.
  179. *
  180. * @returns {Function}
  181. */
  182. export function hideConfirmPlayingDialog() {
  183. return (dispatch: IStore['dispatch']) => {
  184. dispatch(hideDialog(ShareVideoConfirmDialog));
  185. };
  186. }