Updated WebrtcPlayer
This commit is contained in:
@@ -158,11 +158,30 @@ const id = `${Math.random().toString(36).slice(2)}`;
|
|||||||
} else {
|
} else {
|
||||||
remoteStream.addTrack(ev.track);
|
remoteStream.addTrack(ev.track);
|
||||||
}
|
}
|
||||||
|
ev.track.onended = () => {
|
||||||
|
console.warn("🔴 Remote track ended!");
|
||||||
|
emit("disconnected", { msg: "Stream ended" });
|
||||||
|
};
|
||||||
|
|
||||||
|
ev.track.onmute = () =>
|
||||||
|
console.warn("Track muted (broadcaster may have stopped)");
|
||||||
|
ev.track.onunmute = () => console.log("Track unmuted");
|
||||||
|
|
||||||
emit("track", { kind: ev.track.kind });
|
emit("track", { kind: ev.track.kind });
|
||||||
});
|
});
|
||||||
|
|
||||||
pc.addEventListener("iceconnectionstatechange", () => {
|
pc.addEventListener("iceconnectionstatechange", () => {
|
||||||
emit("ice", { state: pc.iceConnectionState });
|
// emit("ice", { state: pc.iceConnectionState });
|
||||||
|
const state = pc.iceConnectionState;
|
||||||
|
emit("ice", { state });
|
||||||
|
console.log("ICE connection state:", state);
|
||||||
|
|
||||||
|
if (["disconnected", "failed", "closed"].includes(state)) {
|
||||||
|
console.warn(
|
||||||
|
"🔴 ICE disconnected — broadcaster likely ended stream.",
|
||||||
|
);
|
||||||
|
emit("disconnected", { msg: "Stream disconnected" });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const localCandidates = [];
|
const localCandidates = [];
|
||||||
@@ -278,11 +297,22 @@ const id = `${Math.random().toString(36).slice(2)}`;
|
|||||||
if (type === "status") showOverlay(payload.msg);
|
if (type === "status") showOverlay(payload.msg);
|
||||||
if (type === "playing") hideOverlay();
|
if (type === "playing") hideOverlay();
|
||||||
if (type === "error") showOverlay(payload.msg || payload);
|
if (type === "error") showOverlay(payload.msg || payload);
|
||||||
if (type === "disconnected") showOverlay(payload.msg);
|
if (type === "disconnected") {
|
||||||
if (type === "no-media") showOverlay("Stream not started");
|
handleStreamEnded();
|
||||||
|
showOverlay(payload.msg);
|
||||||
|
}
|
||||||
|
if (type === "no-media") {
|
||||||
|
handleStreamEnded();
|
||||||
|
showOverlay("Stream not started");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function handleStreamEnded() {
|
||||||
|
videoEl.pause();
|
||||||
|
videoEl.srcObject = null;
|
||||||
|
}
|
||||||
|
|
||||||
async function startWithRetry() {
|
async function startWithRetry() {
|
||||||
try {
|
try {
|
||||||
await player.start();
|
await player.start();
|
||||||
|
|||||||
Reference in New Issue
Block a user