defer actx until needed (audioplayer, uploads) and

try to be less reliant on the actx speedhack for upload performance
This commit is contained in:
ed 2022-09-07 21:08:09 +02:00
parent 590c763659
commit 8fcb2d1554
3 changed files with 59 additions and 17 deletions

View file

@ -1013,7 +1013,6 @@ function set_files_html(html) {
var ACtx = window.AudioContext || window.webkitAudioContext,
actx = ACtx && new ACtx(),
hash0 = location.hash,
mp;
@ -1907,8 +1906,36 @@ function ev_play(e) {
}
var audio_eq = (function () {
var r = {
var actx = null,
audio_eq = null;
function start_actx() {
// bonus: speedhack for unfocused file hashing (removes 1sec delay on subtle.digest resolves)
if (!actx) {
if (!ACtx)
return;
actx = new ACtx();
console.log('actx created');
}
try {
if (actx.state == 'suspended') {
actx.resume();
setTimeout(function () {
console.log('actx is ' + actx.state);
}, 500);
}
}
catch (ex) {
console.log('actx start failed; ' + ex);
}
}
function create_eq() {
if (audio_eq)
return start_actx();
var r = audio_eq = {
"en": false,
"bands": [31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000],
"gains": [4, 3, 2, 1, 0, 0, 1, 2, 3, 4],
@ -1919,6 +1946,7 @@ var audio_eq = (function () {
"acst": {}
};
start_actx();
if (!actx)
ebi('audio_eq').parentNode.style.display = 'none';
@ -2179,8 +2207,7 @@ var audio_eq = (function () {
bcfg_bind(r, 'en', 'au_eq', false, r.apply);
r.draw();
return r;
})();
}
// plays the tid'th audio file on the page
@ -2258,6 +2285,7 @@ function play(tid, is_ev, seek) {
else
mp.au.src = mp.au.rsrc = url;
create_eq();
audio_eq.apply();
setTimeout(function () {
@ -2277,12 +2305,6 @@ function play(tid, is_ev, seek) {
if (window.thegrid)
thegrid.loadsel();
try {
if (actx.state == 'suspended')
actx.resume();
}
catch (ex) { }
try {
mp.au.play();
if (mp.au.paused)
@ -6197,7 +6219,9 @@ ebi('files').onclick = ebi('docul').onclick = function (e) {
function reload_mp() {
if (mp && mp.au) {
audio_eq.stop();
if (audio_eq)
audio_eq.stop();
mp.au.pause();
mp.au = null;
mpl.unbuffer();
@ -6208,7 +6232,9 @@ function reload_mp() {
plays[a].parentNode.innerHTML = '-';
mp = new MPlayer();
audio_eq.acst = {};
if (audio_eq)
audio_eq.acst = {};
setTimeout(pbar.onresize, 1);
}

View file

@ -809,7 +809,7 @@ function up2k_init(subtle) {
bcfg_bind(uc, 'turbo', 'u2turbo', turbolvl > 1, draw_turbo, false);
bcfg_bind(uc, 'datechk', 'u2tdate', turbolvl < 3, null, false);
bcfg_bind(uc, 'az', 'u2sort', u2sort.indexOf('n') + 1, set_u2sort, false);
bcfg_bind(uc, 'hashw', 'hashw', !!window.WebAssembly && (!HTTPS || !CHROME || MOBILE), set_hashw, false);
bcfg_bind(uc, 'hashw', 'hashw', !!window.WebAssembly && (!subtle || !CHROME || MOBILE), set_hashw, false);
var st = {
"files": [],
@ -882,6 +882,7 @@ function up2k_init(subtle) {
set_fsearch();
function nav() {
start_actx();
ebi('file' + fdom_ctr).click();
}
ebi('u2btn').onclick = nav;
@ -1044,6 +1045,7 @@ function up2k_init(subtle) {
}
dst.push([fobj, fobj.name]);
}
start_actx(); // good enough for chrome; not firefox
return read_dirs(null, [], dirs, good_files, nil_files, bad_files);
}
@ -1149,6 +1151,7 @@ function up2k_init(subtle) {
msg += L.u_just1;
return modal.alert(msg, function () {
start_actx();
gotallfiles(good_files, nil_files, []);
});
}
@ -1160,8 +1163,10 @@ function up2k_init(subtle) {
msg += L.u_just1;
return modal.confirm(msg, function () {
start_actx();
gotallfiles(good_files.concat(nil_files), [], []);
}, function () {
start_actx();
gotallfiles(good_files, [], []);
});
}
@ -1178,14 +1183,16 @@ function up2k_init(subtle) {
if (uc.ask_up && !uc.fsearch)
return modal.confirm(msg.join('') + '</ul>', function () {
start_actx();
up_them(good_files);
toast.inf(15, L.u_unpt);
toast.inf(15, L.u_unpt, L.u_unpt);
}, null);
up_them(good_files);
}
function up_them(good_files) {
start_actx();
var evpath = get_evpath(),
draw_each = good_files.length < 50;
@ -1267,6 +1274,13 @@ function up2k_init(subtle) {
pvis.changecard(pvis.act);
}
ebi('u2tabw').className = 'ye';
setTimeout(function () {
if (!actx || actx.state != 'suspended' || toast.tag == L.u_unpt)
return;
toast.warn(30, "<div onclick=\"start_actx();toast.inf(3,'thanks!')\">please click this text to<br />unlock full upload speed</div>");
}, 500);
}
function more_one_file() {
@ -1485,6 +1499,7 @@ function up2k_init(subtle) {
if (!is_busy) {
uptoast();
//throw console.hist.join('\n');
}
else {
timer.add(donut.do);
@ -1706,7 +1721,8 @@ function up2k_init(subtle) {
pvis.setab(t.n, nchunks);
pvis.move(t.n, 'bz');
if (nchunks > 1 && hws.length && uc.hashw)
if (hws.length && uc.hashw && (nchunks > 1 || document.visibilityState == 'hidden'))
// resolving subtle.digest w/o worker takes 1sec on blur if the actx hack breaks
return wexec_hash(t, chunksize, nchunks);
var segm_next = function () {

View file

@ -134,7 +134,7 @@ function vis_exh(msg, url, lineNo, columnNo, error) {
'<h1>you hit a bug!</h1>',
'<p style="font-size:1.3em;margin:0">try to <a href="#" onclick="localStorage.clear();location.reload();">reset copyparty settings</a> if you are stuck here, or <a href="#" onclick="ignex();">ignore this</a> / <a href="#" onclick="ignex(true);">ignore all</a></p>',
'<p style="color:#fff">please send me a screenshot arigathanks gozaimuch: <a href="<ghi>" target="_blank">github issue</a> or <code>ed#2644</code></p>',
'<p class="b">' + esc(url + ' @' + lineNo + ':' + columnNo), '<br />' + esc(String(msg)) + '</p>',
'<p class="b">' + esc(url + ' @' + lineNo + ':' + columnNo), '<br />' + esc(String(msg)).replace(/\n/g, '<br />') + '</p>',
'<p><b>UA:</b> ' + esc(navigator.userAgent + '')
];