libp2p-pubsub
Version:
67 lines • 1.92 kB
TypeScript
/// <reference types="node" />
import { EventEmitter } from 'events';
import pushable from 'it-pushable';
import type { PeerId } from 'libp2p-interfaces/peer-id';
import type { MuxedStream } from 'libp2p-interfaces/stream-muxer';
export interface Options {
id: PeerId;
protocol: string;
}
/**
* Thin wrapper around a peer's inbound / outbound pubsub streams
*/
export declare class PeerStreams extends EventEmitter {
readonly id: PeerId;
readonly protocol: string;
/**
* Write stream - it's preferable to use the write method
*/
outboundStream: pushable.Pushable<Uint8Array> | undefined;
/**
* Read stream
*/
inboundStream: AsyncIterable<Uint8Array> | undefined;
/**
* The raw outbound stream, as retrieved from conn.newStream
*/
private _rawOutboundStream;
/**
* The raw inbound stream, as retrieved from the callback from libp2p.handle
*/
private _rawInboundStream;
/**
* An AbortController for controlled shutdown of the inbound stream
*/
private readonly _inboundAbortController;
constructor(opts: Options);
/**
* Do we have a connection to read from?
*
* @type {boolean}
*/
get isReadable(): boolean;
/**
* Do we have a connection to write on?
*
* @type {boolean}
*/
get isWritable(): boolean;
/**
* Send a message to this peer.
* Throws if there is no `stream` to write to available.
*/
write(data: Uint8Array): void;
/**
* Attach a raw inbound stream and setup a read stream
*/
attachInboundStream(stream: MuxedStream): AsyncIterable<Uint8Array>;
/**
* Attach a raw outbound stream and setup a write stream
*/
attachOutboundStream(stream: MuxedStream): Promise<void>;
/**
* Closes the open connection to peer
*/
close(): void;
}
//# sourceMappingURL=peer-streams.d.ts.map