Riyad Zaigirdar
Riyad Zaigirdar

Reputation: 750

Cant Record Stream Using MediaRecorder In Server?

First I am trying to make a Webrtc peer connection from the browser to the server using SFU model.

Here is the post request which makes the webrtc peer connection from the browser to the server(SFU)

app.post("/broadcast", async ({ body }, res) => {
  const peer = new webrtc.RTCPeerConnection({
    iceServers: [
      {
        urls: "stun:stun.stunprotocol.org",
      },
    ],
  });
  peer.ontrack = (e) => handleTrackEvent(e, peer); <-- Important
  const desc = new webrtc.RTCSessionDescription(body.sdp);
  await peer.setRemoteDescription(desc);
  const answer = await peer.createAnswer();
  await peer.setLocalDescription(answer);
  const payload = {
    sdp: peer.localDescription,
  };

  res.json(payload);
});

In the handleTrackEvent function, I am getting the stream which I want to start record and save in the server's local storage.

function handleTrackEvent(e, peer) {
  console.log(e.streams);
  senderStream = e.streams[0];
  var recorder = new MediaStreamRecorder(e.streams);
  recorder.recorderType = MediaRecorderWrapper;
  recorder.mimeType = "video/webm";
  recorder.ondataavailable = (blob) => {
    console.log(blob);
  };
  recorder.start(5 * 1000); <-- Error generator
}

But when try to start the recording and get the blob in 5 sec intervals, it gives me "MediaRecorder Not Found" ...

Passing following params over MediaRecorder API. { mimeType: 'video/webm' }
/Users/tecbackup/webrtc-peer/node_modules/msr/MediaStreamRecorder.js:672
            mediaRecorder = new MediaRecorder(mediaStream);
            ^

ReferenceError: MediaRecorder is not defined

I am very new to webrtc, I need some suggestion to save the live stream from the browser to the server....In future, if find the blob, then I will save the blobs sequentially in a mp4 file in the server. Then, on runtime i start pressing ffmpeg in that mp4 file to get 240p, 360p, 720p ts files for hls streaming

Upvotes: 1

Views: 320

Answers (0)

Related Questions