Skip to content

Commit 86b110d

Browse files
wangw-1991backkem
authored andcommitted
Some small changes:
- Add link to "Use Cases" in EXPLAINER.md - Adjust the order of paragraphs to make them unified - Remove "Examples" chapter temporarily: there are two examples, one is moved to the corresponding chapter, the other one was removed due to duplication. Maybe we can add the actual use cases based on this API in the future. - Fix some errors.
1 parent 1ce345b commit 86b110d

File tree

1 file changed

+99
-134
lines changed

1 file changed

+99
-134
lines changed

index.bs

Lines changed: 99 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The Local Peer-to-Peer API aims to give browsers the means to communicate direct
2626

2727
Many modern Web security measures rely on the presence of naming, signaling and certificate authorities. Local use-cases where these authorities are not readily available have started lagging behind in user experience or are not supported altogether. The Local Peer-to-Peer API aims to bring back first-class support for local communication use-cases while working within the same strict user-friendliness, security and privacy requirements.
2828

29-
Examples of potential uses of this API include: Collaboration tools that work during an internet outage or emergency situations, connecting to your NAS, your home security system, your robotic assistant doing the dishes or your GPU farm in the basement that's running your personalized virtual assistant.
29+
Examples of potential uses of this API include: Collaboration tools that work during an internet outage or emergency situations, connecting to your NAS, your home security system, your robotic assistant doing the dishes or your GPU farm in the basement that's running your personalized virtual assistant. See also [Use Cases](https://github.com/WICG/local-peer-to-peer/blob/main/EXPLAINER.md#use-cases).
3030

3131
This specification aims to strike a balance between creating a powerful new building block for developers and providing a seamless, secure and privacy preserving experience for browser users. As an example: while the API doesn't provide raw socket access, it does aim to give developers the flexibility to innovate on top by providing a persistent, two-way communication channel with little overhead.
3232

