peerix - v0.1.0
    Preparing search index...

    Class RemotePeer

    Represents a remote peer connection. Do not create RemotePeer instances manually.

    Index

    Properties

    channels: Map<string, RTCDataChannel>

    Negotiated data channels keyed by channel label.

    connection: RTCPeerConnection

    Native WebRTC peer connection to the remote peer.

    id: string

    Remote peer identifier.

    metadata?: any

    Metadata advertised by the remote peer.

    room: string

    Room name the peer is associated with.

    Peer connection state, updated on connection state changes.

    streams: Map<string, MediaStream>

    Remote media streams keyed by stream label.

    Methods

    • Closes a previously opened data channel to the current remote peer.

      Parameters

      • options: string | { label: string }

        Channel label or object containing label.

      Returns Promise<void>

    • Closes and frees all connection resources.

      Returns void

    • Unregisters an event handler for a specific event type emitted by the remote peer connection.

      Type Parameters

      Parameters

      • event: K | K[]

        Event type to stop listening for.

      • handler: (...args: RemotePeerEvents[K]) => void

        Callback function to remove from the event listeners.

      Returns void

    • Opens a data channel to the current remote peer.

      If a channel with the same label already exists, it will be reused.

      You can open a channel with the same label on both local and remote peers or only on one side. In any case, only one channel will be created for each label. You can send data through the channel in both directions.

      Parameters

      Returns Promise<void>

    • Publishes new or updates an existing media stream to the current remote peer.

      If you pass a MediaStream instance directly, it will be published under a label equal to the stream id. Otherwise, you can specify an explicit label in the options object. If a stream with the same label already exists, it will be updated and its tracks will be added/removed as needed to minimize renegotiations.

      If the stream is published with the managed option, its tracks will be automatically stopped when the stream is unpublished or replaced with a new stream.

      Parameters

      • options: MediaStream | StreamOptions

        Stream descriptor or MediaStream instance.

      Returns Promise<void | MediaStream>

      The published MediaStream instance if successful, or undefined.

    • Sends a message through data channels.

      If options is omitted, the message is sent to all open channels for every connected remote peer. If options is a string, it is treated as channel label.

      Parameters

      • message: any

        Message payload to send. This may be a string, a Blob, an ArrayBuffer, a TypedArray or a DataView object.

      • Optionaloptions: string | { label?: string }

        Optional channel label or object containing label.

      Returns void

    • Stops publishing a previously published media stream to the current remote peer.

      If you pass a MediaStream instance directly, it will be unpublished based on its id as label. Otherwise, you can specify the label in the options object or pass it directly as a string.

      If the stream was published with the managed option, its tracks will be stopped automatically.

      Parameters

      • options: string | MediaStream | { label?: string }

        A stream label, MediaStream instance, or an object containing a label.

      Returns Promise<void | MediaStream>

      The unpublished MediaStream instance, or undefined.