WebRTCPeerConnection
Interface to a WebRTC peer connection.
WebRTCPeerConnection.swift:29class WebRTCPeerConnection
A WebRTC connection between the local computer and a remote peer. Provides an interface to connect, maintain and monitor the connection.
Setting up a WebRTC connection between two peers may not seem a trivial task, but it can be broken down into 3 main steps:
The peer that wants to initiate the connection (
A
from now on) creates an offer and send it to the other peer (B
from now on).B
receives the offer, generate and answer, and sends it toA
).A
andB
then generates and exchange ICE candidates with each other.
After these steps, the connection should become connected. Keep on reading or look into the tutorial for more information.
This object emits the following signals:
Superclasses
class RefCounted
Base class for reference-counted objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Types
enum ConnectionState
enum GatheringState
class Signal1
Signal support.
class Signal2
Signal support.
class Signal3
Signal support.
enum SignalingState
Type members
static func setDefaultExtension(extensionClass: StringName
) Sets the
extensionClass
as the defaultWebRTCPeerConnectionExtension
returned when creating a newWebRTCPeerConnection
.class var godotClassName: StringName
Instance members
var dataChannelReceived: Signal3
Emitted when a new in-band channel is received, i.e. when the channel was created with
negotiated: false
(default).var iceCandidateCreated: Signal2
Emitted when a new ICE candidate has been created. The three parameters are meant to be passed to the remote peer over the signaling server.
var sessionDescriptionCreated: Signal1
Emitted after a successful call to
createOffer
orsetRemoteDescription(type:sdp:)
(when it generates an answer). The parameters are meant to be passed tosetLocalDescription(type:sdp:)
on this object, and sent to the remote peer over the signaling server.func addIceCandidate(media: String, index: Int32, name: String
) -> GodotError Add an ice candidate generated by a remote peer (and received over the signaling server). See [signal ice_candidate_created].
func close(
) Close the peer connection and all data channels associated with it.
func createDataChannel(label: String, options: GDictionary
) -> WebRTCDataChannel? Returns a new
WebRTCDataChannel
(ornull
on failure) with givenlabel
and optionally configured via theoptions
dictionary. This method can only be called when the connection is in state .stateNew.func createOffer(
) -> GodotError Creates a new SDP offer to start a WebRTC connection with a remote peer. At least one
WebRTCDataChannel
must have been created before calling this method.func getConnectionState(
) -> WebRTCPeerConnection.ConnectionState Returns the connection state. See
ConnectionState
.func getGatheringState(
) -> WebRTCPeerConnection.GatheringState Returns the ICE
GatheringState
of the connection. This lets you detect, for example, when collection of ICE candidates has finished.func getSignalingState(
) -> WebRTCPeerConnection.SignalingState Returns the
SignalingState
on the local end of the connection while connecting or reconnecting to another peer.func initialize(configuration: GDictionary
) -> GodotError Re-initialize this peer connection, closing any previously active connection, and going back to state .stateNew. A dictionary of
configuration
options can be passed to configure the peer connection.func poll(
) -> GodotError Call this method frequently (e.g. in
_process(delta:)
or_physicsProcess(delta:)
) to properly receive signals.func setLocalDescription(type: String, sdp: String
) -> GodotError Sets the SDP description of the local peer. This should be called in response to [signal session_description_created].
func setRemoteDescription(type: String, sdp: String
) -> GodotError Sets the SDP description of the remote peer. This should be called with the values generated by a remote peer and received over the signaling server.