I am trying to make use of the MediaStream object (from node-webrtc, which works like browser API).
The problem is, that there is no MediaRecorder available in the Node environment.
I use Janode to connect to the Janus WebRTC server and get the live stream. I then set up WebRTC and have it ready to stream and track objects.
How can I save them to file as with MediaRecorder? I prefer blob first, but it can be straight to file.
import express from "express";
import { createServer as create HTTP server } from "HTTP";
import Janode from "janode";
import StreamingPlugin from "janode/plugins/streaming";
import wrtc from "wrtc";
const { RTCPeerConnection, RTCSessionDescription, MediaStream } = wrtc;
const app = express();
const connection = await Janode.connect({
is_admin: false,
address: {
url: "janusServerUrl",
apisecret: "secret",
},
});
const session = await connection.create();
const streamingHandle = await session.attach(StreamingPlugin);
const peerConnection = new RTCPeerConnection();
peerConnection.ontrack = (event) => {
if (event.track.kind != "video") return;
const stream = new MediaStream();
stream.addTrack(event.track)
}
const { jsep, restart = false } = await streamingHandle.watch({ id: 1 });
await peerConnection.setRemoteDescription(new RTCSessionDescription(jsep));
const answer = await peerConnection.createAnswer();
await peerConnection.setLocalDescription(answer);
I have tried Puppeteer, and it works, but I still want to do it in a Node environment to reduce workload.