Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions files/en-us/web/api/bluetoothremotegattserver/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Server on a remote device.
physically connected.
- {{DOMxRef("BluetoothRemoteGATTServer.device")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : A reference to the {{DOMxRef("BluetoothDevice")}} running the server.
- {{DOMxRef("BluetoothRemoteGATTServer.maxWriteWithoutResponseSize")}} {{ReadOnlyInline}} {{Experimental_Inline}}
- : The largest payload a write without response can send in a single ATT packet for the current connection.

## Instance methods

Expand All @@ -34,6 +36,11 @@ Server on a remote device.
- : Returns a promise to a list of primary {{DOMxRef("BluetoothRemoteGATTService")}} objects
offered by the Bluetooth device for a specified `BluetoothServiceUUID`.

## Events

- {{DOMxRef("BluetoothRemoteGATTServer.maxwritewithoutresponsesizechanged_event", "maxwritewithoutresponsesizechanged")}} {{Experimental_Inline}}
- : Fired when the known maximum write-without-response payload size changes.

## Specifications

{{Specifications}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "BluetoothRemoteGATTServer: maxWriteWithoutResponseSize property"
short-title: maxWriteWithoutResponseSize
slug: Web/API/BluetoothRemoteGATTServer/maxWriteWithoutResponseSize
page-type: web-api-instance-property
status:
- experimental
---

{{APIRef("Bluetooth API")}}{{SecureContext_Header}}

The **`BluetoothRemoteGATTServer.maxWriteWithoutResponseSize`** read-only property returns the largest payload, in bytes, that {{domxref("BluetoothRemoteGATTCharacteristic.writeValueWithoutResponse()")}} can send to the connected device in a single ATT packet without fragmentation or rejection due to its size.

The value reflects the maximum currently known to the browser for this connection, not necessarily the final negotiated maximum. It can change after connection, for example when the browser learns of an ATT MTU update. Listen for the {{domxref("BluetoothRemoteGATTServer.maxwritewithoutresponsesizechanged_event", "maxwritewithoutresponsesizechanged")}} event or read the property before writing to account for updates. Some platforms do not report subsequent MTU changes to the browser.

## Value

An integer representing a number of bytes. If the platform does not report the connection's MTU, the default is 20 bytes.

## Examples

This example splits a byte array into chunks that fit in a single write-without-response packet:

```js
async function writeInChunks(characteristic, data) {
const server = characteristic.service.device.gatt;
const chunkSize = server.maxWriteWithoutResponseSize ?? 20;

for (let offset = 0; offset < data.byteLength; offset += chunkSize) {
await characteristic.writeValueWithoutResponse(
data.subarray(offset, offset + chunkSize),
);
}
}
```

For long transfers, re-read the property before each write or listen for `maxwritewithoutresponsesizechanged` to update the chunk size. Writes can still fail if the connection is lost or the device rejects them.

## Specifications

- [Web Bluetooth specification proposal](https://github.com/whatwg/bluetooth/pull/672)

## See also

- {{domxref("BluetoothRemoteGATTServer.maxwritewithoutresponsesizechanged_event", "maxwritewithoutresponsesizechanged")}} event
- {{domxref("BluetoothRemoteGATTCharacteristic.writeValueWithoutResponse()")}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
title: "BluetoothRemoteGATTServer: maxwritewithoutresponsesizechanged event"
short-title: maxwritewithoutresponsesizechanged
slug: Web/API/BluetoothRemoteGATTServer/maxwritewithoutresponsesizechanged_event
page-type: web-api-event
status:
- experimental
---

{{APIRef("Bluetooth API")}}{{SecureContext_Header}}

The **`maxwritewithoutresponsesizechanged`** event of the {{domxref("BluetoothRemoteGATTServer")}} interface fires when the browser updates the known value of {{domxref("BluetoothRemoteGATTServer.maxWriteWithoutResponseSize")}} for a connection. For example, this can happen when the browser learns that the connection's ATT MTU has changed.

The event does not include the new size; read the property to get the current value. On platforms that do not report MTU changes to the browser, the value may remain constant and the event may not fire.

## Syntax

Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.

```js-nolint
addEventListener("maxwritewithoutresponsesizechanged", (event) => { })

onmaxwritewithoutresponsesizechanged = (event) => { }
```

## Event type

A generic {{domxref("Event")}}.

## Examples

```js
const server = device.gatt;

server.addEventListener("maxwritewithoutresponsesizechanged", () => {
console.log(`Maximum write payload: ${server.maxWriteWithoutResponseSize}`);
});

await server.connect();
```

## Specifications

- [Web Bluetooth specification proposal](https://github.com/whatwg/bluetooth/pull/672)

## See also

- {{domxref("BluetoothRemoteGATTServer.maxWriteWithoutResponseSize")}}
- {{domxref("BluetoothRemoteGATTCharacteristic.writeValueWithoutResponse()")}}
Loading