js-libp2p-interfaces/dist/src/pubsub/peer-streams.d.ts
2020-12-10 12:33:44 +01:00

112 lines
3.0 KiB
TypeScript

/// <reference types="node" />
export = PeerStreams;
declare const PeerStreams_base: typeof import("events").EventEmitter;
/**
* @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream
* @typedef {import('peer-id')} PeerId
* @typedef {import('it-pushable').Pushable<Uint8Array>} PushableStream
*/
/**
* Thin wrapper around a peer's inbound / outbound pubsub streams
*/
declare class PeerStreams extends PeerStreams_base {
/**
* @param {object} properties - properties of the PeerStreams.
* @param {PeerId} properties.id
* @param {string} properties.protocol
*/
constructor({ id, protocol }: {
id: PeerId;
protocol: string;
});
/**
* @type {import('peer-id')}
*/
id: import('peer-id');
/**
* Established protocol
*
* @type {string}
*/
protocol: string;
/**
* The raw outbound stream, as retrieved from conn.newStream
*
* @private
* @type {null|MuxedStream}
*/
private _rawOutboundStream;
/**
* The raw inbound stream, as retrieved from the callback from libp2p.handle
*
* @private
* @type {null|MuxedStream}
*/
private _rawInboundStream;
/**
* An AbortController for controlled shutdown of the inbound stream
*
* @private
* @type {AbortController}
*/
private _inboundAbortController;
/**
* Write stream -- its preferable to use the write method
*
* @type {null|PushableStream}
*/
outboundStream: null | import("it-pushable").Pushable<Uint8Array>;
/**
* Read stream
*
* @type {null| AsyncIterable<Uint8Array>}
*/
inboundStream: null | AsyncIterable<Uint8Array>;
/**
* 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.
*
* @param {Uint8Array} data
* @returns {void}
*/
write(data: Uint8Array): void;
/**
* Attach a raw inbound stream and setup a read stream
*
* @param {MuxedStream} stream
* @returns {AsyncIterable<Uint8Array>}
*/
attachInboundStream(stream: MuxedStream): AsyncIterable<Uint8Array>;
/**
* Attach a raw outbound stream and setup a write stream
*
* @param {MuxedStream} stream
* @returns {Promise<void>}
*/
attachOutboundStream(stream: MuxedStream): Promise<void>;
/**
* Closes the open connection to peer
*
* @returns {void}
*/
close(): void;
}
declare namespace PeerStreams {
export { MuxedStream, PeerId, PushableStream };
}
type MuxedStream = import("../stream-muxer/types").MuxedStream;
type PeerId = import("peer-id");
type PushableStream = import("it-pushable").Pushable<Uint8Array>;
//# sourceMappingURL=peer-streams.d.ts.map