From 1a9aae04c3a3799a52793e5a3f521924a3bb64c2 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sat, 10 Dec 2022 20:32:37 +0100 Subject: [PATCH] Disable call button on disconnect, add backoff for conn retries Signed-off-by: Knut Ahlers --- src/app.vue | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/app.vue b/src/app.vue index 988987f..c4184dd 100644 --- a/src/app.vue +++ b/src/app.vue @@ -33,7 +33,7 @@ - + @@ -71,15 +71,26 @@ export default { pendingCall() { return this.phone.conn && this.phone.conn.status() === 'pending' }, + + phoneReady() { + return this.phone.conn && this.phone.device && this.phone.registered + }, }, data() { return { + backoff: { + current: 100, + initial: 100, + max: 30000, + multiplier: 1.25, + }, identity: null, number: '', phone: { conn: null, device: null, + registered: false, }, state: '', wakeLock: { @@ -132,6 +143,7 @@ export default { }, setupPhone() { + this.backoff.current = Math.min(this.backoff.current * this.backoff.multiplier, this.backoff.max) const opts = { codecPreferences: ['opus', 'pcmu'], fakeLocalDTMF: true } if (this.phone.device) { @@ -146,7 +158,11 @@ export default { .then(resp => { this.phone.device = new Device(resp.data.token, opts) - this.phone.device.on('registered', () => this.announceStatus('Device registered')) + this.phone.device.on('registered', () => { + this.backoff.current = this.backoff.initial + this.phone.registered = true + this.announceStatus('Device registered') + }) this.phone.device.on('error', err => console.error(err)) @@ -156,8 +172,9 @@ export default { }) this.phone.device.on('unregistered', () => { + this.phone.registered = false this.announceStatus('Phone unregistered, reconnecting...') - this.setupPhone() + window.setTimeout(() => this.setupPhone(), this.backoff.current) }) this.phone.device.register()