node-webrtc-examples icon indicating copy to clipboard operation
node-webrtc-examples copied to clipboard

RTCVideoSink on Frame

Open remymatheus opened this issue 4 years ago • 1 comments
trafficstars

Hi, thanks for your help, I have the following code, I make the connection correctly and receive the MediaStream, but when I want to use RTCVideoSink , it does not fire the event "addEventListener('frame')", I don't know if something is wrong. Thanks for your help.

socket.on("offer", (id, description) => {
  peerConnection = new wrtc.RTCPeerConnection(config);
  peerConnection
    .setRemoteDescription(description)
    .then(() => peerConnection.createAnswer())
    .then(sdp => peerConnection.setLocalDescription(sdp))
    .then(() => {
      socket.emit("answer", id, peerConnection.localDescription);

    });
  peerConnection.onicecandidate = event => {
    if (event.candidate) {
      socket.emit("candidate", id, event.candidate);
    }
  };
  peerConnection.ontrack = event => { // ON TRACK EVENT CREATE RTCVideoSink with MediaStreamTrack, This is wrong?
    const tracks = event.streams[0].getVideoTracks();
    const transceiver = peerConnection.addTransceiver(tracks[0]);
    const sink = new RTCVideoSink(transceiver.receiver.track);
    sink.addEventListener('frame', ({ frame: { width, height, data }}) => {
      ----- CODE -----
    });
  };
});

remymatheus avatar Apr 28 '21 01:04 remymatheus