Skip to content

Commit

Permalink
Add a gattserverdisconnected event to report when a page needs to re-…
Browse files Browse the repository at this point in the history
…connect.

Fixes #159.
  • Loading branch information
jyasskin committed Jan 28, 2016
1 parent 48f256a commit 9751a8a
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 23 deletions.
60 changes: 57 additions & 3 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ spec: webidl
Promise<BluetoothDevice> requestDevice(RequestDeviceOptions options);
};
Bluetooth implements EventTarget;
Bluetooth implements BluetoothDeviceEventHandlers;
Bluetooth implements CharacteristicEventHandlers;
Bluetooth implements ServiceEventHandlers;
</pre>
Expand Down Expand Up @@ -1343,6 +1344,7 @@ spec: webidl
Promise&lt;BluetoothGATTRemoteServer> connectGATT();
};
BluetoothDevice implements EventTarget;
BluetoothDevice implements BluetoothDeviceEventHandlers;
BluetoothDevice implements CharacteristicEventHandlers;
BluetoothDevice implements ServiceEventHandlers;
</pre>
Expand Down Expand Up @@ -2136,9 +2138,6 @@ spec: webidl
Promise&lt;sequence&lt;BluetoothGATTService>>
getPrimaryServices(optional BluetoothServiceUUID service);
};
BluetoothGATTRemoteServer implements EventTarget;
BluetoothGATTRemoteServer implements CharacteristicEventHandlers;
BluetoothGATTRemoteServer implements ServiceEventHandlers;
</pre>

<div class="note" heading="{{BluetoothGATTRemoteServer}} attributes"
Expand Down Expand Up @@ -2992,6 +2991,12 @@ spec: webidl
or a <a href="#notification-events">value change notification/indication</a>.
</dd>

<dt><dfn event for="BluetoothDevice"><code>gattserverdisconnected</code></dfn></dt>
<dd>
Fired on a {{BluetoothDevice}} when
<a href="#disconnection-events">an active GATT connection is lost</a>.
</dd>

<dt><dfn event for="BluetoothGATTService"><code>serviceadded</code></dfn></dt>
<dd>
Fired on a new {{BluetoothGATTService}}
Expand All @@ -3018,6 +3023,43 @@ spec: webidl
</dl>
</section>

<section>
<h4 id="disconnection-events">Responding to Disconnection</h4>

<p>
When a <a>Bluetooth device</a> <var>device</var>'s <a>ATT Bearer</a> is lost
(e.g. because the remote device moved out of range
or the user used a platform feature to disconnect it),
for each {{BluetoothDevice}} <var>deviceObj</var> the UA MUST
<a>queue a task</a> on <var>deviceObj</var>'s <a>relevant settings object</a>'s
<a>responsible event loop</a>
to perform the following steps:
</p>
<ol class="algorithm">
<li>
If <code><var>deviceObj</var>@{{BluetoothDevice/[[representedDevice]]}}</code>
is not the <a>same device</a> as <var>device</var>,
abort these steps.
</li>
<li>
If <code>!<var>deviceObj</var>.gattServer.{{BluetoothGATTRemoteServer/connected}}</code>,
abort these steps.
</li>
<li>
Set <code><var>deviceObj</var>.gattServer.{{BluetoothGATTRemoteServer/connected}}</code>
to `false`.
</li>
<li>
<a>Fire an event</a> named {{gattserverdisconnected}}
with its {{Event/bubbles}} attribute initialized to `true`
at <code><var>deviceObj</var></code>.
<p class="note">
This event is <em>not</em> fired at the {{BluetoothGATTRemoteServer}}.
</p>
</li>
</ol>
</section>

<section>
<h4 id="notification-events">Responding to Notifications and Indications</h4>

Expand Down Expand Up @@ -3184,6 +3226,18 @@ spec: webidl
for the {{characteristicvaluechanged}} event type.
</p>

<pre class="idl">
[NoInterfaceObject]
interface BluetoothDeviceEventHandlers {
attribute EventHandler ongattserverdisconnected;
};
</pre>
<p>
<dfn attribute for="BluetoothDeviceEventHandlers">ongattserverdisconnected</dfn>
is an <a>Event handler IDL attribute</a>
for the {{gattserverdisconnected}} event type.
</p>

<pre class="idl">
[NoInterfaceObject]
interface ServiceEventHandlers {
Expand Down
Loading

0 comments on commit 9751a8a

Please sign in to comment.