major remote desktop upgrades + do opus. Hopefully all the tests pass 😭
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { WebRTCStatsSampler } from "./webrtc-stats.js";
|
||||
|
||||
// Tiny WHEP (WebRTC-HTTP Egress Protocol) client.
|
||||
//
|
||||
// Wires a <video> element to a server-proxied WHEP endpoint:
|
||||
@@ -16,14 +18,17 @@ export class WhepClient {
|
||||
* @param {HTMLAudioElement} [opts.audioEl] Attach the audio track here.
|
||||
* Default: hidden <audio> appended to <body>.
|
||||
* @param {(state: string) => void} [opts.onState]
|
||||
* @param {(stats: object) => void} [opts.onStats]
|
||||
*/
|
||||
constructor(opts) {
|
||||
this.whepPath = opts.whepPath;
|
||||
this.videoEl = opts.videoEl || null;
|
||||
this.audioEl = opts.audioEl || null;
|
||||
this.onState = opts.onState || (() => {});
|
||||
this.onStats = opts.onStats || (() => {});
|
||||
this.pc = null;
|
||||
this.resourceURL = "";
|
||||
this.statsSampler = null;
|
||||
}
|
||||
|
||||
async start() {
|
||||
@@ -31,6 +36,7 @@ export class WhepClient {
|
||||
|
||||
const pc = new RTCPeerConnection({});
|
||||
this.pc = pc;
|
||||
this.statsSampler = new WebRTCStatsSampler(pc, this.onStats);
|
||||
if (this.videoEl) pc.addTransceiver("video", { direction: "recvonly" });
|
||||
if (this.audioEl) pc.addTransceiver("audio", { direction: "recvonly" });
|
||||
|
||||
@@ -46,6 +52,8 @@ export class WhepClient {
|
||||
};
|
||||
pc.onconnectionstatechange = () => {
|
||||
this.onState(pc.connectionState);
|
||||
if (pc.connectionState === "connected") this.statsSampler?.start();
|
||||
if (["failed", "closed", "disconnected"].includes(pc.connectionState)) this.statsSampler?.stop();
|
||||
};
|
||||
|
||||
const offer = await pc.createOffer();
|
||||
@@ -76,6 +84,8 @@ export class WhepClient {
|
||||
const pc = this.pc;
|
||||
const url = this.resourceURL;
|
||||
this.pc = null;
|
||||
this.statsSampler?.stop();
|
||||
this.statsSampler = null;
|
||||
this.resourceURL = "";
|
||||
if (url) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user