Peer-to-Peer Data API
点对点数据 API 使 Web 应用程序可以点对点发送和接收通用应用程序数据。 用于发送和接收数据的 API 对 WebSocket 的行为进行建模。
- Method: RTCDataChannel
createDataChannel([TreatNullAs=EmptyString] DOMString label, optionalRTCDataChannelInit dataChannelDict)
- Attribute: EventHandler
ondatachannel
接口 RTCDataChannel 接口方法
表A-8 方法
Return type | Description |
---|---|
void | close() |
void | send(DOMString data) |
void | send(Blob data) |
void | send(ArrayBuffer data) |
void | send(ArrayBufferView data) |
RTCDataChannel 接口属性
表A-9 属性
Access property | Type | Name |
---|---|---|
readonly | DOMString | label |
readonly | boolean | ordered |
readonly | unsigned? | maxRetransmitTime |
readonly | unsigned? | maxRetransmits |
readonly | DOMString | protocol |
readonly | attribute | negotiated |
readonly | unsigned | shortid |
readonly | RTCDataChannelState | readyState |
readonly | unsigned long | bufferedAmount |
EventHandler | onopen | |
EventHandler | onerror | |
EventHandler | onclose | |
EventHandler | onmessage | |
DOMString | binaryType |
表A-10 RTCDataChannelInit 字典
Name | Type | Description |
---|---|---|
id | unsigned short | 覆盖此通道的 ID 的默认选择。 |
maxRetransmitTime | unsigned short | 限制如果未成功传送通道将重新传输数据的时间。 |
maxRetransmits | unsigned short | 限制如果传输失败则通道将重新传输数据的次数。 |
negotiated | boolean | 默认为 false 。 默认值 false 指示用户代理宣布带内通道,并指示另一个对等方调度相应的 RTCDataChannel 对象。 如果设置为 true ,则由应用程序来协商通道并创建具有与另一个对等方相同的 ID 的 RTCDataChannel 对象。 |
ordered | boolean | 默认为 true 。 如果设置为 false ,则允许数据无序发送。 默认值 true 保证数据将按顺序传递。 |
protocol | DOMString | 默认为 "" 。 此通道使用的子协议名称 |
表A-11 RTCDataChannelState 枚举值
Value | Description |
---|---|
connecting | 用户代理正在尝试建立基础数据传输。 这是使用 createDataChannel() 创建的 RTCDataChannel 对象的初始状态。 |
open | 建立了基础数据传输,并且可以进行通信。 这是作为 RTCDataChannelEvent 的一部分调度的 RTCDataChannel 对象的初始状态。 |
closing | 关闭基础数据传输的过程已开始。 |
closed | 基础数据传输已关闭或无法建立。 |
当前内容版权归 Salvatore Loreto & Simon Pietro Romano 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 Salvatore Loreto & Simon Pietro Romano .