An interface representing some way to connect to other peers

Remarks

The Repo uses one or more NetworkAdapters to connect to other peers. Because the network may take some time to be ready the Repo will wait until the adapter emits a ready event before it starts trying to use it

The NetworkAdapter is an abstract class that can be used as a base to build a custom network adapter. It is most useful as a simple way to add the necessary event emitter functionality

interface NetworkAdapterInterface {
    peerId?: PeerId;
    peerMetadata?: PeerMetadata;
    addListener<T>(event, fn, context?): this;
    connect(peerId, peerMetadata?): void;
    disconnect(): void;
    emit<T>(event, ...args): boolean;
    eventNames(): (keyof NetworkAdapterEvents)[];
    listenerCount(event): number;
    listeners<T>(event): ((...args) => void)[];
    off<T>(event, fn?, context?, once?): this;
    on<T>(event, fn, context?): this;
    once<T>(event, fn, context?): this;
    removeAllListeners(event?): this;
    removeListener<T>(event, fn?, context?, once?): this;
    send(message): void;
}

Hierarchy

Implemented by

Properties

peerId?: PeerId
peerMetadata?: PeerMetadata

Methods

  • Type Parameters

    Parameters

    Returns this

  • Return an array listing the events for which the emitter has registered listeners.

    Returns (keyof NetworkAdapterEvents)[]

  • Return the number of listeners listening to a given event.

    Parameters

    Returns number

  • Return the listeners registered for a given event.

    Type Parameters

    Parameters

    • event: T

    Returns ((...args) => void)[]

  • Type Parameters

    Parameters

    Returns this

  • Add a listener for a given event.

    Type Parameters

    Parameters

    Returns this

  • Add a one-time listener for a given event.

    Type Parameters

    Parameters

    Returns this

  • Remove all listeners, or those of the specified event.

    Parameters

    • Optional event: keyof NetworkAdapterEvents

    Returns this

  • Remove the listeners of a given event.

    Type Parameters

    Parameters

    Returns this

Generated using TypeDoc