bluetoothLink = {
const baseLink = deploy("bluetooth", (req, res) => {
res.send(
html`
<button id="connectBtn">Connect to Device</button>
<script>
var channel = new BroadcastChannel('${req.query.session}');
const button = document.getElementById("connectBtn");
button.onclick = async event => {
event.preventDefault();
console.log("clicked");
navigator.bluetooth.requestDevice({acceptAllDevices: true})
.then(device=>{
console.log("Device info: ");
console.log(device);
channel.postMessage(device.id); // Call the bidge
})
.catch(err=>{
console.log("Error info: "+err.message);
});
};
</script>
`.outerHTML
);
});
return html`<a target="_blank" href="${baseLink.href}?session=${session}">bluetooth</a>`;
}