Skip to content

Commit

Permalink
Implement fixes from richtr#138
Browse files Browse the repository at this point in the history
  • Loading branch information
ogdendavis committed Nov 30, 2021
1 parent 1d15cc8 commit 79c0c19
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
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;
};

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

0 comments on commit 79c0c19

Please sign in to comment.