mirror of
https://github.com/Dangoware/confetti-box.git
synced 2025-04-19 15:22:57 -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 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) {
|
||||
console.log("Started upload for", file.name);
|
||||
|
||||
// Start the upload and add it to the set of in-progress uploads
|
||||
const uploadPromise = uploadFile(file, duration, maxSize);
|
||||
inProgressUploads.add(uploadPromise);
|
||||
|
@ -77,6 +90,10 @@ async function sendFiles(files, duration, maxSize) {
|
|||
|
||||
// Wait for any remaining uploads to complete
|
||||
await Promise.allSettled(inProgressUploads);
|
||||
|
||||
wakeLock.release().then(() => {
|
||||
wakeLock = null;
|
||||
});
|
||||
}
|
||||
|
||||
async function uploadFile(file, duration, maxSize) {
|
||||
|
|
Loading…
Reference in a new issue