Skip to content

API reference / @jsprismarine/native-network / PeerConnection

Class: PeerConnection ​

Defined in: packages/native-network/src/PeerConnection.ts:168

A peer connection in the native library.

Events: description ({ type, sdp }), candidate (LocalCandidate), gatheringstatechange, connectionstatechange, iceconnectionstatechange, datachannel (DataChannel). libdatachannel negotiates by itself: a remote offer produces the answer, and the first data channel on a new connection produces the offer.

Extends ​

  • EventEmitter

Constructors ​

Constructor ​

new PeerConnection(network, options?): PeerConnection

Defined in: packages/native-network/src/PeerConnection.ts:185

Parameters ​

network ​

NativeNetwork

The loaded library.

options? ​

PeerConnectionOptions = {}

Binding and ports.

Returns ​

PeerConnection

Throws ​

When libdatachannel refuses the configuration.

Overrides ​

EventEmitter.constructor

Properties ​

connectionState ​

connectionState: PeerConnectionState = 'new'

Defined in: packages/native-network/src/PeerConnection.ts:169


iceConnectionState ​

iceConnectionState: IceConnectionState = 'new'

Defined in: packages/native-network/src/PeerConnection.ts:171


iceGatheringState ​

iceGatheringState: GatheringState = 'new'

Defined in: packages/native-network/src/PeerConnection.ts:170


id ​

readonly id: number

Defined in: packages/native-network/src/PeerConnection.ts:175


localDescription ​

localDescription: { sdp: string; type: "offer" | "answer"; } | undefined

Defined in: packages/native-network/src/PeerConnection.ts:173

The last local description libdatachannel made.

Methods ​

addRemoteCandidate() ​

addRemoteCandidate(candidate, sdpMid?): void

Defined in: packages/native-network/src/PeerConnection.ts:226

Adds a remote candidate.

Parameters ​

candidate ​

string

The candidate line, with or without a=.

sdpMid? ​

string = '0'

Its media id; 0 when absent, as a NetherNet offer has one section.

Returns ​

void


close() ​

close(): void

Defined in: packages/native-network/src/PeerConnection.ts:291

Closes the connection and its channels. libdatachannel shuts SCTP down gracefully, so what was sent before still arrives; the native objects are freed once it reports closed, and deleting them sooner would cut that shutdown short.

Returns ​

void


createDataChannel() ​

createDataChannel(label, options?): DataChannel

Defined in: packages/native-network/src/PeerConnection.ts:243

Creates a data channel; on a new connection, that makes libdatachannel produce the offer.

Parameters ​

label ​

string

The channel's label.

options? ​

DataChannelOptions = {}

Ordering and retransmissions.

Returns ​

DataChannel

The channel.


currentLocalSdp() ​

currentLocalSdp(): string | undefined

Defined in: packages/native-network/src/PeerConnection.ts:263

The current local description as libdatachannel holds it, with every candidate gathered so far; read it after gatheringstatechange reaches complete to send one with all of them.

Returns ​

string | undefined

The SDP, or undefined before there is one.


selectedCandidatePair() ​

selectedCandidatePair(): SelectedCandidatePair | undefined

Defined in: packages/native-network/src/PeerConnection.ts:278

The candidate pair ICE selected, once connected.

Returns ​

SelectedCandidatePair | undefined


setRemoteDescription() ​

setRemoteDescription(description): void

Defined in: packages/native-network/src/PeerConnection.ts:210

Applies the remote side's description. An offer makes libdatachannel answer.

Parameters ​

description ​

The description and its type.

sdp ​

string

type ​

"offer" | "answer"

Returns ​

void