DataChannel消息发送

原因:由于需要使用DataChannel进行消息发送,故在此记录一下流程

概述:通过创建DataChannel,通过事件监听获取连接状态,从而实现消息发送,底层协议为DCT_RTP或者DCT_SCTP。

流程介绍:

首先配置启用rtp_data_channel,底层在创建webrtcsession时会默认data_channel底层协议为DCT_RTP。

webrtc::PeerConnectionInterface::RTCConfiguration config;
config.enable_rtp_data_channel = true;

创建对应的数据通道

 sendchannel = peer_connection_->CreateDataChannel("sendDataChannel", nullptr);

创建回调对象,用于接收通道连接状态。

class OnDataChannel1 :public webrtc::DataChannelObserver {
public:
}
sendchannel->RegisterObserver(&m_datachannel);

接着通过SetLocalDescription和SetRemoteDescription将对应的信息设置给数据通道。从而实现数据通道的互通。此时就会接收到状态回调。通过获取状态信息,可以实现数据的发送。

注意:在设置sdp信息时数据通道的协议和指定的协议比较依照情况修改底层代码。

你可能感兴趣的:(WebRTC)