@@ -119,9 +119,16 @@ void WebrtcConnection::sendSignalingMessage(
119119
120120void WebrtcConnection::handleMessage (nrtc::util::WebrtcSignalingMessage& msg) {
121121 std::lock_guard<std::mutex> lock (mutex_);
122+
122123 if (msg.isDescription ()) {
123124 auto desc = msg.getDescription ();
124- NPLOGI << " Description received: " << desc.sdp ;
125+ auto type = desc.type == " offer" ? SDP_TYPE_OFFER : SDP_TYPE_ANSWER;
126+ peer_connection_set_remote_description (pc_, desc.sdp .c_str (), type);
127+ }
128+
129+ if (msg.isCandidate ()) {
130+ std::string cand = msg.getCandidate ().candidate ;
131+ peer_connection_add_ice_candidate (pc_, cand.data ());
125132 }
126133}
127134
@@ -139,6 +146,16 @@ void WebrtcConnection::onIceConnectionStateChange(PeerConnectionState state,
139146 NPLOGI << " ICE Connection state changed to " << state;
140147}
141148
142- void WebrtcConnection::onIceCandidate (char * description, void * userdata) {}
149+ void WebrtcConnection::onIceCandidate (char * description, void * userdata) {
150+ WebrtcConnection* conn = reinterpret_cast <WebrtcConnection*>(userdata);
151+ std::string cand = std::string (description);
152+ nrtc::util::SignalingCandidate signalingCandidate (cand);
153+
154+ // @TODO: Probably not correct to just set "0" here.
155+ signalingCandidate.setSdpMid (" 0" );
156+
157+ conn->sendSignalingMessage (
158+ nrtc::util::WebrtcSignalingMessage (signalingCandidate));
159+ }
143160
144- } // namespace nabto::example
161+ } // namespace nabto::example
0 commit comments