Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat: Interface changes to enable WebTransport #292

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/interface-stream-muxer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface StreamMuxer extends Duplex<Uint8Array> {
* Initiate a new stream with the given name. If no name is
* provided, the id of the stream will be used.
*/
newStream: (name?: string) => Stream
newStream: (name?: string) => Stream | Promise<Stream>

/**
* Close or abort all tracked streams and stop the muxer
Expand Down
10 changes: 9 additions & 1 deletion packages/interface-transport/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AbortOptions } from '@libp2p/interfaces'
import type { EventEmitter } from '@libp2p/interfaces/events'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection'
import type { Duplex } from 'it-stream-types'

Expand Down Expand Up @@ -78,11 +79,18 @@ export interface UpgraderEvents {
'connectionEnd': CustomEvent<Connection>
}

export interface UpgradeOptions {
// Enable only if your transporter natively supports encryption and you've authenticated the remote peer manually
skipEncryption?: boolean
// Use a custom muxerfactory to upgrade the connection
withStreamMuxer?: StreamMuxerFactory
}

export interface Upgrader extends EventEmitter<UpgraderEvents> {
/**
* Upgrades an outbound connection on `transport.dial`.
*/
upgradeOutbound: (maConn: MultiaddrConnection) => Promise<Connection>
upgradeOutbound: (maConn: MultiaddrConnection, opts?: UpgradeOptions) => Promise<Connection>

/**
* Upgrades an inbound connection on transport listener.
Expand Down