Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.any.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // @flow
  2. import uuid from 'uuid';
  3. import { getLocalParticipant } from '../base/participants';
  4. import { extractFqnFromPath } from '../dynamic-branding/functions';
  5. import { REACTIONS } from './constants';
  6. import logger from './logger';
  7. /**
  8. * Returns the queue of reactions.
  9. *
  10. * @param {Object} state - The state of the application.
  11. * @returns {boolean}
  12. */
  13. export function getReactionsQueue(state: Object) {
  14. return state['features/reactions'].queue;
  15. }
  16. /**
  17. * Returns chat message from reactions buffer.
  18. *
  19. * @param {Array} buffer - The reactions buffer.
  20. * @returns {string}
  21. */
  22. export function getReactionMessageFromBuffer(buffer: Array<string>) {
  23. return buffer.map(reaction => REACTIONS[reaction].message).reduce((acc, val) => `${acc}${val}`);
  24. }
  25. /**
  26. * Returns reactions array with uid.
  27. *
  28. * @param {Array} buffer - The reactions buffer.
  29. * @returns {Array}
  30. */
  31. export function getReactionsWithId(buffer: Array<string>) {
  32. return buffer.map<Object>(reaction => {
  33. return {
  34. reaction,
  35. uid: uuid.v4()
  36. };
  37. });
  38. }
  39. /**
  40. * Sends reactions to the backend.
  41. *
  42. * @param {Object} state - The redux state object.
  43. * @param {Array} reactions - Reactions array to be sent.
  44. * @returns {void}
  45. */
  46. export async function sendReactionsWebhook(state: Object, reactions: Array<?string>) {
  47. const { webhookProxyUrl: url } = state['features/base/config'];
  48. const { conference } = state['features/base/conference'];
  49. const { jwt } = state['features/base/jwt'];
  50. const { locationURL } = state['features/base/connection'];
  51. const localParticipant = getLocalParticipant(state);
  52. const headers = {
  53. 'Authorization': `Bearer ${jwt}`,
  54. 'Content-Type': 'application/json'
  55. };
  56. const reqBody = {
  57. meetingFqn: extractFqnFromPath(locationURL.pathname),
  58. sessionId: conference.sessionId,
  59. submitted: Date.now(),
  60. reactions,
  61. participantId: localParticipant.id,
  62. participantName: localParticipant.name
  63. };
  64. if (url) {
  65. try {
  66. const res = await fetch(`${url}/reactions`, {
  67. method: 'POST',
  68. headers,
  69. body: JSON.stringify(reqBody)
  70. });
  71. if (!res.ok) {
  72. logger.error('Status error:', res.status);
  73. }
  74. } catch (err) {
  75. logger.error('Could not send request', err);
  76. }
  77. }
  78. }