| |
680 |
680 |
|
| |
681 |
681 |
|
| |
682 |
682 |
takeShot(stream, grayscale) { |
| |
683 |
683 |
const i = this.streams.indexOf(stream); |
| |
684 |
684 |
const video = this.videos[i]; |
| |
685 |
685 |
|
| |
686 |
686 |
if (!video.paused) { |
| |
687 |
687 |
const streamName = this.streamNames[i]; |
| |
688 |
688 |
const conf = this.mediaConf[streamName]; |
| |
689 |
689 |
|
| |
690 |
690 |
|
| |
691 |
691 |
const iHeight = typeof conf.height === 'undefined' ? video.videoHeight : conf.height; |
| |
692 |
692 |
const iWidth = typeof conf.width === 'undefined' ? video.videoWidth : conf.width; |
| |
693 |
693 |
const self = this; |
| |
694 |
694 |
const pictures = this.pictures[i]; |
| |
695 |
695 |
const prevPicture = this.prevPictures[i]; |
| |
696 |
696 |
|
| |
697 |
697 |
const canvas = document.createElement('canvas'); |
| |
698 |
698 |
canvas.width = iWidth; |
| |
699 |
699 |
canvas.height = iHeight; |
| |
700 |
|
canvas.getContext('2d').drawImage(video, 0, 0, iWidth, iHeight); |
| |
|
700 |
const ctx = canvas.getContext('2d', {willReadFrequently: true}); |
| |
|
701 |
ctx.drawImage(video, 0, 0, iWidth, iHeight); |
| |
701 |
702 |
|
| |
702 |
703 |
|
| |
703 |
704 |
|
| |
704 |
705 |
|
| |
705 |
706 |
|
| |
706 |
707 |
|
| |
707 |
708 |
|
| |
708 |
709 |
|
| |
709 |
710 |
if (streamName === 'camera' && |
| |
710 |
711 |
prevPicture !== null && |
| |
711 |
712 |
this.areCanvasEquals(canvas, prevPicture)) { |
| |
712 |
713 |
throw 'Camera is sending the same identical picture twice.'; |
| |
713 |
714 |
} |
| |
714 |
715 |
this.prevPictures[i] = this.cloneCanvas(canvas); |
| |
715 |
716 |
|
| |
716 |
717 |
if (grayscale) { |
| |
717 |
718 |
this.canvasToGrayscale(canvas); |
| |
718 |
719 |
} |
| |
719 |
720 |
|
| |
720 |
721 |
this.watermark(canvas, (new window.Date()).toTZISOString()); |