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.

actions.web.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import VideoLayout from '../../../modules/UI/videolayout/VideoLayout';
  4. import { MEDIA_TYPE } from '../base/media';
  5. import { getTrackByMediaTypeAndParticipant } from '../base/tracks';
  6. export * from './actions.any';
  7. /**
  8. * Captures a screenshot of the video displayed on the large video.
  9. *
  10. * @returns {Function}
  11. */
  12. export function captureLargeVideoScreenshot() {
  13. return (dispatch: Dispatch<any>, getState: Function): Promise<string> => {
  14. const state = getState();
  15. const largeVideo = state['features/large-video'];
  16. if (!largeVideo) {
  17. return Promise.resolve();
  18. }
  19. const tracks = state['features/base/tracks'];
  20. const { jitsiTrack } = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, largeVideo.participantId);
  21. const videoStream = jitsiTrack.getOriginalStream();
  22. // Get the video element for the large video, cast HTMLElement to HTMLVideoElement to make flow happy.
  23. /* eslint-disable-next-line no-extra-parens*/
  24. const videoElement = ((document.getElementById('largeVideo'): any): HTMLVideoElement);
  25. if (!videoElement) {
  26. return Promise.resolve();
  27. }
  28. // Create a HTML canvas and draw video on to the canvas.
  29. const [ track ] = videoStream.getVideoTracks();
  30. const { height, width } = track.getSettings() ?? track.getConstraints();
  31. const canvasElement = document.createElement('canvas');
  32. const ctx = canvasElement.getContext('2d');
  33. canvasElement.style.display = 'none';
  34. canvasElement.height = parseInt(height, 10);
  35. canvasElement.width = parseInt(width, 10);
  36. ctx.drawImage(videoElement, 0, 0);
  37. const dataURL = canvasElement.toDataURL('image/png', 1.0);
  38. // Cleanup.
  39. ctx.clearRect(0, 0, canvasElement.width, canvasElement.height);
  40. canvasElement.remove();
  41. return Promise.resolve(dataURL);
  42. };
  43. }
  44. /**
  45. * Resizes the large video container based on the dimensions provided.
  46. *
  47. * @param {number} width - Width that needs to be applied on the large video container.
  48. * @param {number} height - Height that needs to be applied on the large video container.
  49. * @returns {Function}
  50. */
  51. export function resizeLargeVideo(width: number, height: number) {
  52. return (dispatch: Dispatch<any>, getState: Function) => {
  53. const state = getState();
  54. const largeVideo = state['features/large-video'];
  55. if (largeVideo) {
  56. const largeVideoContainer = VideoLayout.getLargeVideo();
  57. largeVideoContainer.updateContainerSize(width, height);
  58. largeVideoContainer.resize();
  59. }
  60. };
  61. }