diff --git a/index.bs b/index.bs index 04f1e30..cd40e8f 100644 --- a/index.bs +++ b/index.bs @@ -2896,35 +2896,74 @@ spec: html

The connect() method, when invoked, - MUST return a new promise promise and - run the following steps in parallel: + MUST perform the following steps:

    +
  1. Let |promise| be a new promise.
  2. If this.device.{{[[representedDevice]]}} is `null`, - reject promise with a {{NetworkError}} and abort these steps. -
  3. -
  4. - If this.device.{{[[representedDevice]]}} has no ATT Bearer, - attempt to create one using the procedures described - in "Connection Establishment" under GAP Interoperability Requirements. + queue a task to reject |promise| with a {{NetworkError}}, + return |promise|, + and abort these steps.
  5. - If this attempt fails, - reject promise with a {{NetworkError}} and abort these steps. + Add |promise| to this.{{[[activeAlgorithms]]}}.
  6. - Queue a task to perform the following sub-steps: + Return |promise| and run the following steps in parallel:
    1. - If this.device.{{[[representedDevice]]}} is `null`, - reject promise with a {{NetworkError}} and abort these steps. -
    2. -
    3. - Set `this.connected` to `true`. + If this.device.{{[[representedDevice]]}} has no ATT Bearer, + do the following sub-steps: +
        +
      1. + Attempt to create an ATT Bearer using the procedures described + in "Connection Establishment" under GAP Interoperability Requirements. + Abort this attempt if |promise| is removed from this.{{[[activeAlgorithms]]}}. + + Note: These procedures can wait forever + if a connectable advertisement isn't received. + The website should call {{disconnect()}} + if it no longer wants to connect. +
      2. +
      3. + If this attempt was aborted because + |promise| was removed from this.{{[[activeAlgorithms]]}}, + reject promise with an {{AbortError}} and abort these steps. +
      4. +
      5. + If this attempt failed for another reason, + reject promise with a {{NetworkError}} and abort these steps. +
      6. +
    4. - Resolve promise with this. + Queue a task to perform the following sub-steps: +
        +
      1. + If |promise| is not in this.{{[[activeAlgorithms]]}}, + reject promise with an {{AbortError}}, + garbage-collect the connection of + this.{{[[representedDevice]]}}, + and abort these steps. +
      2. +
      3. + Remove |promise| from this.{{[[activeAlgorithms]]}}. +
      4. +
      5. + If this.device.{{[[representedDevice]]}} is `null`, + reject promise with a {{NetworkError}}, + garbage-collect the connection of + this.{{[[representedDevice]]}}, + and abort these steps. +
      6. +
      7. + Set `this.connected` to `true`. +
      8. +
      9. + Resolve promise with this. +
      10. +
  7. @@ -2937,6 +2976,9 @@ spec: html MUST perform the following steps:

      +
    1. + Clear this.{{[[activeAlgorithms]]}} + to abort any active `connect()` calls.
    2. If this.{{connected}} is false, abort these steps.
    3. @@ -2947,13 +2989,45 @@ spec: html Let device be this.device.{{[[representedDevice]]}}.
    4. - In parallel: - if, for all {{BluetoothDevice}}s deviceObj in the whole UA - with deviceObj.{{[[representedDevice]]}} - the same device as device, - deviceObj.gatt.{{BluetoothRemoteGATTServer/connected}} is `false`, - the UA SHOULD destroy - device's ATT Bearer. + Garbage-collect the connection of |device|. +
    5. +
    +
+ +
+

+ To garbage-collect the connection of a |device|, + the UA must, do the following steps in parallel: +

+
    +
  1. + If systems that aren't using this API, + either inside or outside of the UA, + are using the device's ATT Bearer, + abort this algorithm. +
  2. +
  3. + For all {{BluetoothDevice}}s deviceObj in the whole UA: +
      +
    1. + If deviceObj.{{[[representedDevice]]}} is + not the same device as device, + continue to the next |deviceObj|. +
    2. +
    3. + If deviceObj.gatt.{{BluetoothRemoteGATTServer/connected}} + is `true`, + abort this algorithm. +
    4. +
    5. + If deviceObj.gatt.{{[[activeAlgorithms]]}} + contains the {{Promise}} of a call to {{connect()}}, + abort this algorithm. +
    6. +
    +
  4. +
  5. + Destroy device's ATT Bearer.