no-sleep-app
Version:
NoSleepApp is a lightweight JavaScript library that prevents devices from going to sleep during critical activities. It uses the Screen Wake Lock API or a fallback video playback method to keep the screen active, ensuring uninterrupted user experiences ac
2,236 lines (537 loc) • 24.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: exports</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: exports</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>exports<span class="signature">(options)</span><span class="type-signature"></span></h2>
<div class="class-description">NoSleepApp prevents devices from entering sleep mode.
It uses the Wake Lock API, older iOS hacks, or video playback depending on device support.</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="exports"><span class="type-signature"></span>new exports<span class="signature">(options)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last">Configuration options for NoSleepApp.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>strategy</code></td>
<td class="type">
<span class="param-type">'wakeLock'</span>
|
<span class="param-type">'video'</span>
|
<span class="param-type">'legacy'</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
'wakeLock'
</td>
<td class="description last">The strategy to use for preventing sleep.</td>
</tr>
<tr>
<td class="name"><code>retryInterval</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
10000
</td>
<td class="description last">Interval to retry enabling Wake Lock if it fails (in milliseconds).</td>
</tr>
<tr>
<td class="name"><code>fallbackEnabled</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">Whether to enable fallback mechanisms if Wake Lock is not available.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line20">line 20</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="_wakeLock"><span class="type-signature"></span>_wakeLock<span class="type-signature"> :WakeLockSentinel|null</span></h4>
<div class="description">
The active Wake Lock instance.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">WakeLockSentinel</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line42">line 42</a>
</li></ul></dd>
</dl>
<h4 class="name" id="callback"><span class="type-signature"></span>callback<span class="type-signature"> :function</span></h4>
<div class="description">
The callback function to execute when the state changes.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">function</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="visibility-listener.js.html">visibility-listener.js</a>, <a href="visibility-listener.js.html#line18">line 18</a>
</li></ul></dd>
</dl>
<h4 class="name" id="enabled"><span class="type-signature"></span>enabled<span class="type-signature"> :boolean</span></h4>
<div class="description">
Indicates whether NoSleepApp is currently enabled.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">boolean</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line38">line 38</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepElement"><span class="type-signature"></span>noSleepElement<span class="type-signature"> :NoSleepElement</span></h4>
<div class="description">
Video element for non-iOS and non-Wake Lock devices.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">NoSleepElement</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line51">line 51</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepTimer"><span class="type-signature"></span>noSleepTimer<span class="type-signature"> :number|null</span></h4>
<div class="description">
Timer ID for the iOS hack to prevent sleep.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line48">line 48</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepVideo"><span class="type-signature"></span>noSleepVideo<span class="type-signature"> :HTMLVideoElement</span></h4>
<div class="description">
The hidden video element used to prevent sleep.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">HTMLVideoElement</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="no-sleep-element.js.html">no-sleep-element.js</a>, <a href="no-sleep-element.js.html#line16">line 16</a>
</li></ul></dd>
</dl>
<h4 class="name" id="visibilityListener"><span class="type-signature"></span>visibilityListener<span class="type-signature"> :VisibilityListener|null</span></h4>
<div class="description">
Listener for visibility changes to re-enable Wake Lock.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">VisibilityListener</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line45">line 45</a>
</li></ul></dd>
</dl>
</article>
</section>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>exports<span class="signature">()</span><span class="type-signature"></span></h2>
<div class="class-description">Class to manage a hidden video element that prevents devices from sleeping.</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="exports"><span class="type-signature"></span>new exports<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="no-sleep-element.js.html">no-sleep-element.js</a>, <a href="no-sleep-element.js.html#line11">line 11</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="_wakeLock"><span class="type-signature"></span>_wakeLock<span class="type-signature"> :WakeLockSentinel|null</span></h4>
<div class="description">
The active Wake Lock instance.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">WakeLockSentinel</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line42">line 42</a>
</li></ul></dd>
</dl>
<h4 class="name" id="callback"><span class="type-signature"></span>callback<span class="type-signature"> :function</span></h4>
<div class="description">
The callback function to execute when the state changes.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">function</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="visibility-listener.js.html">visibility-listener.js</a>, <a href="visibility-listener.js.html#line18">line 18</a>
</li></ul></dd>
</dl>
<h4 class="name" id="enabled"><span class="type-signature"></span>enabled<span class="type-signature"> :boolean</span></h4>
<div class="description">
Indicates whether NoSleepApp is currently enabled.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">boolean</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line38">line 38</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepElement"><span class="type-signature"></span>noSleepElement<span class="type-signature"> :NoSleepElement</span></h4>
<div class="description">
Video element for non-iOS and non-Wake Lock devices.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">NoSleepElement</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line51">line 51</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepTimer"><span class="type-signature"></span>noSleepTimer<span class="type-signature"> :number|null</span></h4>
<div class="description">
Timer ID for the iOS hack to prevent sleep.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line48">line 48</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepVideo"><span class="type-signature"></span>noSleepVideo<span class="type-signature"> :HTMLVideoElement</span></h4>
<div class="description">
The hidden video element used to prevent sleep.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">HTMLVideoElement</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="no-sleep-element.js.html">no-sleep-element.js</a>, <a href="no-sleep-element.js.html#line16">line 16</a>
</li></ul></dd>
</dl>
<h4 class="name" id="visibilityListener"><span class="type-signature"></span>visibilityListener<span class="type-signature"> :VisibilityListener|null</span></h4>
<div class="description">
Listener for visibility changes to re-enable Wake Lock.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">VisibilityListener</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line45">line 45</a>
</li></ul></dd>
</dl>
</article>
</section>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>exports<span class="signature">(callback)</span><span class="type-signature"></span></h2>
<div class="class-description">Class to listen for visibility and fullscreen changes in the document.
It triggers a callback when the document becomes visible or enters fullscreen mode.</div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="exports"><span class="type-signature"></span>new exports<span class="signature">(callback)</span><span class="type-signature"></span></h4>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last">The callback function to invoke on visibility or fullscreen changes.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="visibility-listener.js.html">visibility-listener.js</a>, <a href="visibility-listener.js.html#line10">line 10</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="_wakeLock"><span class="type-signature"></span>_wakeLock<span class="type-signature"> :WakeLockSentinel|null</span></h4>
<div class="description">
The active Wake Lock instance.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">WakeLockSentinel</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line42">line 42</a>
</li></ul></dd>
</dl>
<h4 class="name" id="callback"><span class="type-signature"></span>callback<span class="type-signature"> :function</span></h4>
<div class="description">
The callback function to execute when the state changes.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">function</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="visibility-listener.js.html">visibility-listener.js</a>, <a href="visibility-listener.js.html#line18">line 18</a>
</li></ul></dd>
</dl>
<h4 class="name" id="enabled"><span class="type-signature"></span>enabled<span class="type-signature"> :boolean</span></h4>
<div class="description">
Indicates whether NoSleepApp is currently enabled.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">boolean</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line38">line 38</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepElement"><span class="type-signature"></span>noSleepElement<span class="type-signature"> :NoSleepElement</span></h4>
<div class="description">
Video element for non-iOS and non-Wake Lock devices.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">NoSleepElement</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line51">line 51</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepTimer"><span class="type-signature"></span>noSleepTimer<span class="type-signature"> :number|null</span></h4>
<div class="description">
Timer ID for the iOS hack to prevent sleep.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line48">line 48</a>
</li></ul></dd>
</dl>
<h4 class="name" id="noSleepVideo"><span class="type-signature"></span>noSleepVideo<span class="type-signature"> :HTMLVideoElement</span></h4>
<div class="description">
The hidden video element used to prevent sleep.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">HTMLVideoElement</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="no-sleep-element.js.html">no-sleep-element.js</a>, <a href="no-sleep-element.js.html#line16">line 16</a>
</li></ul></dd>
</dl>
<h4 class="name" id="visibilityListener"><span class="type-signature"></span>visibilityListener<span class="type-signature"> :VisibilityListener|null</span></h4>
<div class="description">
Listener for visibility changes to re-enable Wake Lock.
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">VisibilityListener</span>
|
<span class="param-type">null</span>
</li>
</ul>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line45">line 45</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module.exports.html">exports</a></li></ul><h3>Global</h3><ul><li><a href="global.html#disable">disable</a></li><li><a href="global.html#enable">enable</a></li><li><a href="global.html#handleFullscreenChange">handleFullscreenChange</a></li><li><a href="global.html#handleVisibilityChange">handleVisibilityChange</a></li><li><a href="global.html#isEnabled">isEnabled</a></li><li><a href="global.html#isNativeWakeLockSupported">isNativeWakeLockSupported</a></li><li><a href="global.html#isOldIOS">isOldIOS</a></li><li><a href="global.html#pause">pause</a></li><li><a href="global.html#play">play</a></li><li><a href="global.html#removeListeners">removeListeners</a></li><li><a href="global.html#setMetadataListener">setMetadataListener</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.4</a> on Fri Nov 22 2024 23:19:12 GMT+0000 (Greenwich Mean Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>