Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    Dismiss Notice

Question Unity WebRTC DataChannel not connected

Discussion in 'Unity Render Streaming' started by patrickk2, Dec 20, 2020.

  1. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    88
    Hello everyone!

    I have trouble getting a connection between my Linux server and the corresponding corresponding WebGL client (both build with Unity with the WebRTC package).

    The exchange of offer and answer works fine, I see they are created and set in the respective logs. The server creates a DataChannel and adds the OnOpen, OnClose, and OnMessage event handlers accordingly (they only log the event, and do nothing else).

    On the client side RTCPeerConnection, I made sure to add anOnDataChannel event handler.

    (More detailed information is in the spoiler tags. If anything is missing, that could help analyse the problem, please tell me. I will try to provide the information as quickly as I can.)

    1. Client sends request for new connection to server (via HTTP)
    2. Server creates RTCPeerConnection, and
      1. Adds OnIceCandidate and OnIceConnectionChange listeners
      2. Creates a DataChannel and adds OnOpen, OnClose and OnMessage listeners to it
      3. Creates an Offer
      4. Sets the Offer as the local description
    3. Server sends the SDP of its connections local description to the client
    4. Client create RTCPeerConnection, and
      1. Adds OnIceCandidate and OnIceConnectionChange listeners
      2. Adds OnDataChannel listener
      3. Sets the received SDP as the remote connection
      4. Creates an Answer
      5. Sets the Answer as the local description
    5. Client sends the SDP of its connections local description to the server
    6. Server sets the received SDP as its connections remote description

    The created Offers and Answers look fine to me. The second ICE candidate in the offer is reachable from the WebGL client.

    Offer:
    Code (csharp):
    1.  
    2. v=0
    3. o=- 5366312064322448853 2 IN IP4 127.0.0.1
    4. s=-
    5. t=0 0
    6. a=group:BUNDLE 0
    7. a=msid-semantic: WMS
    8. m=application 7701 UDP/DTLS/SCTP webrtc-datachannel
    9. c=IN IP4 SERVER.EXTERNAL.IP.ADDRESS
    10. a=candidate:1876262918 1 udp 2122260223 SERVER.LOCAL.IP.ADDRESS 7701 typ host generation 0 network-id 1
    11. a=candidate:2579888594 1 udp 1686052607 SERVER.EXTERNAL.IP.ADDRESS 7701 typ srflx raddr SERVER.LOCAL.IP.ADDRESS rport 7701 generation 0 network-id 1
    12. a=candidate:559316214 1 tcp 1518280447 SERVER.LOCAL.IP.ADDRESS 7701 typ host tcptype passive generation 0 network-id 1
    13. a=ice-ufrag:TqC1
    14. a=ice-pwd:Hx7vnJSW9mmeSYP2IZqRy8i5
    15. a=ice-options:trickle
    16. a=fingerprint:sha-256 53:48:DA:18:BA:B3:7E:62:F5:E7:46:43:4B:CF:61:38:D8:B3:4B:E4:D6:02:39:88:82:FE:04:FB:DC:B8:6C:53
    17. a=setup:actpass
    18. a=mid:0
    19. a=sctp-port:5000
    20. a=max-message-size:262144
    21.  
    Answer:
    Code (csharp):
    1.  
    2. v=0
    3. o=mozilla...THIS_IS_SDPARTA-83.0 1159867020348037098 0 IN IP4 0.0.0.0
    4. s=-
    5. t=0 0
    6. a=fingerprint:sha-256 63:9B:64:96:ED:82:AA:A8:35:AD:2B:72:C6:81:67:97:69:C6:56:92:1C:E6:88:89:41:06:4B:41:27:EA:E1:D5
    7. a=group:BUNDLE 0
    8. a=ice-options:trickle
    9. a=msid-semantic:WMS *
    10. m=application 9 UDP/DTLS/SCTP webrtc-datachannel
    11. c=IN IP4 0.0.0.0
    12. a=sendrecv
    13. a=ice-pwd:f36d327bb2047e5d55b29bb6638d24e6
    14. a=ice-ufrag:ced5a3cc
    15. a=mid:0
    16. a=setup:active
    17. a=sctp-port:5000
    18. a=max-message-size:1073741823
    19.  

    Unfortunatelly I never see in the server logs that the channel was opened, or in the client logs, that it was received.

    I do see in the server logs that the RTCIceConnectionState changes to Checking, but no further changes after that. Although the offer from the server contains a candidate that should work.

    I would really appreciate any thoughts, and tipps to find the cause that the RTCPeerConnections don't really connect.

    Thanks in advance and best regards,
    Patrick
     
  2. kazuki_unity729

    kazuki_unity729

    Unity Technologies

    Joined:
    Aug 2, 2018
    Posts:
    581
    The WebRTC package does not support WebGL platform yet.
    I would like to know how you are testing it.
     
  3. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    88
    Hello Kazuki and thank you for your answer!

    I’ve coded some own stuff to use WebGL as target. Of course, I’m eager for the official stuff from Unity as soon as it will be released.

    But nevertheless, back to my question, if you apologize. Do you – or anyone else who is reading through my post – have a clue why this stuff isn’t working? Maybe any ideas and/or hints what is on a wrong track?

    Thank you in advance!

    Best regards,
    Patrick
     
  4. sahithigurram25

    sahithigurram25

    Joined:
    May 13, 2020
    Posts:
    4
    Hello Patrick, I have the exact same problem. May I know if you found a reason why the data channel is not being opened?
     
  5. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    88
    Hello sahithigurram25!

    If I remember corretly the problem was, that I messed up the order of creating the datachannel and the offer. I created the offer first, so it never contained information about the data channel (i.e. I got the steps 2.2 und 2.3 from the connection process in my first post mixed up).

    Hope that helps, or at least sends you in the right direction.

    Best regards,
    Patrick
     
  6. sahithigurram25

    sahithigurram25

    Joined:
    May 13, 2020
    Posts:
    4
    Thanks for ur reply. But I have created the datachannel before creating the offer but it still doesn't open up for me.

    My situation is that I am negotiating the offer by copying the offer that was created by one of the peer connections and pasting the offer at the remote peer connection. I'm doing this by means of unity text box UI. I think that's creating the issue.
    Also I tried to open up the dataChannel by manually negotiating and setting up an id to the RTCDataChannelinit object. But when I pass this object to RTCPeerconnection.createdatachannel, the resulting RTCDatachannel object's id is still -1. It is not updating it to the user given id.

    I'm not sure if u worked on this but please feel free to give some suggestions.
     
  7. patrickk2

    patrickk2

    Joined:
    Dec 8, 2019
    Posts:
    88
    Hello sahithigurram25!

    I have never tried to set the ID of the RTC datachannel, so I cannot say anything on this matter.

    The copy & paste approach does sound problematic to me though. Are you sure that the resulting string is valid session description? And are you passing the RTCSessionDescription object created from it to the peer connections SetRemoteDescription() method?

    If so, you should get a valid answer after that by calling the peers CreateAnswer() method.

    I hope this can help at least a little, all I can say is, that the connection worked fine with the steps from my original post, als long as I don't mix up the order.

    Best regards,
    Patrick
     
  8. sahithigurram25

    sahithigurram25

    Joined:
    May 13, 2020
    Posts:
    4
    Yeah the offer and the answer negotiation works. The only problem was with the dataChannel. Anyways thanks for your suggestion.