1
0
Fork 0
mirror of https://github.com/Luzifer/browserphone.git synced 2024-11-08 13:50:05 +00:00

Use connection to read status

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-07-13 15:27:55 +02:00
parent 00856f9353
commit 2b76995274
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -63,18 +63,24 @@ export default {
keys() { keys() {
return [1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#'] return [1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#']
}, },
ongoingCall() {
return this.phone.conn && this.phone.conn.status() === 'open'
},
ringing() {
return this.phone.conn && this.phone.conn.status() === 'ringing'
},
}, },
data() { data() {
return { return {
identity: null, identity: null,
number: '', number: '',
ongoingCall: false,
phone: { phone: {
conn: null, conn: null,
device: null, device: null,
}, },
ringing: false,
state: '', state: '',
wakeLock: { wakeLock: {
obj: null, obj: null,
@ -116,27 +122,17 @@ export default {
this.phone.device.on('error', err => console.error(err)) this.phone.device.on('error', err => console.error(err))
this.phone.device.on('connect', conn => { this.phone.device.on('connect', conn => {
this.phone.conn = conn this.phone.conn = conn
this.ongoingCall = true
this.ringing = false
this.announceStatus('Call connected') this.announceStatus('Call connected')
this.setWakeLock(true) this.setWakeLock(true)
}) })
this.phone.device.on('disconnect', () => { this.phone.device.on('disconnect', () => {
this.phone.conn = null this.phone.conn = null
this.ongoingCall = false
this.announceStatus('Call disconnected') this.announceStatus('Call disconnected')
this.setWakeLock(false) this.setWakeLock(false)
}) })
this.phone.device.on('incoming', conn => { this.phone.device.on('incoming', conn => {
this.announceStatus(`Incoming call from ${conn.parameters.From}...`, false) this.announceStatus(`Incoming call from ${conn.parameters.From}...`, false)
this.phone.conn = conn this.phone.conn = conn
this.ringing = true
this.phone.conn.on('disconnect', () => {
this.phone.conn = null
this.ongoingCall = false
this.announceStatus('Call disconnected')
this.ringing = true
})
}) })
this.phone.device.on('offline', () => { this.phone.device.on('offline', () => {
this.announceStatus('Phone disconnected, reconnecting...') this.announceStatus('Phone disconnected, reconnecting...')
@ -150,7 +146,6 @@ export default {
.then(resp => { .then(resp => {
this.identity = resp.data.identity this.identity = resp.data.identity
this.phone.device.setup(resp.data.token, opts) this.phone.device.setup(resp.data.token, opts)
this.ringing = false
}) })
.catch(err => console.error(err)) .catch(err => console.error(err))
}, },
@ -180,7 +175,7 @@ export default {
}, },
toggleCall() { toggleCall() {
if (this.ringing && this.phone.conn) { if (this.ringing) {
this.phone.conn.accept() this.phone.conn.accept()
return return
} }