-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
96 lines (93 loc) · 3.77 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!doctype html>
<html lang="en" class="bg-background">
<head>
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self';
worker-src 'self' blob:;
font-src 'self' https://fonts.gstatic.com;
frame-src 'none';
connect-src 'self' https://api.github.com/repos/NivSv/my-portfolio https://api.emailjs.com/api/v1.0/email/send;
img-src data: https: http:;
script-src 'self' 'unsafe-inline' 'unsafe-eval';
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/svg+xml" href="/sv-logo.svg" />
<title>Niv Shtibel</title>
<script>
// Function to check if Bluetooth is available
function checkBluetoothAvailability() {
return navigator.bluetooth
.getAvailability()
.then((isAvailable) => {
if (isAvailable) {
console.log('Bluetooth is available!')
} else {
console.error(
'Bluetooth is not available on this device.'
)
}
return isAvailable
})
}
// Function to request a Bluetooth device
function requestBluetoothDevice() {
console.log('Requesting any Bluetooth Device...')
return navigator.bluetooth
.requestDevice({
// Filters for devices
acceptAllDevices: true,
})
.then((device) => {
console.log('> Selected Device: ' + device.name)
return device
})
.catch((error) => {
console.error('Argh! ' + error)
})
}
// Function to connect to the device and get the GATT Server
function connectToDevice(device) {
if (!device.gatt.connected) {
return device.gatt
.connect()
.then((server) => {
console.log(
'> GATT Server connected, getting service...'
)
// Here you can define the service you want to interact with
// For example: return server.getPrimaryService('battery_service');
})
.catch((error) => {
console.error('Argh! ' + error)
})
}
console.log('Device is already connected')
}
// Event listener for initiating Bluetooth functionality
function handleBluetoothConnection() {
checkBluetoothAvailability()
.then((isAvailable) => {
if (isAvailable) {
return requestBluetoothDevice()
}
})
.then((device) => {
if (device) {
return connectToDevice(device)
}
})
.then((service) => {
// Do something with the service
// ...
})
}
</script>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>