mirror of
https://github.com/Dangoware/confetti-box.git
synced 2025-04-19 23:32:58 -05:00
Added wake lock for uploading to prevent failures
This commit is contained in:
parent
8514c52e93
commit
0932f6ec31
1 changed files with 17 additions and 0 deletions
|
@ -61,7 +61,20 @@ async function sendFiles(files, duration, maxSize) {
|
||||||
const inProgressUploads = new Set();
|
const inProgressUploads = new Set();
|
||||||
const concurrencyLimit = 10;
|
const concurrencyLimit = 10;
|
||||||
|
|
||||||
|
// Create a reference for the Wake Lock.
|
||||||
|
let wakeLock = null;
|
||||||
|
|
||||||
|
// create an async function to request a wake lock
|
||||||
|
try {
|
||||||
|
wakeLock = await navigator.wakeLock.request("screen");
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Failed to set wake-lock!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
console.log("Started upload for", file.name);
|
||||||
|
|
||||||
// Start the upload and add it to the set of in-progress uploads
|
// Start the upload and add it to the set of in-progress uploads
|
||||||
const uploadPromise = uploadFile(file, duration, maxSize);
|
const uploadPromise = uploadFile(file, duration, maxSize);
|
||||||
inProgressUploads.add(uploadPromise);
|
inProgressUploads.add(uploadPromise);
|
||||||
|
@ -77,6 +90,10 @@ async function sendFiles(files, duration, maxSize) {
|
||||||
|
|
||||||
// Wait for any remaining uploads to complete
|
// Wait for any remaining uploads to complete
|
||||||
await Promise.allSettled(inProgressUploads);
|
await Promise.allSettled(inProgressUploads);
|
||||||
|
|
||||||
|
wakeLock.release().then(() => {
|
||||||
|
wakeLock = null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function uploadFile(file, duration, maxSize) {
|
async function uploadFile(file, duration, maxSize) {
|
||||||
|
|
Loading…
Reference in a new issue