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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. const promise = Promise.resolve();
  17. if (!largeVideo) {
  18. return promise;
  19. }
  20. const tracks = state['features/base/tracks'];
  21. const participantTrack = getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.VIDEO, largeVideo.participantId);
  22. // Participants that join the call video muted do not have a jitsiTrack attached.
  23. if (!(participantTrack && participantTrack.jitsiTrack)) {
  24. return promise;
  25. }
  26. const videoStream = participantTrack.jitsiTrack.getOriginalStream();
  27. if (!videoStream) {
  28. return promise;
  29. }
  30. // Get the video element for the large video, cast HTMLElement to HTMLVideoElement to make flow happy.
  31. /* eslint-disable-next-line no-extra-parens*/
  32. const videoElement = ((document.getElementById('largeVideo'): any): HTMLVideoElement);
  33. if (!videoElement) {
  34. return promise;
  35. }
  36. // Create a HTML canvas and draw video on to the canvas.
  37. const [ track ] = videoStream.getVideoTracks();
  38. const { height, width } = track.getSettings() ?? track.getConstraints();
  39. const canvasElement = document.createElement('canvas');
  40. const ctx = canvasElement.getContext('2d');
  41. canvasElement.style.display = 'none';
  42. canvasElement.height = parseInt(height, 10);
  43. canvasElement.width = parseInt(width, 10);
  44. ctx.drawImage(videoElement, 0, 0);
  45. const dataURL = canvasElement.toDataURL('image/png', 1.0);
  46. // Cleanup.
  47. ctx.clearRect(0, 0, canvasElement.width, canvasElement.height);
  48. canvasElement.remove();
  49. return Promise.resolve(dataURL);
  50. };
  51. }
  52. /**
  53. * Resizes the large video container based on the dimensions provided.
  54. *
  55. * @param {number} width - Width that needs to be applied on the large video container.
  56. * @param {number} height - Height that needs to be applied on the large video container.
  57. * @returns {Function}
  58. */
  59. export function resizeLargeVideo(width: number, height: number) {
  60. return (dispatch: Dispatch<any>, getState: Function) => {
  61. const state = getState();
  62. const largeVideo = state['features/large-video'];
  63. if (largeVideo) {
  64. const largeVideoContainer = VideoLayout.getLargeVideo();
  65. largeVideoContainer.updateContainerSize(width, height);
  66. largeVideoContainer.resize();
  67. }
  68. };
  69. }