node-webrtc / node-webrtc-examples

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

How do I decode the MediaStream emitted from .ontrack() ? #45

Closed dsteinman closed 2 years ago

dsteinman commented 2 years ago

Basically I've established a WebRTC connection to a WebRTC server (UV4L) and am trying to extract the audio from the stream.

https://developer.mozilla.org/en-US/docs/Web/API/MediaStream

The MediaStream class provided by node-webrtc does not appear to be implemented as it is documented there, is that right?

Although a MediaStream object is emitted by RTCPeerConnection.ontrack() it appears to be an empty/fake EventEmitter object.

let pc = new RTCPeerConnection(...)
pc.ontrack = function(event) {
   let mediaStream = event.streams[0];

   console.log(mediaStream.toString()); // [object MediaStream]

   console.log(MediaStream prototype); // undefined

   for (let key in mediaStream) {
        console.log(key, mediaStream)
   }
   // addEventListener MediaStream {}
   // dispatchEvent MediaStream {}
   // removeEventListener MediaStream {}
}

Maybe I'm missing something here, is there any way to decode the audio/video from a WebRTC server using this library?