@@ -222,11 +222,11 @@ The capabilities of the Local WebTransport session are defined in [[!webtranspor
222222

223223
Note: The WebTransport-over-QUIC protocol is yet to be defined. Potentially considering earlier work such as [draft-vvv-webtransport-quic](https://datatracker.ietf.org/doc/html/draft-vvv-webtransport-quic-02).
224224

225+
<section algorithm="LP2PReceiver">
226+
225227
LP2PReceiver Interface {#lp2p-receiver}
226228
================================================
227229

228-
<section algorithm="LP2PReceiver">
229-
230230
The <dfn interface>LP2PReceiver</dfn> interface allows advertising on the local network, enabling other peers to discover and connect.
231231

232232
<pre class="idl">
@@ -265,25 +265,6 @@ dictionary LP2PConnectionEventInit : EventInit {
265265
};
266266
</pre>
267267

268-
Examples {#lp2p-receiver-examples}
269-
---------------------------------
270-
271-
Example: Setting up a receiver to listen for connections:
272-
273-
274-
<pre class='example' highlight='js'>
275-
const receiver = new LP2PReceiver({
276-
nickname: "example-receiver",
277-
});
278-
receiver.onconnection = e => {
279-
console.log("Connection established!");
280-
const conn = e.connection;
281-
};
282-
283-
// Blocks until permission is received.
284-
await receiver.start();
285-
</pre>
286-
287268
Events {#lp2p-receiver-events}
288269
------------------------------
289270

@@ -326,6 +307,24 @@ The following are the <a>event handlers</a> (and their corresponding <a>event ha
326307
</tbody>
327308
</table>
328309

310+
Examples {#lp2p-receiver-examples}
311+
---------------------------------
312+
313+
Example: Setting up a receiver to listen for connections:
314+
315+
<pre class='example' highlight='js'>
316+
const receiver = new LP2PReceiver({
317+
nickname: "example-receiver",
318+
});
319+
receiver.onconnection = e => {
320+
console.log("Connection established!");
321+
const conn = e.connection;
322+
};
323+
324+
// Blocks until permission is received.
325+
await receiver.start();
326+
</pre>
327+
329328
</section>
330329

331330
<section algorithm="LP2PRequest">
@@ -358,7 +357,6 @@ Examples {#lp2p-request-examples}
358357

359358
Example: Setting up a request for a connection:
360359

361-
362360
<pre class='example' highlight='js'>
363361
const request = new LP2PRequest({
364362
nickname: "example-request",
@@ -384,10 +382,6 @@ interface LP2PConnection : EventTarget {
384382
};
385383
</pre>
386384

387-
</section>
388-
389-
<section algorithm="LP2PDataChannel">
390-
391385
LP2PQuicTransport Interface Extensions {#lp2p-connection-quic-transport-extensions}
392386
-------------------------------------------------------------------
393387

@@ -439,11 +433,14 @@ const transport = new LP2PQuicTransport(conn);
439433
await transport.ready;
440434
</pre>
441435

436+
</section>
437+
438+
<section algorithm="LP2PDataChannel">
442439

443440
The LP2PDataChannel Interface {#lp2p-data-channel}
444441
==========================================
445442

446-
The LP2PDataChannel interface represents a bi-directional data channel between two peers. An LP2PDataChannel is created via a [factory method](#lp2p-data-channel-extensions) on a LP2PConnection object.
443+
The LP2PDataChannel interface represents a bi-directional data channel between two peers. An LP2PDataChannel is created via a [factory method](#lp2p-connection-data-channel-extensions) on a LP2PConnection object.
447444

448445
Note: The LP2PDataChannel interface is purposefully kept as close as possible to the [RTCDataChannel](https://www.w3.org/TR/webrtc/#rtcdatachannel) interface defined in [[!webrtc]]. The aim is to allow seamless transition of developers that are familiar with WebRTC as well as allowing libraries to easily work with both the [[!webrtc]] and LP2P API.
449446

@@ -477,7 +474,6 @@ dictionary LP2PDataChannelInit {
477474
};
478475
</pre>
479476

480-
481477
Events {#lp2p-data-channel-events}
482478
---------------------------------
483479

@@ -520,10 +516,10 @@ The following event is [=fire an event|fired=] at the {{LP2PDataChannel}} object
520516
</tbody>
521517
</table>
522518

523-
Data Channel Event handlers {#lp2p-data-channel-event-handlers}
519+
Event handlers {#lp2p-data-channel-event-handlers}
524520
---------------------------------------------------------------
525521

526-
The following are the <a>event handlers</a> (and their corresponding <a>event handler event types</a>) that must be supported, as <a>event handler IDL attributes</a>, by all objects implementing the [[#lp2p-connection|LP2PConnection]] interface:
522+
The following are the <a>event handlers</a> (and their corresponding <a>event handler event types</a>) that must be supported, as <a>event handler IDL attributes</a>, by all objects implementing the [[#lp2p-data-channel|LP2PDataChannel]] interface:
527523

528524
<table class="data">
529525
<thead>
@@ -555,7 +551,7 @@ The following are the <a>event handlers</a> (and their corresponding <a>event ha
555551
</tr>
556552
</table>
557553

558-
LP2PConnection Interface Extensions {#lp2p-data-channel-extensions}
554+
LP2PConnection Interface Extensions {#lp2p-connection-data-channel-extensions}
559555
-------------------------------------------------------------------
560556

561557
<pre class="idl">
@@ -584,7 +580,7 @@ dictionary LP2PDataChannelEventInit : EventInit {
584580
};
585581
</pre>
586582

587-
Extensions Events {#lp2p-data-channel-extensions-events}
583+
Extensions Events {#lp2p-connection-data-channel-extensions-events}
588584
------------------------------
589585

590586
The following event is [=fire an event|fired=] at the {{LP2PConnection}} object:
@@ -606,7 +602,7 @@ The following event is [=fire an event|fired=] at the {{LP2PConnection}} object:
606602
</tbody>
607603
</table>
608604

609-
Extensions Event handlers {#lp2p-data-channel-extensions-event-handlers}
605+
Extensions Event handlers {#lp2p-connection-data-channel-extensions-event-handlers}
610606
------------------------------------------------------------------------
611607

612608
The following are the <a>event handlers</a> (and their corresponding <a>event handler event types</a>) that must be supported, as <a>event handler IDL attributes</a>, by all objects implementing the {{LP2PConnection}} interface:
@@ -626,6 +622,57 @@ The following are the <a>event handlers</a> (and their corresponding <a>event ha
626622
</tbody>
627623
</table>
628624

625+
Examples {#data-channel-communication-examples}
626+
---------------------------------------------------
627+
628+
Example: Receive a {{LP2PDataChannel}} on an existing connection as receiver:
629+
630+
<pre class='example' highlight='js'>
631+
const receiver = new LP2PReceiver({
632+
nickname: "example-receiver",
633+
});
634+
635+
receiver.onconnection = e => {
636+
const conn = e.connection;
637+
console.log("Receiver: Got a connection!");
638+
639+
conn.ondatachannel = e => {
640+
const channel = e.channel;
641+
642+
channel.onmessage = e => {
643+
const message = e.data;
644+
console.log(\`Receiver: Received message: ${message}\`);
645+
};
646+
647+
channel.send("Good day to you, requester!");
648+
};
649+
};
650+
651+
await receiver.start();
652+
</pre>
653+
654+
Example: Create a {{LP2PDataChannel}} on an existing connection as requester:
655+
656+
<pre class='example' highlight='js'>
657+
const request = new LP2PRequest({
658+
nickname: "example-request",
659+
});
660+
661+
const conn = await request.start();
662+
console.log("Requester: Got a connection!");
663+
664+
const channel = conn.createDataChannel("My Channel");
665+
666+
channel.onopen = e => {
667+
channel.onmessage = e => {
668+
const message = e.data;
669+
console.log(\`Requester: Received message: ${message}\`);
670+
};
671+
672+
channel.send("Good day to you, receiver!");
673+
};
674+
</pre>
675+
629676
</section>
630677

631678
<section algorithm="LP2PQuicTransport">
@@ -659,6 +706,23 @@ partial interface LP2PReceiver {
659706
};
660707
</pre>
661708

709+
LP2PQuicTransportEvent {#lp2p-quic-transport-event}
710+
------------------------------------------------
711+
712+
Issue: In general, when defining a new interface that inherits from Event please always ask feedback from the WHATWG or the W3C WebApps WG community. See [defining event interfaces](https://dom.spec.whatwg.org/#defining-event-interfaces).
713+
714+
<pre class="idl">
715+
[Exposed=(Window,Worker), SecureContext]
716+
interface LP2PQuicTransportEvent : Event {
717+
constructor(DOMString type, LP2PQuicTransportEventInit QuicTransportEventInitDict);
718+
readonly attribute LP2PQuicTransport transport;
719+
};
720+
721+
dictionary LP2PQuicTransportEventInit : EventInit {
722+
required LP2PQuicTransport transport;
723+
};
724+
</pre>
725+
662726
Extensions Events {#lp2p-quic-transport-events}
663727
------------------------------
664728

@@ -701,23 +765,6 @@ The following are the <a>event handlers</a> (and their corresponding <a>event ha
701765
</tbody>
702766
</table>
703767

704-
LP2PQuicTransportEvent {#lp2p-quic-transport-event}
705-
------------------------------------------------
706-
707-
Issue: In general, when defining a new interface that inherits from Event please always ask feedback from the WHATWG or the W3C WebApps WG community. See [defining event interfaces](https://dom.spec.whatwg.org/#defining-event-interfaces).
708-
709-
<pre class="idl">
710-
[Exposed=(Window,Worker), SecureContext]
711-
interface LP2PQuicTransportEvent : Event {
712-
constructor(DOMString type, LP2PQuicTransportEventInit QuicTransportEventInitDict);
713-
readonly attribute LP2PQuicTransport transport;
714-
};
715-
716-
dictionary LP2PQuicTransportEventInit : EventInit {
717-
required LP2PQuicTransport transport;
718-
};
719-
</pre>
720-
721768
Examples {#lp2p-quic-transport-examples}
722769
----------------------------------------
723770

@@ -741,7 +788,7 @@ const receiver = new LP2PReceiver({
741788
nickname: "example-receiver",
742789
});
743790

744-
receiver.ontransport = e => {
791+
receiver.ontransport = async e => {
745792
const transport = e.transport;
746793

747794
// Blocks until transport is ready.
@@ -756,88 +803,6 @@ Refer to the [WebTransport examples](https://www.w3.org/TR/webtransport/#example
756803

757804
</section>
758805

759-
Examples {#examples}
760-
====================
761-
762-
Data Channel Communication {#examples-data-channel}
763-
---------------------------------------------------
764-
765-
<pre class='example' highlight='js'>
766-
// Peer A
767-
const receiver = new LP2PReceiver({
768-
nickname: "Peer A",
769-
});
770-
771-
receiver.onconnection = e => {
772-
const conn = e.connection;
773-
console.log("Receiver: Got a connection!");
774-
775-
conn.ondatachannel = e => {
776-
const channel = e.channel;
777-
778-
channel.onmessage = e => {
779-
const message = e.data;
780-
console.log(\`Receiver: Received message: ${message}\`);
781-
};
782-
783-
channel.send("Good day to you, requester!");
784-
};
785-
};
786-
787-
await receiver.start();
788-
789-
// Peer B
790-
const request = new LP2PRequest({
791-
nickname: "Peer B",
792-
});
793-
794-
const conn = await request.start();
795-
console.log("Requester: Got a connection!");
796-
797-
const channel = conn.createDataChannel("My Channel");
798-
799-
channel.onopen = e => {
800-
channel.onmessage = e => {
801-
const message = e.data;
802-
console.log(\`Requester: Received message: ${message}\`);
803-
};
804-
805-
channel.send("Good day to you, receiver!");
806-
};
807-
</pre>
808-
809-
WebTransport Communication {#examples-web-transport}
810-
---------------------------------------------------
811-
812-
<pre class='example' highlight='js'>
813-
// Peer A
814-
const receiver = new LP2PReceiver({
815-
nickname: "Peer A",
816-
});
817-
818-
receiver.ontransport = e => {
819-
const transport = e.transport;
820-
821-
// Blocks until transport is ready.
822-
await transport.ready;
823-
}
824-
825-
// Blocks until permission is received.
826-
await receiver.start();
827-
828-
// Peer B
829-
const request = new LP2PRequest({
830-
nickname: "Peer B",
831-
});
832-
833-
const transport = new LP2PQuicTransport(request);
834-
835-
// Blocks until transport is ready.
836-
await transport.ready;
837-
</pre>
838-
839-
Refer to the [WebTransport examples](https://www.w3.org/TR/webtransport/#examples) for usage of a [[!webtransport]] object.
840-
841806
Appendix A: OSP Extension Messages {#appendix-a}
842807
================================================
843808

0 commit comments

Comments
 (0)