1dictionary BluetoothDataFilterInit {
2  BufferSource dataPrefix;
3  BufferSource mask;
4};
5
6dictionary BluetoothLEScanFilterInit {
7  sequence<BluetoothServiceUUID> services;
8  DOMString name;
9  DOMString namePrefix;
10  // Maps unsigned shorts to BluetoothDataFilters.
11  object manufacturerData;
12  // Maps BluetoothServiceUUIDs to BluetoothDataFilters.
13  object serviceData;
14};
15
16dictionary RequestDeviceOptions {
17  sequence<BluetoothLEScanFilterInit> filters;
18  sequence<BluetoothServiceUUID> optionalServices = [];
19  boolean acceptAllDevices = false;
20};
21
22[Exposed=Window, SecureContext]
23interface Bluetooth : EventTarget {
24  Promise<boolean> getAvailability();
25  attribute EventHandler onavailabilitychanged;
26  [SameObject]
27  readonly attribute BluetoothDevice? referringDevice;
28  Promise<sequence<BluetoothDevice>> getDevices();
29  Promise<BluetoothDevice> requestDevice(RequestDeviceOptions options);
30};
31
32Bluetooth includes BluetoothDeviceEventHandlers;
33Bluetooth includes CharacteristicEventHandlers;
34Bluetooth includes ServiceEventHandlers;
35
36dictionary BluetoothPermissionDescriptor : PermissionDescriptor {
37  DOMString deviceId;
38  // These match RequestDeviceOptions.
39  sequence<BluetoothLEScanFilterInit> filters;
40  sequence<BluetoothServiceUUID> optionalServices = [];
41  boolean acceptAllDevices = false;
42};
43
44dictionary AllowedBluetoothDevice {
45  required DOMString deviceId;
46  required boolean mayUseGATT;
47  // An allowedServices of "all" means all services are allowed.
48  required (DOMString or sequence<UUID>) allowedServices;
49};
50dictionary BluetoothPermissionStorage {
51  required sequence<AllowedBluetoothDevice> allowedDevices;
52};
53
54[Exposed=Window]
55interface BluetoothPermissionResult : PermissionStatus {
56  attribute FrozenArray<BluetoothDevice> devices;
57};
58
59[
60  Exposed=Window,
61  SecureContext
62]
63interface ValueEvent : Event {
64  constructor(DOMString type, optional ValueEventInit initDict = {});
65  readonly attribute any value;
66};
67
68dictionary ValueEventInit : EventInit {
69  any value = null;
70};
71
72[Exposed=Window, SecureContext]
73interface BluetoothDevice : EventTarget {
74  readonly attribute DOMString id;
75  readonly attribute DOMString? name;
76  readonly attribute BluetoothRemoteGATTServer? gatt;
77
78  Promise<undefined> watchAdvertisements(
79      optional WatchAdvertisementsOptions options = {});
80  readonly attribute boolean watchingAdvertisements;
81};
82BluetoothDevice includes BluetoothDeviceEventHandlers;
83BluetoothDevice includes CharacteristicEventHandlers;
84BluetoothDevice includes ServiceEventHandlers;
85
86dictionary WatchAdvertisementsOptions {
87  AbortSignal signal;
88};
89
90[Exposed=Window, SecureContext]
91interface BluetoothManufacturerDataMap {
92  readonly maplike<unsigned short, DataView>;
93};
94[Exposed=Window, SecureContext]
95interface BluetoothServiceDataMap {
96  readonly maplike<UUID, DataView>;
97};
98[
99  Exposed=Window,
100  SecureContext
101]
102interface BluetoothAdvertisingEvent : Event {
103  constructor(DOMString type, BluetoothAdvertisingEventInit init);
104  [SameObject]
105  readonly attribute BluetoothDevice device;
106  readonly attribute FrozenArray<UUID> uuids;
107  readonly attribute DOMString? name;
108  readonly attribute unsigned short? appearance;
109  readonly attribute byte? txPower;
110  readonly attribute byte? rssi;
111  [SameObject]
112  readonly attribute BluetoothManufacturerDataMap manufacturerData;
113  [SameObject]
114  readonly attribute BluetoothServiceDataMap serviceData;
115};
116dictionary BluetoothAdvertisingEventInit : EventInit {
117  required BluetoothDevice device;
118  sequence<(DOMString or unsigned long)> uuids;
119  DOMString name;
120  unsigned short appearance;
121  byte txPower;
122  byte rssi;
123  BluetoothManufacturerDataMap manufacturerData;
124  BluetoothServiceDataMap serviceData;
125};
126
127[Exposed=Window, SecureContext]
128interface BluetoothRemoteGATTServer {
129  [SameObject]
130  readonly attribute BluetoothDevice device;
131  readonly attribute boolean connected;
132  Promise<BluetoothRemoteGATTServer> connect();
133  undefined disconnect();
134  Promise<BluetoothRemoteGATTService> getPrimaryService(BluetoothServiceUUID service);
135  Promise<sequence<BluetoothRemoteGATTService>>
136    getPrimaryServices(optional BluetoothServiceUUID service);
137};
138
139[Exposed=Window, SecureContext]
140interface BluetoothRemoteGATTService : EventTarget {
141  [SameObject]
142  readonly attribute BluetoothDevice device;
143  readonly attribute UUID uuid;
144  readonly attribute boolean isPrimary;
145  Promise<BluetoothRemoteGATTCharacteristic>
146    getCharacteristic(BluetoothCharacteristicUUID characteristic);
147  Promise<sequence<BluetoothRemoteGATTCharacteristic>>
148    getCharacteristics(optional BluetoothCharacteristicUUID characteristic);
149  Promise<BluetoothRemoteGATTService>
150    getIncludedService(BluetoothServiceUUID service);
151  Promise<sequence<BluetoothRemoteGATTService>>
152    getIncludedServices(optional BluetoothServiceUUID service);
153};
154BluetoothRemoteGATTService includes CharacteristicEventHandlers;
155BluetoothRemoteGATTService includes ServiceEventHandlers;
156
157[Exposed=Window, SecureContext]
158interface BluetoothRemoteGATTCharacteristic : EventTarget {
159  [SameObject]
160  readonly attribute BluetoothRemoteGATTService service;
161  readonly attribute UUID uuid;
162  readonly attribute BluetoothCharacteristicProperties properties;
163  readonly attribute DataView? value;
164  Promise<BluetoothRemoteGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor);
165  Promise<sequence<BluetoothRemoteGATTDescriptor>>
166    getDescriptors(optional BluetoothDescriptorUUID descriptor);
167  Promise<DataView> readValue();
168  Promise<undefined> writeValue(BufferSource value);
169  Promise<undefined> writeValueWithResponse(BufferSource value);
170  Promise<undefined> writeValueWithoutResponse(BufferSource value);
171  Promise<BluetoothRemoteGATTCharacteristic> startNotifications();
172  Promise<BluetoothRemoteGATTCharacteristic> stopNotifications();
173};
174BluetoothRemoteGATTCharacteristic includes CharacteristicEventHandlers;
175
176[Exposed=Window, SecureContext]
177interface BluetoothCharacteristicProperties {
178  readonly attribute boolean broadcast;
179  readonly attribute boolean read;
180  readonly attribute boolean writeWithoutResponse;
181  readonly attribute boolean write;
182  readonly attribute boolean notify;
183  readonly attribute boolean indicate;
184  readonly attribute boolean authenticatedSignedWrites;
185  readonly attribute boolean reliableWrite;
186  readonly attribute boolean writableAuxiliaries;
187};
188
189[Exposed=Window, SecureContext]
190interface BluetoothRemoteGATTDescriptor {
191  [SameObject]
192  readonly attribute BluetoothRemoteGATTCharacteristic characteristic;
193  readonly attribute UUID uuid;
194  readonly attribute DataView? value;
195  Promise<DataView> readValue();
196  Promise<undefined> writeValue(BufferSource value);
197};
198
199[SecureContext]
200interface mixin CharacteristicEventHandlers {
201  attribute EventHandler oncharacteristicvaluechanged;
202};
203
204[SecureContext]
205interface mixin BluetoothDeviceEventHandlers {
206  attribute EventHandler onadvertisementreceived;
207  attribute EventHandler ongattserverdisconnected;
208};
209
210[SecureContext]
211interface mixin ServiceEventHandlers {
212  attribute EventHandler onserviceadded;
213  attribute EventHandler onservicechanged;
214  attribute EventHandler onserviceremoved;
215};
216
217typedef DOMString UUID;
218
219[Exposed=Window]
220interface BluetoothUUID {
221  static UUID getService((DOMString or unsigned long) name);
222  static UUID getCharacteristic((DOMString or unsigned long) name);
223  static UUID getDescriptor((DOMString or unsigned long) name);
224
225  static UUID canonicalUUID([EnforceRange] unsigned long alias);
226};
227
228typedef (DOMString or unsigned long) BluetoothServiceUUID;
229typedef (DOMString or unsigned long) BluetoothCharacteristicUUID;
230typedef (DOMString or unsigned long) BluetoothDescriptorUUID;
231
232[SecureContext]
233partial interface Navigator {
234  [SameObject]
235  readonly attribute Bluetooth? bluetooth;
236};
237