QRcheckin / static /bluetooth.js
Corin1998's picture
Create static/bluetooth.js
8e6c80e verified
// デモ用:ビーコン名に "StoreBeacon" を含むデバイスに接続し、
// GATT Characteristic (UUIDサンプル: 0000beac-0000-1000-8000-00805f9b34fb) から venueSlug を取得する想定
async function connectBeacon(){
try{
const device = await navigator.bluetooth.requestDevice({
filters: [{ namePrefix: 'StoreBeacon' }],
optionalServices: ['0000beac-0000-1000-8000-00805f9b34fb']
});
const server = await device.gatt.connect();
const service = await server.getPrimaryService('0000beac-0000-1000-8000-00805f9b34fb');
const ch = await service.getCharacteristic('0000bead-0000-1000-8000-00805f9b34fb');
const value = await ch.readValue();
const decoder = new TextDecoder('utf-8');
const slug = decoder.decode(value.buffer);
alert('ビーコン検出: ' + slug + '\n(実際のチェックインは店舗QRを推奨)');
}catch(e){ alert('Bluetoothエラー: ' + e.message); }
}
document.getElementById('beacon').onclick = () => connectBeacon();