node-webrtc / node-webrtc-examples

MediaStream and RTCDataChannel examples using node-webrtc
508 stars 161 forks source link

RTCVideoSink on Frame #44

Open remymatheus opened 3 years ago

remymatheus commented 3 years ago

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 -----
    });
  };
});
sagarchikhale commented 1 month ago

I have same issue.