-
Notifications
You must be signed in to change notification settings - Fork 443
/
index.ts
63 lines (54 loc) · 1.61 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import type { Direction, Stream } from '../connection/index.js'
import type { AbortOptions } from '../index.js'
import type { Duplex } from 'it-stream-types'
import type { Uint8ArrayList } from 'uint8arraylist'
export interface StreamMuxerFactory {
/**
* The protocol used to select this muxer during connection opening
*/
protocol: string
/**
* Creates a new stream muxer to be used with a new connection
*/
createStreamMuxer(init?: StreamMuxerInit): StreamMuxer
}
/**
* A libp2p stream muxer
*/
export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
/**
* The protocol used to select this muxer during connection opening
*/
protocol: string
/**
* A list of streams that are currently open. Closed streams will not be returned.
*/
readonly streams: Stream[]
/**
* 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 | Promise<Stream>
/**
* Close or abort all tracked streams and stop the muxer
*/
close(options?: AbortOptions): Promise<void>
/**
* Close or abort all tracked streams and stop the muxer
*/
abort(err: Error): void
}
export interface StreamMuxerInit {
/**
* A callback function invoked every time an incoming stream is opened
*/
onIncomingStream?(stream: Stream): void
/**
* A callback function invoke every time a stream ends
*/
onStreamEnd?(stream: Stream): void
/**
* Outbound stream muxers are opened by the local node, inbound stream muxers are opened by the remote
*/
direction?: Direction
}