mirror of
https://codeberg.org/vlw/pip-canvas.git
synced 2025-09-14 02:43:41 +02:00
29 lines
No EOL
715 B
JavaScript
29 lines
No EOL
715 B
JavaScript
export class PipCanvas {
|
|
constructor(source) {
|
|
this.source = source;
|
|
const canvas = document.createElement("canvas");
|
|
this.ctx = canvas.getContext("2d");
|
|
|
|
// Call method with same constructor name if exists
|
|
if (this.source.constructor.name in this) {
|
|
this[this.source.constructor.name]();
|
|
}
|
|
|
|
this.video = document.createElement("video");
|
|
this.video.srcObject = canvas.captureStream(0);
|
|
}
|
|
|
|
// Create from image
|
|
HTMLImageElement() {
|
|
this.ctx.width = this.ctx.canvas.width = this.source.width;
|
|
this.ctx.height = this.ctx.canvas.height = this.source.height;
|
|
|
|
this.ctx.drawImage(this.source, 0, 0);
|
|
}
|
|
|
|
// Open PIP
|
|
open() {
|
|
this.video.play();
|
|
this.video.requestPictureInPicture();
|
|
}
|
|
} |