From facd2c06d411429739730c901b5b91c1f4de4adc Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Mon, 10 Jun 2019 22:28:21 +0200 Subject: [PATCH] Add experimental wake-lock support Signed-off-by: Knut Ahlers --- package-lock.json | 9 +++++++++ package.json | 1 + src/app.vue | 30 ++++++++++++++++++++++++++++++ webpack.config.js | 3 +++ 4 files changed, 43 insertions(+) diff --git a/package-lock.json b/package-lock.json index 7497b89..b35a3f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1082,6 +1082,15 @@ "regenerator-transform": "^0.10.0" } }, + "babel-plugin-transform-runtime": { + "version": "6.23.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-runtime/-/babel-plugin-transform-runtime-6.23.0.tgz", + "integrity": "sha1-iEkNRGUC6puOfvsP4J7E2ZR5se4=", + "dev": true, + "requires": { + "babel-runtime": "^6.22.0" + } + }, "babel-plugin-transform-strict-mode": { "version": "6.24.1", "resolved": "https://registry.npmjs.org/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz", diff --git a/package.json b/package.json index ef54239..25a0bbe 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "axios": "^0.18.0", "babel-core": "^6.26.3", "babel-loader": "^7.1.5", + "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-env": "^1.7.0", "bootstrap": "^4.3.1", "bootstrap-vue": "^2.0.0-rc.19", diff --git a/src/app.vue b/src/app.vue index 24bc900..a6228e6 100644 --- a/src/app.vue +++ b/src/app.vue @@ -76,6 +76,10 @@ export default { }, ringing: false, state: '', + wakeLock: { + obj: null, + request: null, + }, } }, @@ -110,11 +114,13 @@ export default { this.ongoingCall = true this.ringing = false this.announceStatus('Call connected') + this.setWakeLock(true) }) this.phone.device.on('disconnect', () => { this.phone.conn = null this.ongoingCall = false this.announceStatus('Call disconnected') + this.setWakeLock(false) }) this.phone.device.on('incoming', conn => { this.announceStatus(`Incoming call from ${conn.parameters.From}...`, false) @@ -138,6 +144,30 @@ export default { .catch(err => console.error(err)) }, + async setWakeLock(lock) { + if (!navigator || !navigator.getWakeLock) { + // No wake-lock functionality present in this browser + console.debug('Browser has no wake-lock support') + return + } + + if (!this.wakeLock.obj) { + this.wakeLock.obj = await navigator.getWakeLock('screen') + } + + if (lock && !this.wakeLock.request) { + this.wakeLock.request = this.wakeLock.obj.createRequest() + this.announceStatus('Wake-lock aquired: Keeping display active...') + return + } + + if (!lock && this.wakeLock.request) { + this.wakeLock.request.cancel() + this.wakeLock.request = null + this.announceStatus('Wake-lock disabled: Screen may sleep...') + } + }, + toggleCall() { if (this.ringing && this.phone.conn) { this.phone.conn.accept() diff --git a/webpack.config.js b/webpack.config.js index 0362a5d..e27be32 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -43,6 +43,9 @@ module.exports = { use: { loader: 'babel-loader', options: { + plugins: [ + ['transform-runtime', {polyfill: false, regenerator: true}], + ], presets: [ ['env', { "targets": { "browsers": [">0.25%", "not ie 11", "not op_mini all"] } }] ]