forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noble.d.ts
108 lines (89 loc) · 5.2 KB
/
noble.d.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
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
97
98
99
100
101
102
103
104
105
106
107
// Type definitions for noble
// Project: https://github.com/sandeepmistry/noble
// Definitions by: Seon-Wook Park <https://github.com/swook>, Hans Bakker <https://github.com/wind-rider>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "noble" {
import events = require("events");
export function startScanning(): void;
export function startScanning(serviceUUIDs: string[]): void;
export function startScanning(serviceUUIDs: string[], allowDuplicates: boolean): void;
export function stopScanning(): void;
export function on(event: string, listener: Function): events.EventEmitter;
export function on(event: "stateChange", listener: (state: string) => void): events.EventEmitter;
export function on(event: "scanStart", listener: () => void): events.EventEmitter;
export function on(event: "scanStop", listener: () => void): events.EventEmitter;
export function on(event: "discover", listener: (peripheral: Peripheral) => void): events.EventEmitter;
export class Peripheral extends events.EventEmitter {
uuid: string;
advertisement: Advertisement;
rssi: number;
services: Service[];
state: string;
connect(callback?: (error: string) => void): void;
disconnect(callback?: () => void): void;
updateRssi(callback?: (error: string, rssi: number) => void): void;
discoverServices(serviceUUIDs: string[], callback?: (error: string, services: Service[]) => void): void;
discoverAllServicesAndCharacteristics(callback?: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
discoverSomeServicesAndCharacteristics(serviceUUIDs: string[], characteristicUUIDs: string[], callback?: (error: string, services: Service[], characteristics: Characteristic[]) => void): void;
readHandle(handle: Buffer, callback: (error: string, data: Buffer) => void): void;
writeHandle(handle: Buffer, data: Buffer, withoutResponse: boolean, callback: (error: string) => void): void;
toString(): string;
on(event: string, listener: Function): this;
on(event: "connect", listener: (error: string) => void): this;
on(event: "disconnect", listener: (error: string) => void): this;
on(event: "rssiUpdate", listener: (rssi: number) => void): this;
on(event: "servicesDiscover", listener: (services: Service[]) => void): this;
}
export interface Advertisement {
localName: string;
serviceData: Buffer;
txPowerLevel: number;
manufacturerData: Buffer;
serviceUuids: string[];
}
export class Service extends events.EventEmitter {
uuid: string;
name: string;
type: string;
includedServiceUuids: string[];
characteristics: Characteristic[];
discoverIncludedServices(serviceUUIDs: string[], callback?: (error: string, includedServiceUuids: string[]) => void): void;
discoverCharacteristics(characteristicUUIDs: string[], callback?: (error: string, characteristics: Characteristic[]) => void): void;
toString(): string;
on(event: string, listener: Function): this;
on(event: "includedServicesDiscover", listener: (includedServiceUuids: string[]) => void): this;
on(event: "characteristicsDiscover", listener: (characteristics: Characteristic[]) => void): this;
}
export class Characteristic extends events.EventEmitter {
uuid: string;
name: string;
type: string;
properties: string[];
descriptors: Descriptor[];
read(callback?: (error: string, data: Buffer) => void): void;
write(data: Buffer, notify: boolean, callback?: (error: string) => void): void;
broadcast(broadcast: boolean, callback?: (error: string) => void): void;
notify(notify: boolean, callback?: (error: string) => void): void;
discoverDescriptors(callback?: (error: string, descriptors: Descriptor[]) => void): void;
toString(): string;
on(event: string, listener: Function): this;
on(event: string, option: boolean, listener: Function): this;
on(event: "read", listener: (data: Buffer, isNotification: boolean) => void): this;
on(event: "write", withoutResponse: boolean, listener: (error: string) => void): this;
on(event: "broadcast", listener: (state: string) => void): this;
on(event: "notify", listener: (state: string) => void): this;
on(event: "descriptorsDiscover", listener: (descriptors: Descriptor[]) => void): this;
}
export class Descriptor extends events.EventEmitter {
uuid: string;
name: string;
type: string;
readValue(callback?: (error: string, data: Buffer) => void): void;
writeValue(data: Buffer, callback?: (error: string) => void): void;
toString(): string;
on(event: string, listener: Function): this;
on(event: "valueRead", listener: (error: string, data: Buffer) => void): this;
on(event: "valueWrite", listener: (error: string) => void): this;
}
}