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.

functions.js 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // @flow
  2. import { getFakeParticipants } from '../base/participants';
  3. import { VIDEO_PLAYER_PARTICIPANT_NAME, YOUTUBE_PLAYER_PARTICIPANT_NAME } from './constants';
  4. /**
  5. * Validates the entered video url.
  6. *
  7. * It returns a boolean to reflect whether the url matches the youtube regex.
  8. *
  9. * @param {string} url - The entered video link.
  10. * @returns {string} The youtube video id if matched.
  11. */
  12. export function getYoutubeId(url: string) {
  13. if (!url) {
  14. return null;
  15. }
  16. const p = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|(?:m\.)?youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;// eslint-disable-line max-len
  17. const result = url.match(p);
  18. return result ? result[1] : null;
  19. }
  20. /**
  21. * Checks if the status is one that is actually sharing the video - playing, pause or start.
  22. *
  23. * @param {string} status - The shared video status.
  24. * @returns {boolean}
  25. */
  26. export function isSharingStatus(status: string) {
  27. return [ 'playing', 'pause', 'start' ].includes(status);
  28. }
  29. /**
  30. * Returns true if there is a video being shared in the meeting.
  31. *
  32. * @param {Object | Function} stateful - The Redux state or a function that gets resolved to the Redux state.
  33. * @returns {boolean}
  34. */
  35. export function isVideoPlaying(stateful: Object | Function): boolean {
  36. let videoPlaying = false;
  37. // eslint-disable-next-line no-unused-vars
  38. for (const [ id, p ] of getFakeParticipants(stateful)) {
  39. if (p.name === VIDEO_PLAYER_PARTICIPANT_NAME || p.name === YOUTUBE_PLAYER_PARTICIPANT_NAME) {
  40. videoPlaying = true;
  41. break;
  42. }
  43. }
  44. return videoPlaying;
  45. }