GetStream / webrtc-android

🛰️ A versatile WebRTC pre-compiled Android library that reflects the recent WebRTC updates to facilitate real-time video chat for Android and Compose.
https://getstream.github.io/webrtc-android/
Apache License 2.0
568 stars 61 forks source link

Converting Android SessionDescription to javascript RTCSessionDescription error #178

Open tyczj opened 1 month ago

tyczj commented 1 month ago

When trying to send the Android SessionDescription object to a web client RTCSessionDescription I get an error

Error setting remote description DOMException: Failed to execute 'setRemoteDescription' on 'RTCPeerConnection': Failed to parse SessionDescription. Expect line: v=

I also got an error saying that the type enum was incorrect and ANSWER didnt exist, I had to toLowerCase on the type in the web client for that error to go away

When sending the SessionDescription from android I convert it to json with gson like I have seen in a lot of examples

....
json.put("sdp", gson.toJson(desc))
....

Then on the web side I just put that value into the description

peerConnection.setRemoteDescription(new RTCSessionDescription(sdp))

This is what the description data looks like

v=0
o=- 4842731917606126277 2 IN IP4 127.0.0.1
s=-
t=0 0
a=extmap-allow-mixed
a=msid-semantic: WMS

These two types dont seem compatible, what are you suppose to do?

tyczj commented 1 month ago

Just after posting this I found out how to fix it

for anyone else coming across this issue, you cannot just pass in the whole object like this

peerConnection.setRemoteDescription(new RTCSessionDescription(sdp))

or

peerConnection.setRemoteDescription(sdp)

Instead you have to put the type and description in explicitly

peerConnection.setRemoteDescription(new RTCSessionDescription({
                type: sdp.type.toLowerCase(),
                sdp: sdp.description
            }))
tyczj commented 1 month ago

Opening this back up because I dont know if this is a "bug" or not based on the documentation for RTCSessionDescription that using this method is deprecated because setLocalDescription and setRemoteDescription accept sdp that conform to RTCSessionDescriptionInit.

So does that mean the SessionDescription in this library is out of date? Feel free to close again if this isnt a bug and is correct