webrtc
webrtc copied to clipboard
Cannot add a candidate without specifying either sdpMid or sdpMLineIndex - Webrtc Wasm
Your environment.
-
Version: Ubuntu 21.10 (Offer) Ubuntu 20.04 (Answer) go 1.16 GOOS=wasm GOARCH=js pion v3.1.23
-
Browser (Offer) Google Chrome - Ubuntu 21.10 - Version 97.0.4692.99 (Official Build) (64-bit) Firefox - Ubuntu 21.10 - 97.0 (64-bit)
-
Other Information - stacktraces, related issues, suggestions how to fix, links for us to have context
What did you do?
I modified the pion to pion example in order to run the answer on a pc while running the offer inside of wasm. Candidate exchange follows trickle-ice for handling ice candidates as they arrive
What did you expect?
Expected a connection to be made and data transmission to start.
What happened?
Received this error in Firefox:
Uncaught (in promise) TypeError: Cannot add a candidate without specifying either sdpMid or sdpMLineIndex
valueCall http://localhost:9090/wasm_exec.js:399
_resume http://localhost:9090/wasm_exec.js:588
_makeFuncWrapper http://localhost:9090/wasm_exec.js:599
valueCall http://localhost:9090/wasm_exec.js:399
_resume http://localhost:9090/wasm_exec.js:588
_makeFuncWrapper http://localhost:9090/wasm_exec.js:599
And this error in google chrome:
wasm_exec.js:399 Uncaught (in promise) TypeError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': Candidate missing values for both sdpMid and sdpMLineIndex
at syscall/js.valueCall (wasm_exec.js:399:31)
at syscall_js.valueCall (main.wasm:0x180ab9)
at syscall_js.Value.Call (main.wasm:0x17de8f)
at github.com_pion_webrtc_v3.__PeerConnection_.AddICECandidate (main.wasm:0x9413b6)
at wasm_pc_f_loop (main.wasm:0xe8903)
at wasm_export_resume (main.wasm:0xe88e4)
at global.Go._resume (wasm_exec.js:588:23)
When running both offer and answer on the same computer a data connection is created and data is sent but if the answer lies on a different computer over the internet, a connection is not established.
After some additional testing, changing to pion/webrtc v2.2.26 results in the same error on the browser side however a connection is established and data channels are created and operate correctly.
Changing to v3.0.1 however gives the same result as v3.1.23 - ICE connection status does not become connected and data cannot be sent between answer and offer.
Hello. The problem is this piece of code: cecandidate.go#L159
// ToJSON returns an ICECandidateInit
// as indicated by the spec https://w3c.github.io/webrtc-pc/#dom-rtcicecandidate-tojson
func (c ICECandidate) ToJSON() ICECandidateInit {
zeroVal := uint16(0)
emptyStr := ""
candidateStr := ""
candidate, err := c.toICE()
if err == nil {
candidateStr = candidate.Marshal()
}
return ICECandidateInit{
Candidate: fmt.Sprintf("candidate:%s", candidateStr),
SDPMid: &emptyStr,
SDPMLineIndex: &zeroVal,
}
}
Note: Attempting to add a candidate (using addIceCandidate()) that has a value of null for both sdpMid and sdpMLineIndex will throw a TypeError exception.
I ran into this problem in WebRTC-rs, what values should these fields be set to?