forked from abandonware/bleno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
151 lines (105 loc) · 4.73 KB
/
index.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Type definitions for bleno 0.4
// Project: https://github.com/sandeepmistry/bleno
// Definitions by: Manuel Francisco Naranjo <[email protected]>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
type State = 'poweredOn' | 'poweredOff' | 'unauthorized' | 'unsupported' | 'unknown' | 'resetting';
type Property = 'read' | 'write' | 'indicate' | 'notify' | 'writeWithoutResponse';
interface CharacteristicOptions {
uuid: string;
properties?: ReadonlyArray<Property> | null;
secure?: ReadonlyArray<Property> | null;
value?: Buffer | null;
descriptors?: ReadonlyArray<Descriptor> | null;
onIndicate?: (() => void) | null;
onNotify?: (() => void) | null;
onReadRequest?: ((
offset: number,
callback: (result: number, data?: Buffer) => void
) => void) | null;
onSubscribe?: ((maxValueSize: number, updateValueCallback: (data: Buffer) => void) => void) | null;
onUnsubscribe?: (() => void) | null;
onWriteRequest?: ((
data: Buffer,
offset: number,
withoutResponse: boolean,
callback: (result: number) => void
) => void) | null;
}
declare class Characteristic {
uuid: string;
properties: ReadonlyArray<Property>;
secure: ReadonlyArray<Property>;
value: Buffer | null;
descriptors: ReadonlyArray<Descriptor>;
constructor(options: CharacteristicOptions);
onIndicate(): void;
onNotify(): void;
onReadRequest(offset: number, callback: (result: number, data?: Buffer) => void): void;
onSubscribe(maxValueSize: number, updateValueCallback: (data: Buffer) => void): void;
onUnsubscribe(): void;
onWriteRequest(data: Buffer, offset: number, withoutResponse: boolean, callback: (result: number) => void): void;
toString(): string;
readonly RESULT_ATTR_NOT_LONG: number;
readonly RESULT_INVALID_ATTRIBUTE_LENGTH: number;
readonly RESULT_INVALID_OFFSET: number;
readonly RESULT_SUCCESS: number;
readonly RESULT_UNLIKELY_ERROR: number;
static readonly RESULT_ATTR_NOT_LONG: number;
static readonly RESULT_INVALID_ATTRIBUTE_LENGTH: number;
static readonly RESULT_INVALID_OFFSET: number;
static readonly RESULT_SUCCESS: number;
static readonly RESULT_UNLIKELY_ERROR: number;
}
interface DescriptorOptions {
uuid: string;
value?: Buffer | string | null;
}
declare class Descriptor {
uuid: string;
value: Buffer;
constructor(options: DescriptorOptions);
toString(): string;
}
interface PrimaryServiceOptions {
uuid: string;
characteristics?: ReadonlyArray<Characteristic> | null;
}
declare class PrimaryService {
uuid: string;
characteristics: ReadonlyArray<Characteristic>;
constructor(options: PrimaryServiceOptions);
toString(): string;
}
interface Bleno extends NodeJS.EventEmitter {
readonly Characteristic: typeof Characteristic;
readonly Descriptor: typeof Descriptor;
readonly PrimaryService: typeof PrimaryService;
readonly address: string;
readonly mtu: number;
readonly platform: string;
readonly rssi: number;
readonly state: State;
disconnect(): void;
setServices(services: ReadonlyArray<PrimaryService>, callback?: (arg: Error | undefined | null) => void): void;
startAdvertising(name: string, serviceUuids?: ReadonlyArray<string>, callback?: (arg: Error | undefined | null) => void): void;
startAdvertisingIBeacon(uuid: string, major: number, minor: number, measuredPower: number, callback?: (arg: Error | undefined | null) => void): void;
startAdvertisingWithEIRData(advertisementData: Buffer, callback?: (arg: Error | undefined | null) => void): void;
startAdvertisingWithEIRData(advertisementData: Buffer, scanData: Buffer, callback?: (arg: Error | undefined | null) => void): void;
stopAdvertising(callback?: () => void): void;
updateRssi(callback?: (err: null, rssi: number) => void): void;
on(event: 'stateChange', cb: (state: State) => void): this;
on(event: 'platform', cb: (platform: NodeJS.Platform) => void): this;
on(event: 'addressChange', cb: (address: string) => void): this;
on(event: 'accept', cb: (address: string) => void): this;
on(event: 'mtuChange', cb: (mtu: number) => void): this;
on(event: 'disconnect', cb: (clientAddress: string) => void): this;
on(event: 'advertisingStart', cb: (err?: Error | null) => void): this;
on(event: 'advertisingStartError', cb: (err: Error) => void): this;
on(event: 'advertisingStop', cb: () => void): this;
on(event: 'servicesSet', cb: (err?: Error | null) => void): this;
on(event: 'servicesSetError', cb: (err: Error) => void): this;
on(event: 'rssiUpdate', cb: (rssi: number) => void): this;
}
declare const bleno: Bleno;
export = bleno;