0

I am trying to set up the signaling between a browser client and unity client. the two clients use Webrtc and I am using a websocket to make the signaling happen. First, I am creating an offer on the click of a button in the browser. the offer reaches the c# client and the localConnection.setRemoteDescription works fine, then I need to create an answer. Instead the answer is an empty object recieved

{"type":0,"sdp":null}

Any Ideas if there is something wrong?

 public void handleIncommingMessages(object sender, MessageEventArgs e) {
        
        SignalingMessage message = JsonConvert.DeserializeObject<SignalingMessage>(e.Data);
        
        switch (message.type){
            case "offer": handleOffer(message); break;
            case "answer": handleAnswer(message);break;
            case "ice-candidate": handleIceCandidateMessage(message);break;
        }
    }

void handleOffer(SignalingMessage offerMessage)
    {
        localConnection.SetRemoteDescription(ref offerMessage.sessionDescription);
     
        RTCSessionDescriptionAsyncOperation answer = localConnection.CreateAnswer();

        Debug.Log(answer.Desc.sdp);
        SignalingMessage answerMessage = new SignalingMessage {type = "answer" , sessionDescription = answer.Desc , iceCandidate = null};
        socket.Send(JsonConvert.SerializeObject(answerMessage));
    }

this is the implementation of the SignalingMessage class which represents any message to be sent over the websocket

public class SignalingMessage
{
    public string type;
    public RTCSessionDescription sessionDescription;
    public RTCIceCandidate iceCandidate;

}
  • Could you show us your `SignalingMessage` implementation? – derHugo Mar 17 '22 at 18:28
  • public class SignalingMessage { public string type; public RTCSessionDescription sessionDescription; public RTCIceCandidate iceCandidate; } – mohammedshetaya Mar 17 '22 at 18:29
  • this implementation is the structure of any message to be sent over the websocket. So it serves the offer, answer, and ice-candidate signaling – mohammedshetaya Mar 17 '22 at 18:30
  • Just to be sure: the empty answer you receive on the c# or on the other side? It looks odd that there is an `sdp` field while in your c# structure the is none .. – derHugo Mar 17 '22 at 18:40
  • I receive null on the c# side the line Debug.Log(answer.Desc.sdp); prints Null – mohammedshetaya Mar 17 '22 at 18:56
  • I think the problem comes from not using Unity coroutine. The answer is created after the execution of the handle offer function and its SDP can be seen in the second frame. Not sure yet how to fix the problem – mohammedshetaya Mar 18 '22 at 02:32
  • yeah since `asnwer` is an `RTCSessionDescriptionAsyncOperation` the type name sounds like you have to wait for the result first. Could you post a more complete code example .. like where does `handleOffer` get invoked etc? – derHugo Mar 18 '22 at 09:02
  • I have added the complete code – mohammedshetaya Mar 18 '22 at 13:49

0 Answers0