void RtcStream::SetRemoteDescription(const std::string& msg) { // convert to local json object Json::Reader reader; Json::Value jmessage; std::string decodedMsg = talk_base::Base64::Decode(msg, talk_base::Base64::DO_STRICT); if (!reader.parse(decodedMsg, jmessage)) { LOG(WARNING) << " Parse the JSON failed"; return; } // convert to local sesion description object std::string type; std::string sdp; GetStringFromJsonObject(jmessage, kSessionDescriptionTypeName, &type); GetStringFromJsonObject(jmessage, kSessionDescriptionSdpName, &sdp); if ( sdp.empty() || type.empty() ) { LOG(WARNING) << " Convert to SDP failed"; return; } webrtc::SessionDescriptionInterface* session_description( webrtc::CreateSessionDescription(type, sdp)); if (!session_description) { LOG(WARNING) << "Can't parse received session description message."; return; } connection_->SetRemoteDescription( RtcStreamSetSessionDescriptionObserver::Create(), session_description); }
void RtcStream::SetRemoteCandidate(const std::string& msg) { // convert to local json object Json::Reader reader; Json::Value jmessage; std::string decodedMsg = talk_base::Base64::Decode(msg, talk_base::Base64::DO_STRICT); if (!reader.parse(decodedMsg, jmessage)) { LOG(WARNING) << " Parse the JSON failed"; return; } // parse the received json object std::string sdp_mid; int sdp_mlineindex = 0; std::string sdp; if (!GetStringFromJsonObject(jmessage, kCandidateSdpMidName, &sdp_mid) || !GetIntFromJsonObject(jmessage, kCandidateSdpMlineIndexName, &sdp_mlineindex) || !GetStringFromJsonObject(jmessage, kCandidateSdpName, &sdp)) { LOG(WARNING) << "Can't parse received message."; return; } talk_base::scoped_ptr<webrtc::IceCandidateInterface> candidate( webrtc::CreateIceCandidate(sdp_mid, sdp_mlineindex, sdp)); if (!candidate.get()) { LOG(WARNING) << "Can't parse received candidate message."; return; } if (!connection_->AddIceCandidate(candidate.get())) { LOG(WARNING) << "Failed to apply the received candidate"; return; } return; }
void KeTunnelClient::OnRouterMessage(const std::string &peer_id, talk_base::Buffer &msg) { std::string strMsg(msg.data(),msg.length()); Json::Reader reader; Json::Value jmessage; if (!reader.parse(strMsg, jmessage)) { LOG(WARNING) << "Received unknown message. " << strMsg; return; } std::string command; bool ret = GetStringFromJsonObject(jmessage, kKaerMsgCommandName, &command); if(!ret){ LOG(WARNING)<<"get command error"<<peer_id<<" Msg "<<strMsg; return; } }