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

functions.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { getBaseUrl } from '../base/util';
  2. import { FACE_BOX_EVENT_TYPE, DETECT_FACE_BOX } from './constants';
  3. import logger from './logger';
  4. /**
  5. * Sends the face box to all the other participants.
  6. *
  7. * @param {Object} conference - The current conference.
  8. * @param {Object} faceBox - Face box to be sent.
  9. * @returns {void}
  10. */
  11. export function sendFaceBoxToParticipants(
  12. conference: Object,
  13. faceBox: Object
  14. ): void {
  15. try {
  16. conference.sendEndpointMessage('', {
  17. type: FACE_BOX_EVENT_TYPE,
  18. faceBox
  19. });
  20. } catch (err) {
  21. logger.warn('Could not broadcast the face box to the other participants', err);
  22. }
  23. }
  24. /**
  25. * Sends the image data a canvas from the track in the image capture to the face centering worker.
  26. *
  27. * @param {Worker} worker - Face centering worker.
  28. * @param {Object} imageCapture - Image capture that contains the current track.
  29. * @param {number} threshold - Movement threshold as percentage for sharing face coordinates.
  30. * @param {boolean} isHorizontallyFlipped - Indicates whether the image is horizontally flipped.
  31. * @returns {Promise<void>}
  32. */
  33. export async function sendDataToWorker(
  34. worker: Worker,
  35. imageCapture: Object,
  36. threshold: number = 10,
  37. isHorizontallyFlipped = true
  38. ): Promise<void> {
  39. if (imageCapture === null || imageCapture === undefined) {
  40. return;
  41. }
  42. let imageBitmap;
  43. try {
  44. imageBitmap = await imageCapture.grabFrame();
  45. } catch (err) {
  46. logger.warn(err);
  47. return;
  48. }
  49. worker.postMessage({
  50. id: DETECT_FACE_BOX,
  51. baseUrl: getBaseUrl(),
  52. imageBitmap,
  53. threshold,
  54. isHorizontallyFlipped
  55. });
  56. }
  57. /**
  58. * Gets face box for a participant id.
  59. *
  60. * @param {string} id - The participant id.
  61. * @param {Object} state - The redux state.
  62. * @returns {Object}
  63. */
  64. export function getFaceBoxForId(id: string, state: Object) {
  65. return state['features/face-centering'].faceBoxes[id];
  66. }
  67. /**
  68. * Gets the video object position for a participant id.
  69. *
  70. * @param {Object} state - The redux state.
  71. * @param {string} id - The participant id.
  72. * @returns {string} - CSS object-position in the shape of '{horizontalPercentage}% {verticalPercentage}%'.
  73. */
  74. export function getVideoObjectPosition(state: Object, id: string) {
  75. const faceBox = getFaceBoxForId(id, state);
  76. if (faceBox) {
  77. const { left, right, top, bottom } = faceBox;
  78. const horizontalPos = 100 - Math.round((left + right) / 2, 100);
  79. const verticalPos = 100 - Math.round((top + bottom) / 2, 100);
  80. return `${horizontalPos}% ${verticalPos}%`;
  81. }
  82. return '50% 50%';
  83. }