Skip to content
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 #134 #135 #136 #138

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions dist/NoSleep.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ var oldIOS = function oldIOS() {
return typeof navigator !== "undefined" && parseFloat(("" + (/CPU.*OS ([0-9_]{3,4})[0-9_]{0,1}|(CPU like).*AppleWebKit.*Mobile/i.exec(navigator.userAgent) || [0, ""])[1]).replace("undefined", "3_2").replace("_", ".").replace("_", "")) < 10 && !window.MSStream;
};

// Detect native Wake Lock API support
// Detect native Wake Lock API support (Samsung Browser supports it but cannot use it)
var nativeWakeLock = function nativeWakeLock() {
return "wakeLock" in navigator;
return "wakeLock" in navigator && window.navigator.userAgent.indexOf("Samsung") === -1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this not safe? On new Samsungs it might work. Is it possible to execute it, and in case the promise rejects, then we should be like "ok this samsung doesn't allow it, so then fallback"?

};

var NoSleep = function () {
Expand Down Expand Up @@ -150,6 +150,14 @@ var NoSleep = function () {
this._addSourceToVideo(this.noSleepVideo, "webm", webm);
this._addSourceToVideo(this.noSleepVideo, "mp4", mp4);

// For iOS >15 video needs to be on the document to work as a wake lock
Object.assign(this.noSleepVideo.style, {
position: "absolute",
left: "-100%",
top: "-100%"
});
document.querySelector("body").append(this.noSleepVideo);

this.noSleepVideo.addEventListener("loadedmetadata", function () {
if (_this.noSleepVideo.duration <= 1) {
// webm source
Expand Down
Loading