node.js - Get black box in <video> when using webRTC mediasoup - Stack Overflow

I set up a basic code in client-side to receive producer info from server-side and createtag with tha

I set up a basic code in client-side to receive producer info from server-side and create tag with that.

try {
          const { id, producerId, kind, rtpParameters } = consumerInfo[key];

          const codecOptions = {};
          const consumer = await consumerTransportRef.current.consume({
            id,
            producerId,
            kind,
            rtpParameters,
            codecOptions,
          });

          const stream = new MediaStream();
          stream.addTrack(consumer.track);

          createMediaElement(kind, stream, user_id);
        } catch (error) {
          console.error(mediasoupErrorMessage.unknow, error);
        }
}

The createMediaElement funtion

function createMediaElement(kind, stream, userId) {
  let mediaElement;
  const container = document.getElementById(cameraPlaceholder);
  if (!container) {
    console.error(`Container element '${cameraPlaceholder}' not found!`);
    return;
  }

  if (kind === "audio") {
    mediaElement = document.createElement("audio");
    mediaElement.id = `remoteAudio_${userId}`;
    mediaElement.srcObject = stream;
    mediaElement.autoplay = true;
    mediaElement.controls = false;
    mediaElement.style.display = "none";
  } else if (kind === "video") {
    console.log("Video tracks:", stream.getVideoTracks());
    mediaElement = document.createElement("video");
    mediaElement.id = `remoteVideo_${userId}`;
    mediaElement.srcObject = stream;
    mediaElement.autoplay = true;
    mediaElement.playsInline = true;
    mediaElement.muted = true;
    mediaElement.style.width = "340px";
    mediaElement.style.height = "180px";
  }

  container.appendChild(mediaElement);
}

The problem is it always return me a black box, even when the kind, stream, userId is not null. I did try to log the stream, stream.active = true, id exists. Is there any things that I miss in here.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745273597a4619900.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信