[英]Canvas.captureStream() does not exist in Angular 8
I'm trying to send the content of an HTML canvas as a stream using webrtc.我正在尝试使用 webrtc 将 HTML 画布的内容作为流发送。
While in pure HTML + JS I can use Canvas.captureStream()
to get an output stream, it seems like I can't find any way to do it using Angular 8. The code I'm using is:虽然在纯 HTML + JS 中我可以使用Canvas.captureStream()
来获取输出流,但似乎我找不到任何使用 Angular 8 的方法。我使用的代码是:
@ViewChild('canvas', {static: true})
canvas: ElementRef<HTMLCanvasElement>;
private canvasContext: CanvasRenderingContext2D;
ngOnInit() {
this.setupWebRtc();
this.canvasContext = this.canvas.nativeElement.getContext('2d');
}
draw() {
if (this.drawOnTop) {
this.canvasContext.fillStyle = '#27bae7';
this.canvasContext.fillRect(0, 100, this.canvas.nativeElement.width, 50);
// Trying to get an output stream
let streamdata = this.canvas.nativeElement.captureStream();
console.log(streamdata);
}
Using canvas.nativeElemet or canvasContext didn't seem to help as both have no captureStream() function.使用 canvas.nativeElemet 或 canvasContext 似乎没有帮助,因为两者都没有 captureStream() 函数。
I was thinking about using canvas.nativeElement.toDataURL();
我正在考虑使用canvas.nativeElement.toDataURL();
but it seems like a bad approach.但这似乎是一个糟糕的方法。
I would love to get some suggestions.我很想得到一些建议。
Seems like the solution was a simple casting to <Any>
.似乎解决方案是对<Any>
的简单转换。 Meaning it was a typing issue.这意味着这是一个打字问题。 I used:我用了:
const streamdata = (this.canvas.nativeElement as any).captureStream();
To get the stream.获取流。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.