Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce shorthand API #35

Open
backkem opened this issue Jan 9, 2024 · 5 comments
Open

Introduce shorthand API #35

backkem opened this issue Jan 9, 2024 · 5 comments

Comments

@backkem
Copy link
Collaborator

backkem commented Jan 9, 2024

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

@backkem
Copy link
Collaborator Author

backkem commented Jan 26, 2024

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 DataChannel vs WebTransport #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
Copy link

getify commented Jan 26, 2024

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
Copy link

getify commented Jan 26, 2024

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
Copy link
Member

anssiko commented Jan 26, 2024

@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
Copy link

getify commented Jan 26, 2024

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 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants