Skip to content

Commit

Permalink
Add SocketInfo, update opened promise
Browse files Browse the repository at this point in the history
The `opened` promise resolves to a `SocketInfo`.

`SocketInfo` provides `remoteAddress` and (optionally) `localAddress`
  • Loading branch information
jasnell authored Sep 30, 2023
1 parent 1d42a50 commit f078957
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,18 @@ A basic example of using connect with an echo server.
The {{Socket}} class is an instance of the [=socket=] concept. It should not be instantiated directly (`new Socket()`), but instead created by calling {{connect()}}. A constructor for {{Socket}} is intentionally not specified, and is left to implementors to create.

<pre class="idl">
[Exposed=*]
dictionary SocketInfo {
DOMString remoteAddress = null;
DOMString localAddress = null;
};

[Exposed=*]
interface Socket {
readonly attribute ReadableStream readable;
readonly attribute WritableStream writable;

readonly attribute Promise&lt;undefined> opened;
readonly attribute Promise&lt;SocketInfo> opened;

readonly attribute Promise&lt;undefined> closed;
Promise&lt;undefined> close(optional any reason);
Expand Down Expand Up @@ -162,6 +168,11 @@ The {{opened}} attribute is a promise that is resolved when the socket connectio
successfully established, or is rejected if the connection fails. For sockets use secure-transport,
the resolution of the {{opened}} promise indicates the completion of the secure handshake.

The {{opened}} promise resolves a {{SocketInfo}} dictionary that optionally provides details
about the connection that has been established.

By default, the {{opened}} promise is {{marked as handled}}.

<h4 id="closed-attribute">closed</h4>

The {{closed}} attribute is a promise which can be used to keep track of the socket state. It gets resolved under the
Expand Down Expand Up @@ -296,7 +307,7 @@ At any point during the creation of the {{Socket}} instance, `connect` may throw
{{secureTransport}} member
</dt>
<dd>
The secure transport mode to use.
The secure transport mode to use.f
<dl>
<dt>{{off}}</dt>
<dd>A connection is established in plain text.</dd>
Expand All @@ -321,6 +332,24 @@ At any point during the creation of the {{Socket}} instance, `connect` may throw
</dd>
</dl>

<h3 id="socketinfo-dictionary">`SocketInfo` dictionary</h3>

<d1>
<dt>
{{remoteAddress}} member
</dt>
<dd>
Provides the hostname/port combo of the remote peer the {{Socket}} is connected to, for example `"example.com:443"`.
This value may or may not be the same as the address provided to the {{connect()}} method used to create the {{Socket}}.
</dd>
<dt>
{{localAddress}} member
</dt>
<dd>
Optionally provides the hostname/port combo of the local network endpoint, for example `"localhost:12345"`.
</dd>
</d1>

<h3 id="anysocketaddress-type">`AnySocketAddress` type</h3>

<dl>
Expand Down

0 comments on commit f078957

Please sign in to comment.