From c4f1e4d8c05d353158a2373ef8a97f5b9ee3821f Mon Sep 17 00:00:00 2001 From: EpicKiwi Date: Thu, 21 Sep 2023 11:52:30 +0200 Subject: [PATCH] Added video support --- static/js/grab-canvas.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/static/js/grab-canvas.js b/static/js/grab-canvas.js index 43e3d50..b3ccc46 100644 --- a/static/js/grab-canvas.js +++ b/static/js/grab-canvas.js @@ -2,9 +2,9 @@ const globalConnnection = Symbol("grab-canvas-connection") const currentScriptSrc = document.currentScript.src; - const canvas = document.querySelector("canvas"); + const sourceElt = document.querySelector("canvas,video"); - if(!canvas){ + if(!sourceElt){ console.error("No canvas found on this page") } @@ -22,7 +22,12 @@ const allCandidatesCollected = new Promise(res => conn.addEventListener("icecandidate", e => e.candidate == null && res() )) - const canvasStream = canvas.captureStream() + let captureFn = sourceElt.captureStream; + if(!captureFn){ + captureFn = sourceElt.mozCaptureStream; + } + + const canvasStream = captureFn() const canvasStreamTracks = canvasStream.getVideoTracks() if(canvasStreamTracks.length > 0){ conn.addTrack(canvasStreamTracks[0], canvasStream)