sipsorcery-org / sipsorcery

A WebRTC, SIP and VoIP library for C# and .NET. Designed for real-time communications apps.
https://sipsorcery-org.github.io/sipsorcery
Other
1.42k stars 431 forks source link

setRemoteDescription doesn't change signalingState (webRTC) #1061

Closed maurosorrentino closed 7 months ago

maurosorrentino commented 7 months ago

I create the offer like this RTCSessionDescriptionInit offer = this.peerConnection.createOffer(null); I set the local description like this await this.peerConnection.setLocalDescription(offer); via my signaling mechanism I get the offer and set the remote description like this this.peerConnection.setRemoteDescription(offer); // offer is of type RTCSessionDescriptionInit I create the answer like this RTCSessionDescriptionInit answer = this.peerConnection.createAnswer(null); I set the local description like this await this.peerConnection.setLocalDescription(answer); I send the answer via my signaling mechanism and set the remote description like this this.peerConnection.setRemoteDescription(answer); // answer is of type RTCSessionDescriptionInit

RTCPeerConnection minimal implementation is this one RTCConfiguration config = new RTCConfiguration { iceServers = new List<RTCIceServer>() { new RTCIceServer { urls = this.STUN_URL } } };
RTCPeerConnection peerConnection = new RTCPeerConnection(config);

I had a look at the code setRemoteDescription and it's supposed to change the SignalingState and add the ice candidate but it's not changing the state so this won't work peerConnection.onicecandidate += (iceCandidate) => as it checks peerConnection.signalingState == RTCSignalingState.have_remote_offer.

The signaling state is stuck at have_local_offer.

The thing is that remote description gets set as if I do Console.WriteLine(($"remote description {this.peerConnection.remoteDescription.sdp}");) I get the following:

remote description v=0 o=- 86432 0 IN IP4 127.0.0.1 s=sipsorcery t=0 0

I don't need any media settings as I will use the peer connection for exchanging strings.

I'm sure I'm missing something but I don't understand what as there are no errors or warnings

ChristopheI commented 7 months ago

Before you create the offer, you must first specify media involved in the connection / call. (I guess you did it) You create the offer and set it as local description.

The offer must contains one or several lines starting with "m=". Is it the case ?

This offer must be be provided to the peer. The peer could specify which media are involved in the connection / call (for example he wants to receive only audio - not send/receive). Then use the offer using setRemoteDescription. Finally call createanswer to have the 'final' SDP.

Here you must have one or several lines starting with "m=". Is it the case ?

Send it to back to first emitter which must use it using setRemoteDescription.

maurosorrentino commented 7 months ago

adding the audio worked! I didn't think I needed that as I will use webRTC for peer to peer connection but clients will exchange strings and not audio or video. Many thanks, I appreciate it a lot as I was stuck for a while

ChristopheI commented 7 months ago

If you want a DataChannel only, specify it before to create the first offer. (like any other media) I guess your pb is solved