host our own shit
This commit is contained in:
@@ -34,7 +34,8 @@ export class WhepClient {
|
||||
async start() {
|
||||
if (this.pc) await this.stop();
|
||||
|
||||
const pc = new RTCPeerConnection({});
|
||||
const iceServers = await this.resolveIceServers();
|
||||
const pc = new RTCPeerConnection({ iceServers });
|
||||
this.pc = pc;
|
||||
this.statsSampler = new WebRTCStatsSampler(pc, this.onStats);
|
||||
if (this.videoEl) pc.addTransceiver("video", { direction: "recvonly" });
|
||||
@@ -80,6 +81,23 @@ export class WhepClient {
|
||||
await pc.setRemoteDescription({ type: "answer", sdp: answerSDP });
|
||||
}
|
||||
|
||||
async resolveIceServers() {
|
||||
const clientId = new URLSearchParams(window.location.search).get("clientId");
|
||||
if (!clientId) return [];
|
||||
try {
|
||||
const response = await fetch(`/api/webrtc/ice-config?clientId=${encodeURIComponent(clientId)}`, {
|
||||
credentials: "same-origin",
|
||||
cache: "no-store",
|
||||
});
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const body = await response.json();
|
||||
return Array.isArray(body?.iceServers) ? body.iceServers : [];
|
||||
} catch (error) {
|
||||
console.warn("whep: failed to load self-hosted ICE configuration; using host candidates only", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async stop() {
|
||||
const pc = this.pc;
|
||||
const url = this.resourceURL;
|
||||
|
||||
Reference in New Issue
Block a user