@sovereignbase/peer2peer
    Preparing search index...

    Class P2PConnection<T>

    Provides a thin, browser-oriented wrapper around a WebRTC peer connection and its application data channel.

    Type Parameters

    • T extends Record<string, unknown>

      The structured payload type sent through sendMessage() and received via the "message" event.

    Index

    Constructors

    • Creates a live connection instance from one side of a previously exchanged contract.

      Type Parameters

      • T extends Record<string, unknown>

        The structured payload type sent through sendMessage() and received via the "message" event.

      Parameters

      • contract: Contract

        The contract copy for the local role.

      Returns P2PConnection<T>

      Throws UNKNOWN_PEER_CONTRACT when the provided contract does not match a reserved pending or accepted offer.

    Properties

    remoteCameraVideoElement: HTMLVideoElement | undefined

    References the latest remote camera element created for this connection.

    remoteScreenVideoElement: HTMLVideoElement | undefined

    References the latest remote screen-share element created for this connection.

    localCameraVideoElement: HTMLVideoElement | undefined

    Stores the shared local camera preview element, when camera sharing has been enabled.

    localScreenVideoElement: HTMLVideoElement | undefined

    Stores the shared local screen preview element, when screen sharing has been enabled.

    Methods

    • Resolves once the underlying data channel is fully open.

      Returns Promise<void>

      Throws CHANNEL_CLOSED, CHANNEL_ERROR, or CHANNEL_NOT_AVAILABLE if the connection fails before the channel opens.

    • Sends an application payload over the open data channel.

      Parameters

      • message: T

        The structured payload to encode and transmit.

      Returns void

      Throws CONNECTION_NOT_READY when the data channel has not reached the "open" state.

    • Starts sending the shared local camera track and populates the shared local preview element.

      Returns Promise<void>

    • Starts sending the shared local microphone track to the remote peer.

      The first call lazily creates and caches the shared user-media stream.

      Returns Promise<void>

    • Starts sending the shared local display stream and populates the shared local preview element.

      Returns Promise<void>

    • Stops sending the local microphone track, if one is currently attached.

      Returns void

    • Accepts a remote offer and returns the paired contract copies needed by the two peers to finalize the connection locally.

      Parameters

      • offer: Offer

        The remote offer to accept.

      • additionalIceServers: RTCIceServer[] = []

        Optional additional ICE servers appended after the built-in public STUN configuration.

      Returns Promise<ContractCopies>

      The contract copies for the offeror and offeree.

      Throws MISSING_LOCAL_DESCRIPTION when the browser does not expose the generated answer description.

    • Creates a new offer and reserves the local offeror-side connection state until the returned offer is later consumed by the constructor.

      Parameters

      • additionalIceServers: RTCIceServer[] = []

        Optional additional ICE servers appended after the built-in public STUN configuration.

      Returns Promise<Offer>

      An offer that can be transported to the remote peer out-of-band.

      Throws MISSING_LOCAL_DESCRIPTION when the browser does not expose the generated offer description.