Corin1998 commited on
Commit
8e6c80e
·
verified ·
1 Parent(s): 3f28bba

Create static/bluetooth.js

Browse files
Files changed (1) hide show
  1. static/bluetooth.js +20 -0
static/bluetooth.js ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // デモ用:ビーコン名に "StoreBeacon" を含むデバイスに接続し、
2
+ // GATT Characteristic (UUIDサンプル: 0000beac-0000-1000-8000-00805f9b34fb) から venueSlug を取得する想定
3
+
4
+ async function connectBeacon(){
5
+ try{
6
+ const device = await navigator.bluetooth.requestDevice({
7
+ filters: [{ namePrefix: 'StoreBeacon' }],
8
+ optionalServices: ['0000beac-0000-1000-8000-00805f9b34fb']
9
+ });
10
+ const server = await device.gatt.connect();
11
+ const service = await server.getPrimaryService('0000beac-0000-1000-8000-00805f9b34fb');
12
+ const ch = await service.getCharacteristic('0000bead-0000-1000-8000-00805f9b34fb');
13
+ const value = await ch.readValue();
14
+ const decoder = new TextDecoder('utf-8');
15
+ const slug = decoder.decode(value.buffer);
16
+ alert('ビーコン検出: ' + slug + '\n(実際のチェックインは店舗QRを推奨)');
17
+ }catch(e){ alert('Bluetoothエラー: ' + e.message); }
18
+ }
19
+
20
+ document.getElementById('beacon').onclick = () => connectBeacon();