Skip to content

Commit

Permalink
feat: fallback function to use tel:// protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyco97 committed Nov 14, 2024
1 parent e2453ce commit e29d116
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,28 @@ export function callPhoneNumber(phoneNumber: string) {
if (default_device?.type === 'webrtc') {
eventDispatch('phone-island-call-start', { number: phoneNumber })
} else if (default_device?.type === 'nethlink' || hasNethlinkExtension) {
console.log('callto://', phoneNumber)
console.log('Attempting callto://', phoneNumber)

let hasBlurred = false

const onBlur = () => {
hasBlurred = true
window.removeEventListener('blur', onBlur)
}

window.addEventListener('blur', onBlur)

// Use callto:// protocol to start a call
window.location.href = `callto://${phoneNumber}`

// Fallback to tel:// if the callto:// protocol is not supported
setTimeout(() => {
window.removeEventListener('blur', onBlur)
if (!hasBlurred) {
console.log('Fallback to tel://', phoneNumber)
window.location.href = `tel://${phoneNumber}`
}
}, 2000)
} else if (default_device?.type === 'physical') {
eventDispatch('phone-island-call-start', { number: phoneNumber })
}
Expand Down

0 comments on commit e29d116

Please sign in to comment.