mirror of
https://github.com/Luzifer/browserphone.git
synced 2024-11-09 14:20:04 +00:00
Add experimental wake-lock support
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
3ff2a392b6
commit
facd2c06d4
4 changed files with 43 additions and 0 deletions
9
package-lock.json
generated
9
package-lock.json
generated
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
30
src/app.vue
30
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()
|
||||
|
|
|
@ -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"] } }]
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue