GithubHelp home page GithubHelp logo

zakj / no-sleep Goto Github PK

View Code? Open in Web Editor NEW

This project forked from richtr/nosleep.js

8.0 3.0 2.0 245 KB

Prevent display sleep and enable wake lock in any Android or iOS web browser.

License: MIT License

JavaScript 1.89% TypeScript 98.11%

no-sleep's Issues

Feat: Add Title as param

It will be great to have "Title" as param.

I like to pass the title like "App name" to the video Title.

The reason is that "No Sleep" is not much informative for end user of app and have to be somehow explained in the app.

So (maybe) when no sleep video will have "App Name - No sleep" in the name, the user will know what going on.

Thank you.

disable does not release lock

When testing installed to homescreen on ios, calling disable pauses the video, but my screen never sleeps after that. If you close your phone and then look at it locked, you can see the video called "No Sleep" showing
IMG_287025EC6688-1

Panel

Can you please add panel? I think it would be a big improvement. Thanks.

Sleep prevention will fail on iOS standalone (hidden video) if app is busy (under load) for too long

I was experiencing intermittent failures of the sleep prevention in my app. I discovered that sometimes the video used by no-sleep on iOS standalone (home screen app) would reach the end and stop playing without a timeupdate event firing. This seems most prone to occurring when the app is busy (blocking the thread) for a sustained period of time. I created a fork of noslee.page at https://sgilroy.github.io/nosleep.page to demonstrate the problem (and a mitigation).

The currentTime was being set to Math.random(), which can occasionally results in a time at or near 1.0 second, leaving very little time before the end of the video is reached. The video is only 1.048 seconds in duration. There are actually two video files (webm and mp4), but they are very close in length.

To mitigate the problem I made two changes:

  • When shifting the currentTime in the event handler for timeupdate, Math.random() * 0.5 instead of Math.random().
  • Set the playbackRate to 0.1, effectively stretching out the video from 1.048 seconds to approximately 10 seconds.

These changes are available in my fork https://github.com/sgilroy/no-sleep and published in the NPM package https://www.npmjs.com/package/@scottjgilroy/no-sleep.

Note that I did try using loop on the video instead of the timeupdate event, but on iOS this does not seem to be effective in preventing sleep. I did not investigate setting currentTime to 0 instead of a random value, based on the assumption that this strange approach had been introduced for some good reason (such as performance or .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.