RTCDataChannel
Experimental
Esta é uma tecnologia experimental
Verifique a tabela de compatibilidade entre Navegadores cuidadosamente antes de usar essa funcionalidade em produção.
A interface RTCDataChannel representa um canal de rede que pode ser usado para transferências bidirecionais de dados arbitrários de ponto a ponto. Todo canal de dados está associado a RTCPeerConnection
, e cada conexão de pares pode ter até um máximo teórico de 65,534 canais de dados (o limite real pode variar de navegador para navegador).
Para criar um canal de dados e pedir a um ponto remoto para se juntar a você, chame os metodos RTCPeerConnection
's createDataChannel()
. O interlocutor que está sendo convidado a trocar dados recebe um evento datachannel
(que possui o tipo RTCDataChannelEvent
) para informá-lo de que o canal de dados foi adicionado à conexão.
Propriedades
Also inherits propriedades from: EventTarget
binaryType
- The property
binaryType
on theRTCDataChannel
interface is aDOMString
which specifies the type of JavaScript object which should be used to represent binary data received on theRTCDataChannel
. Values allowed by theWebSocket.binaryType
property are also permitted here:"blob"
ifBlob
objects are being used or"arraybuffer"
ifArrayBuffer
objects are being used. The default is"blob"
. bufferedAmount
undefined- The read-only
RTCDataChannel
propertybufferedAmount
returns the number of bytes of data currently queued to be sent over the data channel. bufferedAmountLowThreshold
- The
RTCDataChannel
propertybufferedAmountLowThreshold
is used to specify the number of bytes of buffered outgoing data that is considered "low." The default value is 0. id
undefined- The read-only
RTCDataChannel
propertyid
returns an ID number (between 0 and 65,534) which uniquely identifies theRTCDataChannel
. label
undefined- The read-only
RTCDataChannel
propertylabel
returns aDOMString
containing a name describing the data channel. These labels are not required to be unique. maxPacketLifeTime
undefined- The read-only
RTCDataChannel
propertymaxPacketLifeTime
returns the amount of time, in milliseconds, the browser is allowed to take to attempt to transmit a message, as set when the data channel was created, ornull
. maxRetransmits
undefined- The read-only
RTCDataChannel
propertymaxRetransmits
returns the maximum number of times the browser should try to retransmit a message before giving up, as set when the data channel was created, ornull
, which indicates that there is no maximum. negotiated
undefined- The read-only
RTCDataChannel
propertynegotiated
indicates whether theRTCDataChannel
's connection was negotiated by the Web app (true
) or by the WebRTC layer (false
). ordered
undefined- The read-only
RTCDataChannel
propertyordered
indicates whether or not the data channel guarantees in-order delivery of messages; the default istrue
, which indicates that the data channel is indeed ordered. protocol
undefined- The read-only
RTCDataChannel
propertyprotocol
returns aDOMString
containing the name of the subprotocol in use. If no protocol was specified when the data channel was created, then this property's value is "" (the empty string). readyState
undefined- The read-only
RTCDataChannel
propertyreadyState
returns an enum of typeRTCDataChannelState
which indicates the state of the data channel's underlying data connection. undefinedreliable
- The read-only
RTCDataChannel
propertyreliable
indicates whether or not the data channel is reliable. undefinedstream
- The deprecated (and never part of the official specification)
read-only
RTCDataChannel
propertystream
returns an ID number (between 0 and 65,535) which uniquely identifies theRTCDataChannel
. onbufferedamountlow
- The
RTCDataChannel.onbufferedamountlow
property is anEventHandler
which specifies a function the browser calls when thebufferedamountlow
event is sent to theRTCDataChannel
. This event, which is represented by a simpleEvent
object, is sent when the amount of data buffered to be sent falls to or below the threshold specified by the channel'sRTCDataChannel.bufferedAmountLowThreshold
. onclose
- The
RTCDataChannel.onclose
property is anEventHandler
which specifies a function to be called by the browser when theclose
event is received by theRTCDataChannel
. This is a simpleEvent
which indicates that the data channel has closed down. onclosing
- The
RTCDataChannel.onclosing
property is anEventHandler
which specifies a function to be called by the browser when theclosing
event is received by theRTCDataChannel
. This is a simpleEvent
which indicates that the data channel is being closed, that is,RTCDataChannel
transitions to "closing" state. For example, afterRTCDataChannel.close
was called but the underlying data transport might not have been closed yet. onerror
- The
RTCDataChannel.onerror
property is anEventHandler
which specifies a function to be called when theerror
event is received. When an error occurs on the data channel, the function receives as input anErrorEvent
object describing the error which occurred. onmessage
- The
RTCDataChannel.onmessage
property stores anEventHandler
which specifies a function to be called when themessage
event is fired on the channel. This event is represented by theMessageEvent
interface. This event is sent to the channel when a message is received from the other peer. onopen
- The
RTCDataChannel.onopen
property is anEventHandler
which specifies a function to be called when theopen
event is fired; this is a simpleEvent
which is sent when the data channel's underlying data transport—the link over which theRTCDataChannel
's messages flow—is established or re-established. close()
- The
RTCDataChannel.close()
method closes theRTCDataChannel
. Either peer is permitted to call this method to initiate closure of the channel. send()
- The
send()
method of theRTCDataChannel
interface sends data across the data channel to the remote peer.
Handlers de Eventos
Also inherits handlers de eventos from: EventTarget
Métodos
Also inherits métodos from: EventTarget
Exemplo
var pc = new RTCPeerConnection();
var dc = pc.createDataChannel("my channel");
dc.onmessage = function (event) {
console.log("received: " + event.data);
};
dc.onopen = function () {
console.log("datachannel open");
};
dc.onclose = function () {
console.log("datachannel close");
};
Especificações
Especificação | Status | Comentário |
---|---|---|
WebRTC 1.0: Real-time Communication Between Browsers The definition of 'RTCDataChannel' in that specification. |
Candidata a Recomendação | Especificação inicial |
Compatibilidade do navegador
Característica | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Suporte básico | (Yes) | 22 (22) [1] | Não suportado | (Yes) | ? |
onbufferedamountlow |
56 | Não suportado | Não suportado | 43 | Não suportado |
Característica | Android Webview | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | 29 | 29 | 22.0 (22) [1] | Não suportado | (Yes) | Não suportado |
onbufferedamountlow |
56 | 56 | Não suportado | ? | 43 | ? |
[1] A interface é chamada DataChannel e não RTCDataChannel no Firefox. No entanto, uma ligação foi implementada desde o Firefox 24 para que qualquer um dos nomes funcione.