aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-android/app/src/main/assets
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-android/app/src/main/assets')
-rw-r--r--packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js b/packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js
index e8b40b2d..e78a2337 100644
--- a/packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js
+++ b/packages/meshbay-android/app/src/main/assets/bridge/meshbay-bridge.js
@@ -46,6 +46,45 @@
port.postMessage(JSON.stringify({ id, ch: channel, args }));
});
+ // The Screen Wake Lock API, which Chrome has and the WebView does not: the
+ // video player (and music, when asked) holds it so the screen does not time
+ // out mid-film. Held natively as the WebView's keepScreenOn, and released
+ // when the page hides, as the API does. Cleared first, for a reload that
+ // left one held.
+ if (!('wakeLock' in navigator)) {
+ const held = new Set();
+ const sync = () => call('screen:keep-on', held.size > 0).catch(() => {});
+ class WakeLockSentinel extends EventTarget {
+ constructor() { super(); this.type = 'screen'; this.released = false; this.onrelease = null; }
+ release() {
+ if (!this.released) {
+ this.released = true;
+ held.delete(this);
+ sync();
+ const event = new Event('release');
+ if (typeof this.onrelease === 'function') this.onrelease(event);
+ this.dispatchEvent(event);
+ }
+ return Promise.resolve();
+ }
+ }
+ const request = (type) => {
+ if (type !== 'screen') return Promise.reject(new TypeError('Unsupported wake lock type'));
+ if (document.visibilityState !== 'visible') {
+ return Promise.reject(new DOMException('The page is not visible', 'NotAllowedError'));
+ }
+ const sentinel = new WakeLockSentinel();
+ held.add(sentinel);
+ sync();
+ return Promise.resolve(sentinel);
+ };
+ document.addEventListener('visibilitychange', () => {
+ if (document.visibilityState !== 'visible') [...held].forEach((s) => s.release());
+ });
+ Object.defineProperty(navigator, 'wakeLock', { value: Object.freeze({ request }) });
+ sync();
+ }
+
// A write is a binary message: "MBB1" | id | channel | 0 | handle | bytes,
// big-endian — one copy, no JSON, no base64 (spike S-3: 136 MB/s awaited
// per 48 KB chunk). Without ArrayBuffer messages, base64 over JSON.