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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // @flow
  2. import logger from './logger';
  3. /**
  4. * Sends the facial expression with its duration to all the other participants.
  5. *
  6. * @param {Object} conference - The current conference.
  7. * @param {string} facialExpression - Facial expression to be sent.
  8. * @param {number} duration - The duration of the facial expression in seconds.
  9. * @returns {void}
  10. */
  11. export function sendFacialExpressionToParticipants(
  12. conference: Object,
  13. facialExpression: string,
  14. duration: number
  15. ): void {
  16. try {
  17. conference.sendEndpointMessage('', {
  18. type: 'facial_expression',
  19. facialExpression,
  20. duration
  21. });
  22. } catch (err) {
  23. logger.warn('Could not broadcast the facial expression to the other participants', err);
  24. }
  25. }
  26. /**
  27. * Sends the facial expression with its duration to xmpp server.
  28. *
  29. * @param {Object} conference - The current conference.
  30. * @param {string} facialExpression - Facial expression to be sent.
  31. * @param {number} duration - The duration of the facial expression in seconds.
  32. * @returns {void}
  33. */
  34. export function sendFacialExpressionToServer(
  35. conference: Object,
  36. facialExpression: string,
  37. duration: number
  38. ): void {
  39. try {
  40. conference.sendFacialExpression({
  41. facialExpression,
  42. duration
  43. });
  44. } catch (err) {
  45. logger.warn('Could not send the facial expression to xmpp server', err);
  46. }
  47. }
  48. /**
  49. * Sends the image data a canvas from the track in the image capture to the facial expression worker.
  50. *
  51. * @param {Worker} worker - Facial expression worker.
  52. * @param {Object} imageCapture - Image capture that contains the current track.
  53. * @returns {Promise<void>}
  54. */
  55. export async function sendDataToWorker(
  56. worker: Worker,
  57. imageCapture: Object
  58. ): Promise<void> {
  59. if (imageCapture === null || imageCapture === undefined) {
  60. return;
  61. }
  62. let imageBitmap;
  63. try {
  64. imageBitmap = await imageCapture.grabFrame();
  65. } catch (err) {
  66. logger.warn(err);
  67. return;
  68. }
  69. const canvas = document.createElement('canvas');
  70. const context = canvas.getContext('2d');
  71. canvas.width = imageBitmap.width;
  72. canvas.height = imageBitmap.height;
  73. context.drawImage(imageBitmap, 0, 0);
  74. const imageData = context.getImageData(0, 0, imageBitmap.width, imageBitmap.height);
  75. worker.postMessage({
  76. id: 'SET_TIMEOUT',
  77. imageData
  78. });
  79. }