概述RTCDataChannel 基于 SCTP 提供可靠/不可靠与有序/无序消息传输。可按场景选择参数以平衡延迟与可靠性。用法/示例const pc = new RTCPeerConnection()
const dc = pc.createDataChannel('chat', { ordered: true })
dc.onopen = () => dc.send('hello')
dc.onmessage = e => console.log('msg', e.data)
// 不可靠低延迟
pc.createDataChannel('ticks', { ordered: false, maxRetransmits: 0 })
工程建议对关键消息使用可靠有序通道,对状态广播使用不可靠低延迟通道。监控 `bufferedAmount` 并做限流,避免拥塞;设计重连与状态同步机制。与媒体通道协作,统一会话与错误处理;提供断线回退路径。参考与验证MDN:RTCDataChannel — https://developer.mozilla.org/docs/Web/API/RTCDataChannelW3C:WebRTC — https://www.w3.org/TR/webrtc/

发表评论 取消回复