WICG / local-peer-to-peer

↔️ Proposal for local communication between browsers without the aid of a server.
https://wicg.github.io/local-peer-to-peer/
Other
62 stars 6 forks source link

Introduce shorthand API #35

Open backkem opened 5 months ago

backkem commented 5 months ago

Introduce a shorthand API for the most common case. This was previously discussed in #33.

backkem commented 5 months ago

To design shorthand APIs, I think we'll need to answer the following questions:

  1. Do we want shorthand's for both the DataChannel and WebTransport API or do we pick a 'favorite'? Related to #29.
    • If we want to support both: How to distinguish in the API. Add a lp2p.datachannel.connect( /* ... */ ) prefix or a function postfix such as lp2p.connectDataChannel( /* ... */ ). Either way it makes a shorthand less 'short'.
  2. Can we safely make this assumption for the shorthand: the advertising side will also listen for a transport (DataChannel or WebTransport) & the requesting side will initiate a transport.
  3. Is there appetite for a shorthand that advertises + listens and returns the first transport and stops advertising?
  4. Is there appetite for some "simultaneous open" type shorthand where the API is symmetric (both sides advertise and figure out how to connect).

I find this somewhat hard to decide on. Partially because I would likely prefer to use the lower-level APIs directly.

getify commented 5 months ago

do we pick a 'favorite'?

I don't think that's a good idea. I think we should have equal support (either both shorthand or neither).

getify commented 5 months ago

Is there appetite for a shorthand that advertises + listens and returns the first transport and stops advertising?

Rather than being a separate method shorthand, this feels more like a config option.

anssiko commented 5 months ago

@getify thanks for chiming in. Given feels, it sounds like you have built intuition on how this could be solved, can we pick your brain on this? Feel free to drop further pointers and brain dumps here so we can iterate on this issue together. Thanks!

getify commented 5 months ago

I need to dig further into the API to give more of a authoritative suggestion, by my feel leans this way:

lp2p.connect( /* ... */, { transport: lp2p.DATA_CHANNEL } )

What feels better about this option, even if it's "longer", is that config objects don't have to be specified inline at the call-site, whereas method names (or object property traversals) are sort of tied to the call-site (and thus kind of defeat the benefits of shorthand in the first place).

Alternately:

lp2p.connect( /* ... */, lp2p.DATA_CHANNEL )