Spaces:
Paused
Paused
Download server.js from veltrixcode/GCX: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/spaces/veltrixcode/GCX/resolve/450fbb040a3ec3ada4630b67ebd4a3d138f999fc/server.js
- Command line
-
hf download hf://spaces/veltrixcode/GCX@450fbb040a3ec3ada4630b67ebd4a3d138f999fc/server.js
-
curl -L -o server.js https://huggingface.co/spaces/veltrixcode/GCX/resolve/450fbb040a3ec3ada4630b67ebd4a3d138f999fc/server.js
1.34 kB
| import express from "express"; | |
| import http from "http"; | |
| import mediasoup from "mediasoup"; | |
| const app = express(); | |
| app.use(express.json()); | |
| const worker = await mediasoup.createWorker(); | |
| const router = await worker.createRouter({ | |
| mediaCodecs: [{ | |
| kind: "video", | |
| mimeType: "video/H264", | |
| clockRate: 90000, | |
| parameters: { "packetization-mode": 1, "profile-level-id": "42e01f" } | |
| }] | |
| }); | |
| let producer; | |
| app.post("/whip", async (req, res) => { | |
| const transport = await router.createWebRtcTransport({ | |
| listenIps: [{ ip: "0.0.0.0", announcedIp: null }], | |
| enableUdp: true, enableTcp: true, preferUdp: true | |
| }); | |
| const sdp = req.body.sdp; | |
| await transport.connect({ dtlsParameters: sdp.dtlsParameters }); | |
| producer = await transport.produce({ | |
| kind: "video", | |
| rtpParameters: sdp.rtpParameters | |
| }); | |
| res.json({ ok: true }); | |
| }); | |
| app.get("/whep", async (req, res) => { | |
| if (!producer) return res.status(404).send("No stream"); | |
| const transport = await router.createWebRtcTransport({ | |
| listenIps: [{ ip: "0.0.0.0", announcedIp: null }], | |
| enableUdp: true, enableTcp: true, preferUdp: true | |
| }); | |
| const consumer = await transport.consume({ | |
| producerId: producer.id, | |
| rtpCapabilities: router.rtpCapabilities, | |
| paused: false | |
| }); | |
| res.json({ consumer }); | |
| }); | |
| http.createServer(app).listen(3000); | |