-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmambo.service.ts
67 lines (40 loc) · 1.38 KB
/
mambo.service.ts
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
/// <reference path="./node_modules/@types/web-bluetooth/index.d.ts" />
import { Injectable } from '@angular/core';
import { Drone, MamboUUIDs } from '.';
@Injectable()
export class MamboService {
constructor() {
}
/**
* Runs a bluetooth scan, this triggers a search pop up in the browser for the user to select a device. Once that is done, `search` returns a promise with the selected Drone object
*/
public async search(): Promise<Drone> {
// [web-ble] Search for Device
const device: BluetoothDevice = await window.navigator.bluetooth.requestDevice(
{
filters: [{ namePrefix: 'Mambo' }],
optionalServices: MamboUUIDs.services
});
console.log('Connecting to drone...');
const drone = new Drone(device);
await drone.connect();
return drone;
}
}
// public search2() {
// return new Observable(observer => {
// let drone;
// navigator.bluetooth.requestDevice(
// {
// filters: [{ namePrefix: 'Mambo' }],
// optionalServices: MamboUUIDs.services
// }).then(device => {
// drone = new Drone(device);
// drone.connect()
// .then(() => {
// observer.next(drone);
// });
// });
// return () => drone && drone.disconnect();
// })
// }