defer actx until needed (audioplayer, uploads) and
try to be less reliant on the actx speedhack for upload performance
This commit is contained in:
		
							parent
							
								
									590c763659
								
							
						
					
					
						commit
						8fcb2d1554
					
				| @ -1013,7 +1013,6 @@ function set_files_html(html) { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| var ACtx = window.AudioContext || window.webkitAudioContext, | var ACtx = window.AudioContext || window.webkitAudioContext, | ||||||
| 	actx = ACtx && new ACtx(), |  | ||||||
| 	hash0 = location.hash, | 	hash0 = location.hash, | ||||||
| 	mp; | 	mp; | ||||||
| 
 | 
 | ||||||
| @ -1907,8 +1906,36 @@ function ev_play(e) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| var audio_eq = (function () { | var actx = null, | ||||||
| 	var r = { | 	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, | 		"en": false, | ||||||
| 		"bands": [31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000], | 		"bands": [31.25, 62.5, 125, 250, 500, 1000, 2000, 4000, 8000, 16000], | ||||||
| 		"gains": [4, 3, 2, 1, 0, 0, 1, 2, 3, 4], | 		"gains": [4, 3, 2, 1, 0, 0, 1, 2, 3, 4], | ||||||
| @ -1919,6 +1946,7 @@ var audio_eq = (function () { | |||||||
| 		"acst": {} | 		"acst": {} | ||||||
| 	}; | 	}; | ||||||
| 
 | 
 | ||||||
|  | 	start_actx(); | ||||||
| 	if (!actx) | 	if (!actx) | ||||||
| 		ebi('audio_eq').parentNode.style.display = 'none'; | 		ebi('audio_eq').parentNode.style.display = 'none'; | ||||||
| 
 | 
 | ||||||
| @ -2179,8 +2207,7 @@ var audio_eq = (function () { | |||||||
| 	bcfg_bind(r, 'en', 'au_eq', false, r.apply); | 	bcfg_bind(r, 'en', 'au_eq', false, r.apply); | ||||||
| 
 | 
 | ||||||
| 	r.draw(); | 	r.draw(); | ||||||
| 	return r; | } | ||||||
| })(); |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| // plays the tid'th audio file on the page
 | // plays the tid'th audio file on the page
 | ||||||
| @ -2258,6 +2285,7 @@ function play(tid, is_ev, seek) { | |||||||
| 	else | 	else | ||||||
| 		mp.au.src = mp.au.rsrc = url; | 		mp.au.src = mp.au.rsrc = url; | ||||||
| 
 | 
 | ||||||
|  | 	create_eq(); | ||||||
| 	audio_eq.apply(); | 	audio_eq.apply(); | ||||||
| 
 | 
 | ||||||
| 	setTimeout(function () { | 	setTimeout(function () { | ||||||
| @ -2277,12 +2305,6 @@ function play(tid, is_ev, seek) { | |||||||
| 	if (window.thegrid) | 	if (window.thegrid) | ||||||
| 		thegrid.loadsel(); | 		thegrid.loadsel(); | ||||||
| 
 | 
 | ||||||
| 	try { |  | ||||||
| 		if (actx.state == 'suspended') |  | ||||||
| 			actx.resume(); |  | ||||||
| 	} |  | ||||||
| 	catch (ex) { } |  | ||||||
| 
 |  | ||||||
| 	try { | 	try { | ||||||
| 		mp.au.play(); | 		mp.au.play(); | ||||||
| 		if (mp.au.paused) | 		if (mp.au.paused) | ||||||
| @ -6197,7 +6219,9 @@ ebi('files').onclick = ebi('docul').onclick = function (e) { | |||||||
| 
 | 
 | ||||||
| function reload_mp() { | function reload_mp() { | ||||||
| 	if (mp && mp.au) { | 	if (mp && mp.au) { | ||||||
|  | 		if (audio_eq) | ||||||
| 			audio_eq.stop(); | 			audio_eq.stop(); | ||||||
|  | 
 | ||||||
| 		mp.au.pause(); | 		mp.au.pause(); | ||||||
| 		mp.au = null; | 		mp.au = null; | ||||||
| 		mpl.unbuffer(); | 		mpl.unbuffer(); | ||||||
| @ -6208,7 +6232,9 @@ function reload_mp() { | |||||||
| 		plays[a].parentNode.innerHTML = '-'; | 		plays[a].parentNode.innerHTML = '-'; | ||||||
| 
 | 
 | ||||||
| 	mp = new MPlayer(); | 	mp = new MPlayer(); | ||||||
|  | 	if (audio_eq) | ||||||
| 		audio_eq.acst = {}; | 		audio_eq.acst = {}; | ||||||
|  | 
 | ||||||
| 	setTimeout(pbar.onresize, 1); | 	setTimeout(pbar.onresize, 1); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -809,7 +809,7 @@ function up2k_init(subtle) { | |||||||
|     bcfg_bind(uc, 'turbo', 'u2turbo', turbolvl > 1, draw_turbo, false); |     bcfg_bind(uc, 'turbo', 'u2turbo', turbolvl > 1, draw_turbo, false); | ||||||
|     bcfg_bind(uc, 'datechk', 'u2tdate', turbolvl < 3, null, 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, '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 = { |     var st = { | ||||||
|         "files": [], |         "files": [], | ||||||
| @ -882,6 +882,7 @@ function up2k_init(subtle) { | |||||||
|     set_fsearch(); |     set_fsearch(); | ||||||
| 
 | 
 | ||||||
|     function nav() { |     function nav() { | ||||||
|  |         start_actx(); | ||||||
|         ebi('file' + fdom_ctr).click(); |         ebi('file' + fdom_ctr).click(); | ||||||
|     } |     } | ||||||
|     ebi('u2btn').onclick = nav; |     ebi('u2btn').onclick = nav; | ||||||
| @ -1044,6 +1045,7 @@ function up2k_init(subtle) { | |||||||
|             } |             } | ||||||
|             dst.push([fobj, fobj.name]); |             dst.push([fobj, fobj.name]); | ||||||
|         } |         } | ||||||
|  |         start_actx();  // good enough for chrome; not firefox
 | ||||||
|         return read_dirs(null, [], dirs, good_files, nil_files, bad_files); |         return read_dirs(null, [], dirs, good_files, nil_files, bad_files); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -1149,6 +1151,7 @@ function up2k_init(subtle) { | |||||||
| 
 | 
 | ||||||
|             msg += L.u_just1; |             msg += L.u_just1; | ||||||
|             return modal.alert(msg, function () { |             return modal.alert(msg, function () { | ||||||
|  |                 start_actx(); | ||||||
|                 gotallfiles(good_files, nil_files, []); |                 gotallfiles(good_files, nil_files, []); | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
| @ -1160,8 +1163,10 @@ function up2k_init(subtle) { | |||||||
| 
 | 
 | ||||||
|             msg += L.u_just1; |             msg += L.u_just1; | ||||||
|             return modal.confirm(msg, function () { |             return modal.confirm(msg, function () { | ||||||
|  |                 start_actx(); | ||||||
|                 gotallfiles(good_files.concat(nil_files), [], []); |                 gotallfiles(good_files.concat(nil_files), [], []); | ||||||
|             }, function () { |             }, function () { | ||||||
|  |                 start_actx(); | ||||||
|                 gotallfiles(good_files, [], []); |                 gotallfiles(good_files, [], []); | ||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
| @ -1178,14 +1183,16 @@ function up2k_init(subtle) { | |||||||
| 
 | 
 | ||||||
|         if (uc.ask_up && !uc.fsearch) |         if (uc.ask_up && !uc.fsearch) | ||||||
|             return modal.confirm(msg.join('') + '</ul>', function () { |             return modal.confirm(msg.join('') + '</ul>', function () { | ||||||
|  |                 start_actx(); | ||||||
|                 up_them(good_files); |                 up_them(good_files); | ||||||
|                 toast.inf(15, L.u_unpt); |                 toast.inf(15, L.u_unpt, L.u_unpt); | ||||||
|             }, null); |             }, null); | ||||||
| 
 | 
 | ||||||
|         up_them(good_files); |         up_them(good_files); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     function up_them(good_files) { |     function up_them(good_files) { | ||||||
|  |         start_actx(); | ||||||
|         var evpath = get_evpath(), |         var evpath = get_evpath(), | ||||||
|             draw_each = good_files.length < 50; |             draw_each = good_files.length < 50; | ||||||
| 
 | 
 | ||||||
| @ -1267,6 +1274,13 @@ function up2k_init(subtle) { | |||||||
|             pvis.changecard(pvis.act); |             pvis.changecard(pvis.act); | ||||||
|         } |         } | ||||||
|         ebi('u2tabw').className = 'ye'; |         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() { |     function more_one_file() { | ||||||
| @ -1485,6 +1499,7 @@ function up2k_init(subtle) { | |||||||
| 
 | 
 | ||||||
|                     if (!is_busy) { |                     if (!is_busy) { | ||||||
|                         uptoast(); |                         uptoast(); | ||||||
|  |                         //throw console.hist.join('\n');
 | ||||||
|                     } |                     } | ||||||
|                     else { |                     else { | ||||||
|                         timer.add(donut.do); |                         timer.add(donut.do); | ||||||
| @ -1706,7 +1721,8 @@ function up2k_init(subtle) { | |||||||
|         pvis.setab(t.n, nchunks); |         pvis.setab(t.n, nchunks); | ||||||
|         pvis.move(t.n, 'bz'); |         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); |             return wexec_hash(t, chunksize, nchunks); | ||||||
| 
 | 
 | ||||||
|         var segm_next = function () { |         var segm_next = function () { | ||||||
|  | |||||||
| @ -134,7 +134,7 @@ function vis_exh(msg, url, lineNo, columnNo, error) { | |||||||
|         '<h1>you hit a bug!</h1>', |         '<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="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 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 + '') |         '<p><b>UA:</b> ' + esc(navigator.userAgent + '') | ||||||
|     ]; |     ]; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 ed
						ed