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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. 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. }
  46. /**
  47. * Extracts a Youtube id or URL from the user input.
  48. *
  49. * @param {string} input - The user input.
  50. * @returns {string|undefined}
  51. */
  52. export function extractYoutubeIdOrURL(input: string) {
  53. if (!input) {
  54. return;
  55. }
  56. const trimmedLink = input.trim();
  57. if (!trimmedLink) {
  58. return;
  59. }
  60. const youtubeId = getYoutubeId(trimmedLink);
  61. if (youtubeId) {
  62. return youtubeId;
  63. }
  64. // Check if the URL is valid, native may crash otherwise.
  65. try {
  66. // eslint-disable-next-line no-new
  67. new URL(trimmedLink);
  68. } catch (_) {
  69. return;
  70. }
  71. return trimmedLink;
  72. }