misc
This commit is contained in:
@@ -15,14 +15,11 @@
|
|||||||
region: 'us-east',
|
region: 'us-east',
|
||||||
url: 'https://us.stream.holopirates.moe',
|
url: 'https://us.stream.holopirates.moe',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
region: 'us-east-2',
|
|
||||||
url: 'https://www.kitsu.red',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
region: 'sg',
|
region: 'sg',
|
||||||
url: 'https://restream.kitsune.box.ca',
|
url: 'https://restream.kitsune.box.ca',
|
||||||
},
|
},
|
||||||
|
/*
|
||||||
{
|
{
|
||||||
region: 'eu',
|
region: 'eu',
|
||||||
url: 'https://eu.stream.holopirates.moe',
|
url: 'https://eu.stream.holopirates.moe',
|
||||||
@@ -31,8 +28,9 @@
|
|||||||
region: 'jp',
|
region: 'jp',
|
||||||
url: 'https://jp.stream.holopirates.moe',
|
url: 'https://jp.stream.holopirates.moe',
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
],
|
],
|
||||||
playlist: '/misc/stream/dance/index.m3u8',
|
playlist: '/index.m3u8',
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
+35
-11
@@ -42,6 +42,13 @@
|
|||||||
return results.reduce((a, b) => a + b, 0) / count;
|
return results.reduce((a, b) => a + b, 0) / count;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const measureUpstreamLatency = async (upstream, n = 3) => {
|
||||||
|
const playlistURL = upstream.url + window.restream_config.playlist;
|
||||||
|
const latency = await measureLatency(playlistURL, n);
|
||||||
|
upstream.latency = latency;
|
||||||
|
updateMirrorList();
|
||||||
|
};
|
||||||
|
|
||||||
const updateMirrorList = () => {
|
const updateMirrorList = () => {
|
||||||
const mirrorSelect = document.getElementById('mirror-select');
|
const mirrorSelect = document.getElementById('mirror-select');
|
||||||
const current = mirrorSelect.value;
|
const current = mirrorSelect.value;
|
||||||
@@ -56,8 +63,7 @@
|
|||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = upstream.url;
|
option.value = upstream.url;
|
||||||
option.text =
|
option.text =
|
||||||
`[${upstream.region}] ${upstream.url}` +
|
`[${upstream.region}] ${upstream.url} (` +
|
||||||
'(' +
|
|
||||||
[
|
[
|
||||||
typeof upstream.latency === 'number'
|
typeof upstream.latency === 'number'
|
||||||
? Math.floor(upstream.latency) + 'ms'
|
? Math.floor(upstream.latency) + 'ms'
|
||||||
@@ -136,14 +142,25 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const latencyMeasurementLoop = async () => {
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
for (const upstream of window.restream_config.upstreams) {
|
||||||
|
await measureUpstreamLatency(upstream, 1);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
await sleep(10000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
const video = document.getElementById('video');
|
const video = document.getElementById('video');
|
||||||
const mirrorSelect = document.getElementById('mirror-select');
|
const mirrorSelect = document.getElementById('mirror-select');
|
||||||
const mirrorPopup = document.getElementById('mirror-popup');
|
const mirrorPopup = document.getElementById('mirror-popup');
|
||||||
const mirrorLoadProgress = document.getElementById('mirror-load-progress');
|
const mirrorLoadProgress = document.getElementById('mirror-load-progress');
|
||||||
|
const { upstreams } = window.restream_config;
|
||||||
// Init viewer counter
|
|
||||||
viewCountLoop();
|
|
||||||
|
|
||||||
// Set up hls.js
|
// Set up hls.js
|
||||||
if (Hls.isSupported()) {
|
if (Hls.isSupported()) {
|
||||||
@@ -154,15 +171,11 @@
|
|||||||
// Set up event listeners
|
// Set up event listeners
|
||||||
mirrorSelect.addEventListener('change', () => reloadVideo());
|
mirrorSelect.addEventListener('change', () => reloadVideo());
|
||||||
|
|
||||||
const { upstreams } = window.restream_config;
|
// Measure latency
|
||||||
|
|
||||||
let n = 0;
|
let n = 0;
|
||||||
for (const upstream of upstreams) {
|
for (const upstream of upstreams) {
|
||||||
n += 1;
|
n += 1;
|
||||||
const playlistURL = upstream.url + window.restream_config.playlist;
|
await measureUpstreamLatency(upstream);
|
||||||
const latency = await measureLatency(playlistURL, 3);
|
|
||||||
upstream.latency = latency;
|
|
||||||
updateMirrorList();
|
|
||||||
mirrorLoadProgress.innerText = '(' + n + '/' + upstreams.length + ')';
|
mirrorLoadProgress.innerText = '(' + n + '/' + upstreams.length + ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,6 +183,13 @@
|
|||||||
const upstream = upstreams
|
const upstream = upstreams
|
||||||
.filter((upstream) => typeof upstream.latency === 'number')
|
.filter((upstream) => typeof upstream.latency === 'number')
|
||||||
.sort((a, b) => a.latency - b.latency)[0];
|
.sort((a, b) => a.latency - b.latency)[0];
|
||||||
|
|
||||||
|
if (!upstream) {
|
||||||
|
document.querySelector('#mirror-popup .popup-box').innerText =
|
||||||
|
'No upstream servers found';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mirrorSelect.value = upstream.url;
|
mirrorSelect.value = upstream.url;
|
||||||
reloadVideo();
|
reloadVideo();
|
||||||
|
|
||||||
@@ -179,6 +199,10 @@
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
mirrorPopup.remove();
|
mirrorPopup.remove();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
// Init loops
|
||||||
|
viewCountLoop();
|
||||||
|
latencyMeasurementLoop();
|
||||||
};
|
};
|
||||||
|
|
||||||
if (document.readyState === 'loading')
|
if (document.readyState === 'loading')
|
||||||
|
|||||||
@@ -128,6 +128,11 @@ mkdir -p /var/cache/nginx/proxy_cache
|
|||||||
# create the nginx config file
|
# create the nginx config file
|
||||||
echo "Setting up nginx"
|
echo "Setting up nginx"
|
||||||
cat <<EOF > /etc/nginx/cors.conf
|
cat <<EOF > /etc/nginx/cors.conf
|
||||||
|
proxy_hide_header 'Access-Control-Allow-Origin';
|
||||||
|
proxy_hide_header 'Access-Control-Allow-Methods';
|
||||||
|
proxy_hide_header 'Access-Control-Allow-Headers';
|
||||||
|
proxy_hide_header 'Access-Control-Expose-Headers';
|
||||||
|
|
||||||
if (\$request_method = 'OPTIONS') {
|
if (\$request_method = 'OPTIONS') {
|
||||||
add_header 'Access-Control-Allow-Origin' '*';
|
add_header 'Access-Control-Allow-Origin' '*';
|
||||||
add_header 'Access-Control-Allow-Methods' 'HEAD, GET, POST, OPTIONS';
|
add_header 'Access-Control-Allow-Methods' 'HEAD, GET, POST, OPTIONS';
|
||||||
@@ -243,6 +248,7 @@ http {
|
|||||||
proxy_pass $upstream_server;
|
proxy_pass $upstream_server;
|
||||||
|
|
||||||
location ~ \.(m3u8|mpd)$ {
|
location ~ \.(m3u8|mpd)$ {
|
||||||
|
include /etc/nginx/cors.conf;
|
||||||
rewrite ^(.*)$ $upstream_base\$1 break;
|
rewrite ^(.*)$ $upstream_base\$1 break;
|
||||||
proxy_cache_valid any 1s;
|
proxy_cache_valid any 1s;
|
||||||
proxy_pass $upstream_server;
|
proxy_pass $upstream_server;
|
||||||
|
|||||||
Reference in New Issue
Block a user