WebRTCPeerConnection¶
Inherited By: WebRTCPeerConnectionGDNative
Interfaz a una conexión de pares WebRTC.
Descripción¶
Una conexión WebRTC entre la computadora local y un par remoto. Proporciona una interfaz para conectar, mantener y monitorear la conexión.
Establecer una conexión WebRTC entre dos pares de ahora en adelante) puede no parecer una tarea trivial, pero puede ser dividida en 3 pasos principales:
El par que quiere iniciar la conexión (
A
de ahora en adelante) crea una oferta y la envía al otro par (B
de ahora en adelante).B
recibe la oferta, la genera y la responde, y la envía aA
).A
yB
luego generan e intercambian candidatos ICE entre sí.
Después de estos pasos, la conexión debe conectarse. Sigue leyendo o mira el tutorial para más información.
Métodos¶
add_ice_candidate ( String media, int index, String name ) |
|
void |
close ( ) |
create_data_channel ( String label, Dictionary options={ } ) |
|
create_offer ( ) |
|
get_connection_state ( ) const |
|
initialize ( Dictionary configuration={ } ) |
|
poll ( ) |
|
set_local_description ( String type, String sdp ) |
|
set_remote_description ( String type, String sdp ) |
Señales¶
data_channel_received ( Object channel )
Emitido cuando se recibe un nuevo canal en banda, es decir, cuando el canal fue creado con negotiated: false
(por defecto).
El objeto será una instancia de WebRTCDataChannel. Debe mantener una referencia de él o se cerrará automáticamente. Ver create_data_channel.
Emitido cuando se ha creado un nuevo candidato de la ICE. Los tres parámetros deben ser pasados al par remoto a través del servidor de señales.
Emitido después de una llamada exitosa a create_offer o set_remote_description (cuando genera una respuesta). Los parámetros deben ser pasados a set_local_description en este objeto, y enviados al par remoto a través del servidor de señales.
Enumeraciones¶
enum ConnectionState:
STATE_NEW = 0 --- La conexión es nueva, se pueden crear canales de datos y una oferta en este estado.
STATE_CONNECTING = 1 --- El par está conectando, el ICE está en marcha, ninguno de los transportes ha fallado.
STATE_CONNECTED = 2 --- El par está conectado, todos los transportes de ICE están conectados.
STATE_DISCONNECTED = 3 --- Al menos un transporte ICE está desconectado.
STATE_FAILED = 4 --- Uno o más de los transportes ICE fallaron.
STATE_CLOSED = 5 --- La conexión entre pares se cierra (después de llamar a close por ejemplo).
Descripciones de Métodos¶
Añade un candidato de hielo generado por un par remoto (y recibido a través del servidor de señales). Ver ice_candidate_created.
void close ( )
Close the peer connection and all data channels associated with it.
Note: You cannot reuse this object for a new connection unless you call initialize.
WebRTCDataChannel create_data_channel ( String label, Dictionary options={ } )
Returns a new WebRTCDataChannel (or null
on failure) with given label
and optionally configured via the options
dictionary. This method can only be called when the connection is in state STATE_NEW.
There are two ways to create a working data channel: either call create_data_channel on only one of the peer and listen to data_channel_received on the other, or call create_data_channel on both peers, with the same values, and the negotiated
option set to true
.
Valid options
are:
{
"negotiated": true, # When set to true (default off), means the channel is negotiated out of band. "id" must be set too. "data_channel_received" will not be called.
"id": 1, # When "negotiated" is true this value must also be set to the same value on both peer.
# Only one of maxRetransmits and maxPacketLifeTime can be specified, not both. They make the channel unreliable (but also better at real time).
"maxRetransmits": 1, # Specify the maximum number of attempt the peer will make to retransmits packets if they are not acknowledged.
"maxPacketLifeTime": 100, # Specify the maximum amount of time before giving up retransmitions of unacknowledged packets (in milliseconds).
"ordered": true, # When in unreliable mode (i.e. either "maxRetransmits" or "maxPacketLifetime" is set), "ordered" (true by default) specify if packet ordering is to be enforced.
"protocol": "my-custom-protocol", # A custom sub-protocol string for this channel.
}
Note: You must keep a reference to channels created this way, or it will be closed.
Error create_offer ( )
Crea una nueva oferta SDP para iniciar una conexión WebRTC con un par remoto. Al menos una WebRTCDataChannel debe haber sido creada antes de llamar a este método.
Si esta función devuelve @GlobalScope.OK, se llamará a session_description_created cuando la sesión esté lista para ser enviada.
ConnectionState get_connection_state ( ) const
Devuelve el estado de conexión. Ver ConnectionState.
Error initialize ( Dictionary configuration={ } )
Re-initialize this peer connection, closing any previously active connection, and going back to state STATE_NEW. A dictionary of options
can be passed to configure the peer connection.
Valid options
are:
{
"iceServers": [
{
"urls": [ "stun:stun.example.com:3478" ], # One or more STUN servers.
},
{
"urls": [ "turn:turn.example.com:3478" ], # One or more TURN servers.
"username": "a_username", # Optional username for the TURN server.
"credential": "a_password", # Optional password for the TURN server.
}
]
}
Error poll ( )
Llama a este método con frecuencia (por ejemplo, en Node._process o Node._physics_process) para recibir correctamente las señales.
Establece la descripción del SDP del par local. Esto debe ser llamado en respuesta a session_description_created.
Después de llamar a esta función el par empezará a emitir ice_candidate_created (a menos que se devuelva un Error diferente de @GlobalScope.OK).
Establece la descripción SDP del par remoto. Esto debe ser llamado con los valores generados por un par remoto y recibidos por el servidor de señales.
Si type
es offer
el par emitirá session_description_created con la respuesta apropiada.
Si type
es answer
el par empezará a emitir ice_candidate_created.