mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-07-31 08:19:16 +02:00
go back to non reader.js
This commit is contained in:
@@ -167,14 +167,12 @@
|
|||||||
#keybinds {display: none;}
|
#keybinds {display: none;}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script defer src="./reader.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div style="display:flex;align-items:center;justify-content:space-between;">
|
<div style="display:flex;align-items:center;justify-content:space-between;">
|
||||||
<div>
|
<div>
|
||||||
<h1>RadioPlayer status</h1>
|
<h1>RadioPlayer status <noscript> - NO SCRIPTING - </noscript></h1>
|
||||||
<noscript><h1> - NO SCRIPTING - </h1></noscript>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+44
-51
@@ -340,7 +340,7 @@ document.addEventListener("keydown", e => {
|
|||||||
else if (e.key.toLowerCase() === "j") ws.send(JSON.stringify({action:"jingle", top: e.shiftKey}));
|
else if (e.key.toLowerCase() === "j") ws.send(JSON.stringify({action:"jingle", top: e.shiftKey}));
|
||||||
});
|
});
|
||||||
|
|
||||||
let whepReader = null;
|
let whepPc = null;
|
||||||
let whepAudio = null;
|
let whepAudio = null;
|
||||||
let whepConnected = false;
|
let whepConnected = false;
|
||||||
|
|
||||||
@@ -375,24 +375,14 @@ function whepSetVol(v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function whepToggle() {
|
function whepToggle() {
|
||||||
if(whepConnected) whepDisconnect();
|
if (whepConnected || whepPc) { whepDisconnect(); return; }
|
||||||
else whepConnect();
|
whepConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
function whepDisconnect() {
|
function whepDisconnect() {
|
||||||
whepConnected = false;
|
whepConnected = false;
|
||||||
|
if (whepPc) { try { whepPc.close(); } catch(e){} whepPc = null; }
|
||||||
if (whepReader) {
|
if (whepAudio) { whepAudio.pause(); whepAudio.srcObject = null; whepAudio = null; }
|
||||||
try { whepReader.stop(); } catch(e){}
|
|
||||||
whepReader = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (whepAudio) {
|
|
||||||
whepAudio.pause();
|
|
||||||
whepAudio.srcObject = null;
|
|
||||||
whepAudio = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
whepSetDot('idle');
|
whepSetDot('idle');
|
||||||
whepLog('Disconnected');
|
whepLog('Disconnected');
|
||||||
}
|
}
|
||||||
@@ -400,52 +390,55 @@ function whepDisconnect() {
|
|||||||
async function whepConnect() {
|
async function whepConnect() {
|
||||||
const url = document.getElementById('whep-url-input').value.trim();
|
const url = document.getElementById('whep-url-input').value.trim();
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
|
|
||||||
whepSetDot('connecting');
|
whepSetDot('connecting');
|
||||||
whepLog('Starting MediaMTX reader…');
|
whepLog('Creating peer connection…');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
whepReader = new MediaMTXWebRTCReader({
|
whepPc = new RTCPeerConnection();
|
||||||
url: url,
|
whepPc.ontrack = (e) => {
|
||||||
|
whepLog('Track received, starting playback', 'ok');
|
||||||
onTrack: (evt) => {
|
whepAudio = new Audio();
|
||||||
if(evt.track.kind !== "audio") return;
|
whepAudio.srcObject = e.streams[0];
|
||||||
whepLog('Track received, starting playback', 'ok');
|
whepAudio.volume = parseFloat(document.getElementById('whep-vol').value);
|
||||||
|
whepAudio.play().then(() => {
|
||||||
whepAudio = new Audio();
|
whepLog('Audio playing', 'ok');
|
||||||
whepAudio.srcObject = evt.streams[0];
|
whepConnected = true;
|
||||||
whepAudio.volume = parseFloat(document.getElementById('whep-vol').value);
|
whepSetDot('connected');
|
||||||
|
}).catch(() => {
|
||||||
whepAudio.play().then(() => {
|
whepLog('Autoplay blocked — click anywhere to resume', 'err');
|
||||||
whepLog('Audio playing', 'ok');
|
document.addEventListener('click', () => whepAudio && whepAudio.play(), { once: true });
|
||||||
whepConnected = true;
|
});
|
||||||
whepSetDot('connected');
|
};
|
||||||
}).catch(() => {
|
whepPc.onconnectionstatechange = () => {
|
||||||
whepLog('Autoplay blocked — click anywhere', 'err');
|
whepLog('State: ' + whepPc.connectionState);
|
||||||
document.addEventListener('click', () => whepAudio?.play(), { once: true });
|
if (whepPc.connectionState === 'failed' || whepPc.connectionState === 'disconnected') {
|
||||||
});
|
whepLog('Connection lost', 'err');
|
||||||
},
|
|
||||||
|
|
||||||
onError: (err) => {
|
|
||||||
whepLog('Error: ' + err, 'err');
|
|
||||||
whepDisconnect();
|
whepDisconnect();
|
||||||
whepSetDot('error');
|
whepSetDot('error');
|
||||||
},
|
|
||||||
|
|
||||||
onStateChange: (state) => {
|
|
||||||
whepLog('State: ' + state);
|
|
||||||
if (state === 'closed') whepDisconnect();
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
whepPc.oniceconnectionstatechange = () => whepLog('ICE: ' + whepPc.iceConnectionState);
|
||||||
|
whepPc.addTransceiver('audio', { direction: 'recvonly' });
|
||||||
|
const offer = await whepPc.createOffer();
|
||||||
|
offer.sdp = offer.sdp
|
||||||
|
.replace(/useinbandfec=1/g, 'useinbandfec=1;stereo=1;sprop-stereo=1')
|
||||||
|
.replace(/minptime=10/g, 'minptime=10;ptime=10;maxptime=10');
|
||||||
|
await whepPc.setLocalDescription(offer);
|
||||||
|
whepLog('Sending offer to ' + url);
|
||||||
|
const resp = await fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/sdp', 'Accept': 'application/sdp' },
|
||||||
|
body: whepPc.localDescription.sdp
|
||||||
});
|
});
|
||||||
|
if (!resp.ok) throw new Error(`Server returned ${resp.status} ${resp.statusText}`);
|
||||||
whepLog('Reader started, waiting for media…');
|
const answerSdp = await resp.text();
|
||||||
|
whepLog(`Got SDP answer (${answerSdp.length} bytes)`, 'ok');
|
||||||
} catch (err) {
|
await whepPc.setRemoteDescription({ type: 'answer', sdp: answerSdp });
|
||||||
|
whepLog('Waiting for ICE + track…');
|
||||||
|
} catch(err) {
|
||||||
whepLog('Error: ' + err.message, 'err');
|
whepLog('Error: ' + err.message, 'err');
|
||||||
whepDisconnect();
|
whepDisconnect();
|
||||||
whepSetDot('error');
|
whepSetDot('error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initLayout();
|
initLayout();
|
||||||
setTimeout(connectWs, 100);
|
setTimeout(connectWs, 100);
|
||||||
Reference in New Issue
Block a user