Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
Uncaught TypeError: canvas.captureStream is not a function

new to react, here i am getting live rtsp stream to canvas, i want to captureStream from it and change it to video tag, but for some reason when consoling captureStream i'm getting error: Uncaught TypeError: canvas.captureStream is not a function. I found some answers from stackoverflow but those had it working with one browser and not other, but in my case i am getting that error in every browser (chrome, firefox,safari ), any idea ?

import React, { useRef, useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import { loadPlayer } from 'rtsp-relay/browser';

const StreamVideo = () => {
  const canvas = useRef(null);

  useEffect(() => {
    if (!canvas.current) throw new Error('Ref is null');

    loadPlayer({
      url: 'ws://.../api/stream',
      canvas: canvas.current,
    });
  }, []);
  var stream = canvas.captureStream(25);
  console.log('canvas element', stream);

  return (
    <div >
      <canvas ref={canvas} />
      <video />
    </div>
  );
};

export default StreamVideo;

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your ref starts out null, so you can't call any methods on it until it has a value. And you must access the current property to get the canvas out of your ref.

You handle this in the effect, but not in your code below the effect.

You also need to type your ref properly so typescript knows what element it's going to have in it.

const canvas = useRef<HTMLCanvasElement>(null);

In this case you can probably get away with calling captureStream with the ?. operator so it it will only be called if canvas exists.

var stream = canvas.current?.captureStream(25);
console.log('canvas element', stream);

Here's an example of a canvas streaming to a video tag.

You have to set the srcObject property of a video tag reference to the created stream. You also need the autoPlay attribute set so the video plays it's stream.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda