Skip to content

Commit dc0d733

Browse files
committed
Prevent phones from sleeping while in other modes than standby
1 parent 631fe56 commit dc0d733

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

setup_server.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,27 @@ if [[ "$INSTALL_ANIME" = true ]]; then
237237
cd -
238238
fi
239239

240+
INSTALL_NOSLEEP_JS=true
241+
if [[ "$INSTALL_NOSLEEP_JS" = true ]]; then
242+
NOSLEEP_JS_VERSION=0.12.0
243+
if [[ "$NOSLEEP_JS_VERSION" = "latest" ]]; then
244+
FILENAME_ROOT="master"
245+
FILENAME="$FILENAME_ROOT.zip"
246+
DOWNLOAD_URL=https://github.com/richtr/NoSleep.js/archive/$FILENAME
247+
else
248+
FILENAME_ROOT=$NOSLEEP_JS_VERSION
249+
FILENAME=v$NOSLEEP_JS_VERSION.zip
250+
DOWNLOAD_URL=https://github.com/richtr/NoSleep.js/archive/refs/tags/$FILENAME
251+
fi
252+
cd /tmp
253+
wget $DOWNLOAD_URL
254+
unzip $FILENAME
255+
mkdir -p $BM_LINKED_SITE_DIR/library/nosleep-js
256+
mv NoSleep.js-$FILENAME_ROOT/dist/* $BM_LINKED_SITE_DIR/library/nosleep-js/
257+
rm -r $FILENAME NoSleep.js-$FILENAME_ROOT
258+
cd -
259+
fi
260+
240261
INSTALL_VIDEOJS=true
241262
if [[ "$INSTALL_VIDEOJS" = true ]]; then
242263
VIDEOJS_VERSION=7.13.3

site/public/js/main.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ const MAIN_CONTAINER_ID = 'main_container';
22
const FOOTER_CONTAINER_ID = 'footer_container';
33

44
const MODE_RADIO_STANDBY_ID = 'mode_radio_standby';
5+
const MODE_RADIO_LISTEN_ID = 'mode_radio_listen';
6+
const MODE_RADIO_AUDIO_ID = 'mode_radio_audiostream';
57

6-
var radioIds = [MODE_RADIO_STANDBY_ID, 'mode_radio_listen', 'mode_radio_audiostream'];
8+
var radioIds = [MODE_RADIO_STANDBY_ID, MODE_RADIO_LISTEN_ID, MODE_RADIO_AUDIO_ID];
79
var contentIds = ['mode_content_standby', MODE_CONTENT_LISTEN_ID, MODE_CONTENT_AUDIO_ID];
810
if (USES_CAMERA) {
911
radioIds.push('mode_radio_videostream');
@@ -36,6 +38,8 @@ $(function () {
3638
_ONLY_WAIT_FOR_STREAM = false;
3739
}
3840
});
41+
42+
setupSleepPrevention();
3943
});
4044

4145
function setCurrentMode(mode) {
@@ -58,6 +62,28 @@ function getModeRadio(modeName) {
5862
return $('#mode_radio_' + modeName);
5963
}
6064

65+
function setupSleepPrevention() {
66+
const NO_SLEEP = new NoSleep();
67+
68+
$('#' + MODE_RADIO_LISTEN_ID).click(function () {
69+
if (!NO_SLEEP.enabled) {
70+
NO_SLEEP.enable();
71+
}
72+
});
73+
74+
$('#' + MODE_RADIO_AUDIO_ID).click(function () {
75+
if (!NO_SLEEP.enabled) {
76+
NO_SLEEP.enable();
77+
}
78+
});
79+
80+
$('#' + MODE_RADIO_STANDBY_ID).click(function () {
81+
if (NO_SLEEP.enabled) {
82+
NO_SLEEP.disable();
83+
}
84+
});
85+
}
86+
6187
function registerModeChangeHandler() {
6288
MODE_RADIO_IDS.forEach(id => {
6389
var radio = $('#' + id);

site/public/main.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@
321321
}
322322
require_once(TEMPLATES_DIR . '/hls-js_js.php');
323323
require_once(TEMPLATES_DIR . '/anime_js.php');
324+
require_once(TEMPLATES_DIR . '/nosleep-js_js.php');
324325
require_once(TEMPLATES_DIR . '/jquery_js.php');
325326
require_once(TEMPLATES_DIR . '/js-cookie_js.php');
326327

site/templates/nosleep-js_js.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<script src="library/nosleep-js/NoSleep.min.js"></script>

0 commit comments

Comments
 (0)