RTCForge API Reference v1.1.1
    Preparing search index...

    Interface DataChannelHub

    Abstraction over the peer connection layer that the file-transfer engine uses to open and receive RTCDataChannels.

    This is the integration seam between the file-transfer module and whatever manages the underlying RTCPeerConnections (for example an application's call/mesh layer). A FileTransferManager opens outbound channels through it and listens for inbound ones to drive the transfer protocol.

    Data channels carry two kinds of traffic: a single JSON control channel per peer (labelled CONTROL_CHANNEL_LABEL) and one or more binary chunk channels per transfer (labelled via dataChannelLabel). Implementations should surface every remotely-initiated channel through the data-channel event.

    interface DataChannelHub {
        createDataChannel(
            peerId: string,
            label: string,
            opts?: RTCDataChannelInit,
        ): RTCDataChannel | undefined;
        off(
            event: "data-channel",
            handler: (peerId: string, channel: RTCDataChannel) => void,
        ): void;
        on(
            event: "data-channel",
            handler: (peerId: string, channel: RTCDataChannel) => void,
        ): void;
    }
    Index

    Methods

    • Opens an outbound data channel to peerId.

      Parameters

      • peerId: string

        Identifier of the remote peer to open a channel to.

      • label: string

        Channel label; the transfer engine encodes routing information here.

      • Optionalopts: RTCDataChannelInit

        Optional RTCDataChannel configuration (the engine requests ordered: true).

      Returns RTCDataChannel | undefined

      The new channel, or undefined if there is no active connection to peerId.

    • Subscribes to remotely-initiated data channels.

      Parameters

      • event: "data-channel"

        Always 'data-channel'.

      • handler: (peerId: string, channel: RTCDataChannel) => void

        Invoked with the originating peer id and the newly opened channel.

      Returns void