-
Notifications
You must be signed in to change notification settings - Fork 0
/
testScanning.html
50 lines (43 loc) · 1.38 KB
/
testScanning.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
<html><body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web/buttplug.min.js" integrity="sha256-7KTanv3NixZdkIVK8qf3whxGk6UP30x0b0nSyDpfHts=" crossorigin="anonymous"></script>
<div onclick="startScanning()">
click to start scanning
</div>
<div style="position:absolute; bottom:0;" id=log></div>
<script>
var client;
function log(msg) {
msg = Date.now() + ": " + msg;
console.log(msg);
var l = document.getElementById('log');
l.append(document.createElement("br"));
l.append(msg);
}
doInit = async function () {
log("Init start");
const connector = new Buttplug.ButtplugEmbeddedConnectorOptions();
try {
await Buttplug.buttplugInit();
} catch (e) {
log("Failed to init: " + e);
}
client = new Buttplug.ButtplugClient("JSFiddle");
log("Waiting for connect");
await client.connect(connector);
log("adding listeners");
client.addListener("deviceadded", (device) => {
log(`Device Connected: ${device.Name}`);
});
client.addListener("deviceremoved", (device) => {
log(`Device Removed: ${device.Name}`)
});
client.addListener("scanningfinished", () => {
log("Scanning finished");
});
};
doInit().then();
function startScanning() {
client.startScanning().then(function() { log("Scanning started") }).catch(function() { log("scanning did not start" )});
}
</script>
</body></html>