WebRTC Implementation for TypeScript (Node.js), includes ICE/DTLS/SCTP/RTP/SRTP/WEBM/MP4
Video and Audio can be saved to a webm file using Node.js alone, without the need for gStreamer.
example
import { MediaRecorder, RTCPeerConnection } from "werift";
import { Server } from "ws";
// open ./answer.html
const server = new Server({ port: 8888 });
console.log("start");
server.on("connection", async (socket) => {
const recorder = new MediaRecorder([], "./test.webm", {
width: 640,
height: 360,
});
const pc = new RTCPeerConnection();
{
const transceiver = pc.addTransceiver("video");
transceiver.onTrack.subscribe((track) => {
recorder.addTrack(track);
if (recorder.tracks.length === 2) {
recorder.start();
}
setInterval(() => {
transceiver.receiver.sendRtcpPLI(track.ssrc);
}, 15_000);
});
}
{
const transceiver = pc.addTransceiver("audio");
transceiver.onTrack.subscribe((track) => {
recorder.addTrack(track);
if (recorder.tracks.length === 2) {
recorder.start();
}
});
}
await pc.setLocalDescription(await pc.createOffer());
const sdp = JSON.stringify(pc.localDescription);
socket.send(sdp);
socket.on("message", (data: any) => {
pc.setRemoteDescription(JSON.parse(data));
});
});
Example
const peer = new RTCPeerConnection({ icePortRange: [44444, 44455] });
Minimum port and Maximum port must not be the same value