{"id":25490180,"url":"https://github.com/fix2015/no-sleep-app","last_synced_at":"2025-04-05T14:05:43.862Z","repository":{"id":264255443,"uuid":"892846476","full_name":"fix2015/no-sleep-app","owner":"fix2015","description":"NoSleepJs 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 across modern and legacy devices.","archived":false,"fork":false,"pushed_at":"2025-02-02T21:39:02.000Z","size":804,"stargazers_count":151,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T13:06:59.762Z","etag":null,"topics":["browser-compatibility","device-sleep-prevention","javascript-library","mobile-web","no-sleep","prevent-sleep","screen-activity","video-playback","wake-lock","wake-lock-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fix2015.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-22T22:26:24.000Z","updated_at":"2025-03-21T23:11:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"38ccfc7e-ea22-44a0-9afd-0ce357cb340a","html_url":"https://github.com/fix2015/no-sleep-app","commit_stats":null,"previous_names":["fix2015/no-sleep-js"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fno-sleep-app","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fno-sleep-app/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fno-sleep-app/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fix2015%2Fno-sleep-app/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fix2015","download_url":"https://codeload.github.com/fix2015/no-sleep-app/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345852,"owners_count":20924102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["browser-compatibility","device-sleep-prevention","javascript-library","mobile-web","no-sleep","prevent-sleep","screen-activity","video-playback","wake-lock","wake-lock-api"],"created_at":"2025-02-18T21:27:26.911Z","updated_at":"2025-04-05T14:05:43.835Z","avatar_url":"https://github.com/fix2015.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌙 no-sleep-app\n\n**no-sleep-app** is a lightweight, powerful JavaScript library designed to prevent devices from going to sleep during crucial tasks. Whether you’re developing a media player, an interactive app, or a seamless web experience, **no-sleep-app** ensures your application keeps the screen active across all platforms.\n\n---\n\n## 🌟 Why no-sleep-app?\n\nAs developers, maintaining an uninterrupted user experience is paramount. However, devices often go into sleep mode during long-running tasks or media playback, disrupting users. **no-sleep-app** offers a seamless, cross-platform solution with minimal configuration.\n\n---\n\n### Video in tiktok\n[Watch video](https://www.tiktok.com/@jsmentoring/video/7466939186528931104)\n\n### Key Features\n\n- **Universal Device Support:** Works across modern browsers and older iOS devices.\n- **Lightweight and Simple:** Easy to integrate with minimal configuration needed.\n- **Cross-Platform Compatibility:** Handles wake lock and video playback to prevent sleep on all devices.\n- **Performance Friendly:** Designed to prevent screen dimming and sleep without draining battery life unnecessarily.\n\n---\n\n## ⚙️ How It Works\n\n**no-sleep-app** uses the **Screen Wake Lock API** (when available) to keep the device screen active. For legacy devices, such as older iOS versions, it falls back to a simple video playback trick. This ensures reliable performance, no matter the device or platform.\n\n---\n\n## 📱 Platform Support\n\n**no-sleep-app** is fully compatible with both **iOS** and **Android** devices. Whether your users are on mobile phones or tablets, this library will keep their screens active during important tasks. The library automatically detects the platform and applies the most appropriate method to prevent the device from going to sleep.\n\n---\n\n## 🚀 Installation\n\nInstall **no-sleep-app** via npm or yarn:\n\n```bash\nnpm install no-sleep-app\n```\n\nor\n\n```bash\nyarn add no-sleep-app\n```\n\nAlternatively, you can include the `no-sleep-app.js` script directly in your HTML.\n\n---\n\n## 📖 Usage\n\nTo use **no-sleep-app**, instantiate the library and call its `enable()` and `disable()` methods to start and stop preventing sleep mode:\n\n```javascript\nimport NoSleepApp from 'no-sleep-app';\n\nconst noSleep = new NoSleepApp();\n\n// Enable to prevent sleep\nnoSleep.enable();\n\n// Disable to allow the device to go to sleep\nnoSleep.disable();\n```\n\nCheck whether **no-sleep-app** is currently active:\n\n```javascript\nif (noSleep.isEnabled) {\n  console.log('NoSleep is enabled');\n} else {\n  console.log('NoSleep is disabled');\n}\n```\n\n## 🔧 New Feature:\n\nWith the latest update to **no-sleep-app**, a set of **default options** has been introduced to make customization easier when you instantiate the library without providing specific configuration options.\n\n### ✅ **Easy Customization:** Use default options for basic functionality or modify them to suit your needs.  \n🛠️ **Control Behavior:** Configure how the app prevents sleep with options for strategies, retry intervals, and fallback mechanisms.  \n⚙️ **Flexible and Reliable:** Choose the Wake Lock strategy, set retry intervals, and enable or disable fallbacks based on device capabilities.  \n⚡ **Performance Optimization:** Control when and how often the app retries to ensure the best experience without unnecessary retries.\n\n```javascript\nconst defaultOptions = {\n  strategy: ''wakeLock'|'video'|'legacy'',   // Default strategy is wakeLock\n  retryInterval: 10000,    // Default retry interval is 10 seconds\n  fallbackEnabled: true,   // Default fallback is enabled\n};\n```\n\n### 🔧 **What You Can Control with `defaultOptions`**\n\n- **`strategy: ''wakeLock'|'video'|'legacy'}'`**\n  \n- **`retryInterval: 10000`**: Control how often the library retries to enable the Wake Lock API if it initially fails. By default, it will retry every **10 seconds**.\n\n- **`fallbackEnabled: true`**: Enable or disable fallback mechanisms, such as video playback, when Wake Lock isn't supported. By default, this is set to **true**.\n\n```javascript\nimport NoSleepApp from 'no-sleep-app';\n\n// Instantiate with default options\nconst noSleep = new NoSleepApp( {\n  strategy: 'wakeLock',\n  retryInterval: 10000,  \n  fallbackEnabled: true,  \n});\n```\n\n### 🔄 Customize `defaultOptions`:\n\nIf you want to modify the default behavior, simply pass custom options during initialization:\n\n```javascript\nconst customOptions = {\n  strategy: 'video',   // Use video strategy instead of wakeLock\n  retryInterval: 5000,  // Retry every 5 seconds\n  fallbackEnabled: false, // Disable fallback mechanisms\n};\n\nconst noSleep = new NoSleepApp(customOptions);\n\nnoSleep.enable();\n```\n\nThis makes it easy to control how **no-sleep-app** behaves across different devices and platforms!\n\n## 🌟 Why You Should Use **no-sleep-js**\n\nIn today’s world, where performance and user experience are critical, keeping a device from going to sleep can be essential for certain types of applications. \n\n✅ **Improved User Experience:** Prevent interruptions during critical activities.  \n🎮 **Perfect for Interactive Applications:** Ideal for gaming platforms, media players, and more.  \n🌐 **Cross-Browser Compatibility:** Works seamlessly on modern and older devices.  \n⚡ **Lightweight \u0026 Efficient:** Keeps devices awake without draining the battery unnecessarily.  \n\nWhether you're building an interactive video player, a gaming platform, or any web-based service that requires continuous screen activity, **no-sleep-js** provides a reliable solution. It’s built to be cross-browser and fully functional on both modern and older devices, ensuring your users won’t face interruptions during their experience.\n\n## Connect with Me:\n- [LinkedIn - Vitalii Semianchuk](https://www.linkedin.com/in/vitalii-semianchuk-9812a786/)\n- [Telegram - @jsmentorfree](https://t.me/jsmentorfree) - We do a lot of free teaching on this channel! Join us to learn and grow in web development.\n- [Tiktok - @jsmentoring](https://www.tiktok.com/@jsmentoring) Everyday new videos\n- [Youtube - @jsmentor-uk](https://www.youtube.com/@jsmentor-uk) Mentor live streams\n- [Dev.to - fix2015](https://dev.to/fix2015) Javascript featured, live, experience\n\n## License\n\nMIT License  \nCopyright (c) 2024 Vitalii Semianchuk  \n\n[LinkedIn Profile](https://www.linkedin.com/in/vitalii-semianchuk-9812a786/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fno-sleep-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffix2015%2Fno-sleep-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffix2015%2Fno-sleep-app/lists"}