-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(entry): added battery level check #851
Changes from 7 commits
643d417
b107660
bfef734
2bf6714
2b9206c
5d5332e
54ceb68
a3b9487
2ac023e
a6f10fc
9054d5b
90a2f66
565125b
8da3062
b2d7037
74d6ae9
6d47219
388bfd8
a1f014f
2b3a45d
65c27a5
bcc5821
df17692
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it it helpful to create an ignore object? so we have an easy possibility to extend it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we implement a generalistic solution. so it also works on ios and in desktop browsers (laptop) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two different checks.
Checking sequence The check is placed in the entry before the performance check and triggers a separate message in the layer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the silent catch to switch to video detection. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,3 +56,57 @@ export function initReducedView() { | |
tmp.remove(); | ||
}); | ||
} | ||
|
||
export async function hasBatteryPerformanceIssue(videoBlob) { | ||
await isBatteryLow(); | ||
await canVideoPlay(videoBlob); | ||
} | ||
|
||
/** | ||
* Checks if battery still has enough energy. | ||
* This check is for Chrome and all other browsers that support this setting. | ||
* | ||
* Condition is: The device is not charging and Battery is below <= 20%. | ||
* @see https://blog.google/products/chrome/new-chrome-features-to-save-battery-and-make-browsing-smoother/ | ||
* @see https://developer.chrome.com/blog/memory-and-energy-saver-mode/ | ||
**/ | ||
async function isBatteryLow() { | ||
const MIN_BATTERY_LEVEL = 0.2; | ||
|
||
try { | ||
const battery = await window.navigator.getBattery(); | ||
if (!battery.charging && battery.level <= MIN_BATTERY_LEVEL) { | ||
throw new Error('Battery is low.'); | ||
} | ||
} catch (error) { | ||
// Ignore Check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. silent catch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
|
||
/** | ||
* Checking whether a video can be played. | ||
* This check is for IOS and checks if the power saving mode is enabled. | ||
* | ||
* In this case no video will be played automatically. | ||
*/ | ||
export async function canVideoPlay(blob) { | ||
const VIDEO_TIMEOUT = 250; | ||
|
||
const video = document.createElement('video'); | ||
video.muted = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need that. it seems to be a duplicate -> next line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All |
||
video.setAttribute('muted', 'muted'); | ||
video.setAttribute('playsinline', 'playsinline'); | ||
video.src = URL.createObjectURL(blob); | ||
|
||
const timeout = setTimeout(() => { | ||
throw new Error('Video playback not possible. Reason: timeout'); | ||
}, VIDEO_TIMEOUT); | ||
|
||
try { | ||
await video.play(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explain me, what should happen here in combination with the timeout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Video timeout was removed. Now only the reject from the video https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play |
||
clearTimeout(timeout); | ||
} catch (error) { | ||
clearTimeout(timeout); | ||
throw new Error("Video playback not possible. Reason: can't play video"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please consign a meaningful error message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then there is alternatively only the possibility to forward the video error. No separate text for an error that we can not guess when a video does not play. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { promises as fsPromises } from 'fs'; | ||
import mime from 'mime-types'; | ||
|
||
async function getFileInfo(name, file) { | ||
return { | ||
name, | ||
// eslint-disable-next-line security/detect-non-literal-fs-filename | ||
file: await fsPromises.readFile(file), | ||
mimeType: mime.lookup(file) | ||
}; | ||
} | ||
|
||
export async function getTemplate(files) { | ||
return (await Promise.all(files.map(file => getFileInfo(...file)))) | ||
.map( | ||
({ name, file, mimeType }) => | ||
`export const ${name} = new Blob([new Uint8Array([${[...file].join( | ||
', ' | ||
)}])], {type: '${mimeType}'});` | ||
) | ||
.join('\n'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we use an additional file? Or can we also use a super small base64 string?