Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

function.any.ts 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import { IReduxState } from '../app/types';
  2. import { GIF_DEFAULT_RATING, GIF_PREFIX } from './constants';
  3. import { IGif } from './reducer';
  4. /**
  5. * Returns the gif config.
  6. *
  7. * @param {IReduxState} state - Redux state.
  8. * @returns {Object}
  9. */
  10. export function getGifConfig(state: IReduxState) {
  11. return state['features/base/config'].giphy || {};
  12. }
  13. /**
  14. * Get the GIF display mode.
  15. *
  16. * @param {IReduxState} state - Redux state.
  17. * @returns {string}
  18. */
  19. export function getGifDisplayMode(state: IReduxState) {
  20. return getGifConfig(state).displayMode || 'all';
  21. }
  22. /**
  23. * Get the GIF audience rating.
  24. *
  25. * @param {IReduxState} state - Redux state.
  26. * @returns {string}
  27. */
  28. export function getGifRating(state: IReduxState) {
  29. return getGifConfig(state).rating || GIF_DEFAULT_RATING;
  30. }
  31. /**
  32. * Get the Giphy proxy url.
  33. *
  34. * @param {IReduxState} state - Redux state.
  35. * @returns {string}
  36. */
  37. export function getGiphyProxyUrl(state: IReduxState) {
  38. return getGifConfig(state).proxyUrl;
  39. }
  40. /**
  41. * Gets the URL of the GIF for the given participant or null if there's none.
  42. *
  43. * @param {IReduxState} state - Redux state.
  44. * @param {string} participantId - Id of the participant for which to remove the GIF.
  45. * @returns {Object}
  46. */
  47. export function getGifForParticipant(state: IReduxState, participantId: string): IGif {
  48. return isGifEnabled(state) ? state['features/gifs'].gifList.get(participantId) || {} : {};
  49. }
  50. /**
  51. * Whether or not the message is a GIF message.
  52. *
  53. * @param {string} message - Message to check.
  54. * @returns {boolean}
  55. */
  56. export function isGifMessage(message: string) {
  57. return message.trim().toLowerCase()
  58. .startsWith(GIF_PREFIX);
  59. }
  60. /**
  61. * Returns the url of the gif selected in the gifs menu.
  62. *
  63. * @param {Object} gif - The gif data.
  64. * @param {string} proxyUrl - The proxy server url.
  65. * @returns {boolean}
  66. */
  67. export function getGifUrl(gif?: { data?: { embed_url: string; }; embed_url?: string; }, proxyUrl?: string) {
  68. const embedUrl = gif?.embed_url || gif?.data?.embed_url || '';
  69. const idx = embedUrl.lastIndexOf('/');
  70. const id = embedUrl.substr(idx + 1);
  71. if (proxyUrl) {
  72. return `${proxyUrl}gifs/id/${id}`;
  73. }
  74. return `https://i.giphy.com/media/${id}/giphy.gif`;
  75. }
  76. /**
  77. * Formats the gif message.
  78. *
  79. * @param {string} url - GIF url.
  80. * @returns {string}
  81. */
  82. export function formatGifUrlMessage(url: string) {
  83. return `${GIF_PREFIX}${url}]`;
  84. }
  85. /**
  86. * Get the Giphy API Key from config.
  87. *
  88. * @param {IReduxState} state - Redux state.
  89. * @returns {string}
  90. */
  91. export function getGifAPIKey(state: IReduxState) {
  92. return getGifConfig(state).sdkKey ?? '';
  93. }
  94. /**
  95. * Returns whether or not the feature is enabled.
  96. *
  97. * @param {IReduxState} state - Redux state.
  98. * @returns {boolean}
  99. */
  100. export function isGifEnabled(state: IReduxState) {
  101. const { disableThirdPartyRequests } = state['features/base/config'];
  102. const { giphy } = state['features/base/config'];
  103. const showGiphyIntegration = state['features/dynamic-branding']?.showGiphyIntegration !== false;
  104. if (navigator.product === 'ReactNative' && window.JITSI_MEET_LITE_SDK) {
  105. return false;
  106. }
  107. return showGiphyIntegration && Boolean(!disableThirdPartyRequests && giphy?.enabled && Boolean(giphy?.sdkKey));
  108. }