FIXA-懒得写了

This commit is contained in:
CN-JS-HuiBai
2026-04-02 22:54:46 +08:00
parent 92e7a80a1e
commit 52c8466ddd
3 changed files with 89 additions and 28 deletions

View File

@@ -110,6 +110,21 @@ document.addEventListener('DOMContentLoaded', () => {
}
};
const createStreamSessionId = () => `${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;
const buildStreamUrl = (targetSeconds = null) => {
const codec = codecSelect?.value || 'h264';
const encoder = encoderSelect?.value || 'software';
const streamSessionId = createStreamSessionId();
let streamUrl = `/api/stream?bucket=${encodeURIComponent(selectedBucket)}&key=${encodeURIComponent(selectedKey)}&codec=${encodeURIComponent(codec)}&encoder=${encodeURIComponent(encoder)}&streamSessionId=${encodeURIComponent(streamSessionId)}`;
if (typeof targetSeconds === 'number' && Number.isFinite(targetSeconds) && targetSeconds > 0) {
streamUrl += `&ss=${targetSeconds}`;
}
if (s3Username) streamUrl += `&username=${encodeURIComponent(s3Username)}`;
if (s3Password) streamUrl += `&password=${encodeURIComponent(s3Password)}`;
return streamUrl;
};
const updatePlayControls = () => {
if (controlPlayToggle) {
controlPlayToggle.textContent = videoPlayer.paused ? 'Play' : 'Pause';
@@ -510,11 +525,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
// Build new stream URL with ss parameter
const codec = codecSelect?.value || 'h264';
const encoder = encoderSelect?.value || 'software';
let streamUrl = `/api/stream?bucket=${encodeURIComponent(selectedBucket)}&key=${encodeURIComponent(selectedKey)}&codec=${encodeURIComponent(codec)}&encoder=${encodeURIComponent(encoder)}&ss=${targetSeconds}`;
if (s3Username) streamUrl += `&username=${encodeURIComponent(s3Username)}`;
if (s3Password) streamUrl += `&password=${encodeURIComponent(s3Password)}`;
const streamUrl = buildStreamUrl(targetSeconds);
// Changing src automatically aborts the previous HTTP request,
// which triggers res.on('close') on the server, killing the old ffmpeg process
@@ -876,9 +887,7 @@ document.addEventListener('DOMContentLoaded', () => {
const codec = codecSelect?.value || 'h264';
const encoder = encoderSelect?.value || 'software';
if (!selectedBucket) throw new Error('No bucket selected');
let streamUrl = `/api/stream?bucket=${encodeURIComponent(selectedBucket)}&key=${encodeURIComponent(selectedKey)}&codec=${encodeURIComponent(codec)}&encoder=${encodeURIComponent(encoder)}`;
if (s3Username) streamUrl += `&username=${encodeURIComponent(s3Username)}`;
if (s3Password) streamUrl += `&password=${encodeURIComponent(s3Password)}`;
const streamUrl = buildStreamUrl();
videoPlayer.src = streamUrl;
videoPlayer.load();
videoPlayer.addEventListener('loadedmetadata', () => {