• Stars
    star
    2,122
  • Rank 20,938 (Top 0.5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

NoSleep.js

Prevent display sleep and enable wake lock in all Android and iOS web browsers.

Check out the live demo in any Android or iOS web browser.

Installation

This library is available on Bower as nosleep.

bower install nosleep

This package is published to npm as nosleep.js and can be installed with:

npm install nosleep.js

Alternatively, you can manually add NoSleep.js to your project (or the minified version).

Build from source

Install all development dependencies with:

npm install

To build this library run:

npm run build

A new build of NoSleep.js and NoSleep.min.js will now be available in the /dist directory.

Usage

Import ES6 module:

import NoSleep from 'nosleep.js';

Create a new NoSleep object and then enable or disable it when needed.

To create a new NoSleep object:

var noSleep = new NoSleep();

To enable wake lock:

NOTE: This function call must be wrapped in a user input event handler e.g. a mouse or touch handler

// Enable wake lock.
// (must be wrapped in a user input event handler e.g. a mouse or touch handler)
document.addEventListener('click', function enableNoSleep() {
  document.removeEventListener('click', enableNoSleep, false);
  noSleep.enable();
}, false);

To disable wake lock:

// Disable wake lock at some point in the future.
// (does not need to be wrapped in any user input event handler)
noSleep.disable();

See example/index.html (and the live demo) for more information.

Feedback

If you find any bugs or issues please report them on the NoSleep.js Issue Tracker.

If you would like to contribute to this project please consider forking this repo, making your changes and then creating a new Pull Request back to the main code repository.

License

MIT. Copyright (c) Rich Tibbett.

See the LICENSE file.

More Repositories

1

threeVR

An orientation-aware Virtual Reality controller for web browsers built on top of three.js
JavaScript
436
star
2

guessLanguage.js

A natural language detection library based on trigram statistical analysis for Node.js and the Web.
JavaScript
210
star
3

baseapp

Bootstrap-based web application scaffolding built in Go on top of the Revel Web Framework w/ Docker build support
Go
91
star
4

Marine-Compass

A 3-dimensional floating compass for the web
JavaScript
65
star
5

doe

An emulator for building and debugging device orientation and screen orientation based web applications
JavaScript
49
star
6

plug.play.js

A Network Service Messaging framework for use on top of the W3C Network Service Discovery specification
JavaScript
38
star
7

Opera-Translate

Translate for Opera adds in-page language translation functionality to any web page.
JavaScript
22
star
8

Artificial-Horizon

A JavaScript implementation of an Artifical Horizon Instrument
JavaScript
11
star
9

go-tls-srp

Snapshot of https://bitbucket.org/mjl/go-tls-srp @ 6th Nov 2014
Go
6
star
10

html-media-focus

[DEPRECATED] Connecting remote control interfaces and events with web content
JavaScript
4
star
11

sensortest.org

[DISCONTINUED] How well does your browser support DeviceOrientation Events?
PHP
3
star
12

appearin-handoff-extension

Handoff Appear.in sessions from your desktop to Android mobile web browser
JavaScript
3
star
13

devopera

Repository for Dev.Opera source code
HTML
3
star
14

universal-remote-control-access

A demonstration of how web apps can access media-centric remote control events to control any other web content
JavaScript
3
star
15

Opera-11-Extensions--Auto-I18N-Library

Auto-translation library for Opera 11+ Extensions
JavaScript
2
star
16

docker-jobber

A minimal Docker container for running Jobber (cron-replacement) tasks
2
star
17

Opera-Firebug-Lite-Extension

Firebug Lite extensions for Opera 11+
JavaScript
1
star
18

Browser-to-Phone

Browser to Phone lets you share links, maps, phone numbers and text content between your desktop browser and phone.
Java
1
star