Well, the problem is very unusual. I create Angular app to communicate between two Peers via WebRTC. The architecture was simple 2 peers which sends video stream from camera and receives stream from other peer. Simple and working.
Now I want to add some processing to stream so to first peer I add the canvas element like this:
this.localCameraVideoStream = document.createElement('video');
this.localCameraVideoStream.srcObject = stream;
this.localCameraVideoStream.muted = true;
this.localCameraVideoStream.play();
this.canvas = document.createElement('canvas');
this.canvas.width = 1280;
this.canvas.height = 720;
this.canvasStream = this.canvas.captureStream();
this.localVideoElement.nativeElement.srcObject = this.canvasStream;
this.localVideoElement.nativeElement.muted = true;
this.localVideoElement.nativeElement.play();
this.redrawStreamToCanvas();
And redraw method to draw stream from <video>
element to canvas:
private redrawStreamToCanvas(){
const ctx = this.canvas.getContext('2d');
const width = 1280;
const height = 720;
const combinedVideoStream = this.localCameraVideoStream;
function drawVideo() {
ctx.clearRect(0, 0, width, height);
ctx.drawImage(combinedVideoStream, 0, 0, width, height);
requestAnimationFrame(drawVideo);
}
requestAnimationFrame(drawVideo);
}
Just to clear any doubts. localCameraVideoStream is <video>
element created to save camera stream in a way that <canvas>
can get stream from <video>
.
canvas is <canvas>
localVideoElement is just a <video>
in .html and displays current "local" stream.
Problem is that in local preview everything works properly. When I send canvasStream
to other peer and display it on some <video>
I only get one frame and thats it.
Do you know whats hapenning? It's weird that in preview is ok and without this combinations rtc connection is also ok.