mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 18:39:58 +00:00
Use requestAnimationFrame in place of setInterval for tab mirroring
This commit is contained in:
@@ -90,14 +90,18 @@ async function onRequestSessionSuccess (newSession: cast.Session) {
|
|||||||
const drawFlags =
|
const drawFlags =
|
||||||
ctx.DRAWWINDOW_DRAW_CARET
|
ctx.DRAWWINDOW_DRAW_CARET
|
||||||
| ctx.DRAWWINDOW_DRAW_VIEW
|
| ctx.DRAWWINDOW_DRAW_VIEW
|
||||||
| ctx.DRAWWINDOW_ASYNC_DECODE_IMAGES;
|
| ctx.DRAWWINDOW_ASYNC_DECODE_IMAGES
|
||||||
|
| ctx.DRAWWINDOW_USE_WIDGET_LAYERS;
|
||||||
|
|
||||||
/**
|
let lastFrame: DOMHighResTimeStamp;
|
||||||
* Clears the canvas and draws the window. Called repeatedly,
|
window.requestAnimationFrame(
|
||||||
* currently at 30FPS rate because performance is quite poor.
|
function draw (now: DOMHighResTimeStamp) {
|
||||||
*/
|
|
||||||
function drawWindow () {
|
if (!lastFrame) {
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
lastFrame = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((now - lastFrame) > (1000 / 30)) {
|
||||||
ctx.drawWindow(
|
ctx.drawWindow(
|
||||||
window // window
|
window // window
|
||||||
, 0, 0 // x, y
|
, 0, 0 // x, y
|
||||||
@@ -105,10 +109,12 @@ async function onRequestSessionSuccess (newSession: cast.Session) {
|
|||||||
, canvas.height // h
|
, canvas.height // h
|
||||||
, "white" // bgColor
|
, "white" // bgColor
|
||||||
, drawFlags); // flags
|
, drawFlags); // flags
|
||||||
|
|
||||||
|
lastFrame = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.requestAnimationFrame(draw);
|
||||||
window.setInterval(drawWindow, 1000 / 30);
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Capture video stream from canvas and feed into the RTC
|
* Capture video stream from canvas and feed into the RTC
|
||||||
|
|||||||
Reference in New Issue
Block a user