From 0bffdde9b67ea689460a2cb98ae68caf893ccc05 Mon Sep 17 00:00:00 2001 From: Joao Santos Date: Wed, 6 Mar 2024 01:22:18 +0000 Subject: [PATCH 1/4] handle incoming calls --- public/full.js | 43 +++++++++++++++++++++++++++++++++++-------- views/index.ejs | 7 +++++-- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/public/full.js b/public/full.js index 81830af..b8ae902 100644 --- a/public/full.js +++ b/public/full.js @@ -142,6 +142,7 @@ async function enablePushNotifications() { deviceType: 'Android', // Use Android w/ Firebase on the web deviceToken: token, }) + client.online({pushNotification: __incomingCallNotification}) pnSecretKey = push_notification_key console.log('pnSecretKey: ', pnSecretKey) btnRegister.classList.add('d-none') @@ -165,11 +166,7 @@ async function handlePushNotification(pushNotificationPayload) { switch (resultType) { case 'inboundCall': - window.__call = resultObject - window.__call.on('destroy', () => { - console.warn('Inbound Call got cancelled!!') - }) - updateUIRinging() + this.logger.info('Inbound Call Push Notification received') break default: this.logger.warn('Unknown resultType', resultType, resultObject) @@ -365,7 +362,7 @@ async function getClient() { client = await SWire({ host: _host, token: _token, - rootElement: document.getElementById('rootElement'), + // rootElement: document.getElementById('rootElement'), }) } @@ -399,6 +396,7 @@ window.connect = async () => { logLevel: 'debug', debug: { logWsTraffic: true }, nodeId: steeringId(), + rootElement: document.getElementById('rootElement') }) window.__call = call @@ -534,13 +532,42 @@ function updateUIConnected() { }) } +window.__avaliable = false + +window.toggleAvaliable = async () => { + window.__avaliable = ! window.__avaliable + const isOn = window.__avaliable + btnAvaliable.innerText = isOn ? 'away' : 'avaliable' + btnAvaliable.classList = isOn ? 'btn btn-success' : 'btn btn-warning' + if(!window.__client) { + window.__client = await getClient() + } + client + if(isOn) { + window.__client.online({all: __incomingCallNotification}) + } else { + window.__client.offline() + } +} + +window.__incomingCallNotification = (notification) => { + if(!window.__invite || window.__invite.details.callID !== notification.invite.details.callID) { + window.__invite = notification.invite + } + updateUIRinging() +} + window.answer = async () => { - await window.__call.answer() + const call = await window.__invite.accept(document.getElementById('rootElement')) + window.__call = call + window.__call.on('destroy', () => { + console.warn('Inbound Call got cancelled!!') + }) updateUIConnected() } window.reject = async () => { - await window.__call.hangup() + await window.__invite.reject() restoreUI() } /** diff --git a/views/index.ejs b/views/index.ejs index b6debe5..9d930b1 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -94,7 +94,7 @@
From 2ad55bf5ab7ac0fc167ccd9aa0f641dd1158729a Mon Sep 17 00:00:00 2001 From: Joao Santos Date: Tue, 12 Mar 2024 20:06:59 +0000 Subject: [PATCH 2/4] fix answer --- public/full.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/full.js b/public/full.js index b8ae902..671ac3e 100644 --- a/public/full.js +++ b/public/full.js @@ -558,7 +558,7 @@ window.__incomingCallNotification = (notification) => { } window.answer = async () => { - const call = await window.__invite.accept(document.getElementById('rootElement')) + const call = await window.__invite.accept({rootElement: document.getElementById('rootElement')}) window.__call = call window.__call.on('destroy', () => { console.warn('Inbound Call got cancelled!!') From 23cfe4af580a68add710bc72bc788d89b5ab7e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Barbosa=20Marques=20dos=20Santos?= Date: Wed, 13 Mar 2024 09:53:00 -0300 Subject: [PATCH 3/4] Update views/index.ejs Co-authored-by: Ammar Ansari --- views/index.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.ejs b/views/index.ejs index 9d930b1..30eea7e 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -115,7 +115,7 @@
- Register Device for Push + Register Device for Push Notification