2023-04-05 07:42:20 -06:00
|
|
|
async function testIt () {
|
2021-09-23 05:00:11 -06:00
|
|
|
const device = await navigator.bluetooth.requestDevice({
|
|
|
|
acceptAllDevices: true
|
|
|
|
})
|
|
|
|
document.getElementById('device-name').innerHTML = device.name || `ID: ${device.id}`
|
|
|
|
}
|
|
|
|
|
2023-04-05 07:42:20 -06:00
|
|
|
document.getElementById('clickme').addEventListener('click', testIt)
|
2022-09-26 08:19:58 -06:00
|
|
|
|
2023-04-24 08:35:14 -06:00
|
|
|
function cancelRequest () {
|
2023-03-27 07:31:15 -06:00
|
|
|
window.electronAPI.cancelBluetoothRequest()
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('cancel').addEventListener('click', cancelRequest)
|
|
|
|
|
2022-09-26 08:19:58 -06:00
|
|
|
window.electronAPI.bluetoothPairingRequest((event, details) => {
|
|
|
|
const response = {}
|
2023-02-01 04:59:16 -07:00
|
|
|
|
2022-09-26 08:19:58 -06:00
|
|
|
switch (details.pairingKind) {
|
|
|
|
case 'confirm': {
|
2023-04-24 08:35:14 -06:00
|
|
|
response.confirmed = window.confirm(`Do you want to connect to device ${details.deviceId}?`)
|
2022-09-26 08:19:58 -06:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case 'confirmPin': {
|
2023-04-24 08:35:14 -06:00
|
|
|
response.confirmed = window.confirm(`Does the pin ${details.pin} match the pin displayed on device ${details.deviceId}?`)
|
2022-09-26 08:19:58 -06:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case 'providePin': {
|
2023-04-24 08:35:14 -06:00
|
|
|
const pin = window.prompt(`Please provide a pin for ${details.deviceId}.`)
|
2022-09-26 08:19:58 -06:00
|
|
|
if (pin) {
|
|
|
|
response.pin = pin
|
|
|
|
response.confirmed = true
|
|
|
|
} else {
|
|
|
|
response.confirmed = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.electronAPI.bluetoothPairingResponse(response)
|
2023-04-05 07:42:20 -06:00
|
|
|
})
|