WebRTC的DataChannel功能

一 DataChannel可以发送聊天的文本信息,可以走RTP和DTLS。

新版本用RTP不行,sdp协商时,RtpDataChannel的state_变成kClose。

sdp新增了application字段,协议走UDP/DTLS/SCTP。

m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 0.0.0.0
a=ice-ufrag:qZdI
a=ice-pwd:l2lrs5FGHFlox6XZ6rIiKSdT
a=ice-options:trickle
a=fingerprint:sha-256 79:C9:50:1B:44:98:B2:2B:D7:11:2A:AB:85:23:67:2B:5D:41:DF:7A:59:4C:FC:E2:31:E0:8B:76:DA:02:6A:DD
a=setup:actpass
a=mid:2
a=sctp-port:5000
a=max-message-size:262144

抓包如下:sequence number从1开始依次递增。

端口也和音视频端口一样。

二 peerconnect_client新增DataChannel

需要修改的地方如下:

1 config.enable_dtls_srtp = true;

2 Conductor新增从webrtc::DataChannelObserver派生。

3 在CreateOffer、CreateAnswer函数前新增CreateDataChannel,

data_channel_->RegisterObserver(this);。具体可参考:simple_peer_connection.cc。

4 起定时器发送SendDataViaDataChannel()。    

你可能感兴趣的:(webrtc,webrtc)