Reputation: 989
Chrome.
ICE candidate string generatred on computer A (taken directly from the SDP attribute "candidate"):
candidate:2999745851 1 udp 2122260223 192.168.X.1 65398 typ host generation 0 ufrag XBYY network-id 2
Now that is passed through signaling, to be received on computer B.
computer B received (iceStr):
candidate:2999745851 1 udp 2122260223 192.168.X.1 65398 typ host generation 0 ufrag XBYY network-id 2
and tries to let candidate = new RTCIceCandidate(iceStr)
This results in
TypeError: Failed to construct 'RTCIceCandidate': cannot convert to dictionary.
Computer B does so in order to perform
addIceCandidate(candidate)
on the RTCPeerConnection object.
yet, due to the prior error, unable to proceed.
Reproducable example
<script type="text/javascript">
let c ='candidate:2445384676 1 udp 2122194687 192.168.1.26 57088 typ host generation 0 ufrag z1J2 network-id 1 network-cost 10';
let candidate = new RTCIceCandidate(c);
</script>
Ideas?
All the official code samples and docs instruct to send that very parameter to remote peer. https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/onicecandidate
Then there's some confusion with deprecation (constructed under the hood by other functions it seems ) and JSON encoding so which one is it.
From the official samples: https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Signaling_and_video_calling
function handleNewICECandidateMsg(msg) {
var candidate = new RTCIceCandidate(msg.candidate);
myPeerConnection.addIceCandidate(candidate)
.catch(reportError);
}
The value seems to be also passed directly to var candidate = new RTCIceCandidate(msg.candidate);
which ends up as an exercise in futility (same error).
UPDATE: Looks like the API only understands a String OBJECT (which is sort of a pitty considering the EVENT contains a primitive type!) i.e. reproducable sample
<script type="text/javascript">
let c = new String('candidate:2445384676 1 udp 2122194687 192.168.1.26 57088 typ host generation 0 ufrag z1J2 network-id 1 network-cost 10');
let candidate = new RTCIceCandidate(c);
</script>
But, even then Chrome produces an exception
TypeError: Failed to construct 'RTCIceCandidate': sdpMid and sdpMLineIndex are both null.
There seem to be other 'doubtful' things..like the WebRTC offer contains platform-specific new-line characters.
RTCSessionDescription cannot be instantiated directly from SDP offer returned from event since it's a PRIMITIVE type and RTCSessionDescription() wants String OBJECT. Additionally, the primitive type cannot be easily converted to String since it contains platform specific new-lines and thus simple new String(SDP) results in a malformed String Object.
anyone?
UPDATE In case of the WebRTC offer, the documentation does not state that one needs to provide an explicit JSON object to RTCSessionDescription containing both the type (lame 'offer' string) and SDP fields. Which sort of implicitly forces the use of JSON (inefficient encoding) in the first place throughout the signaling process. (were one no to reconstruct the lame fields on his own but then this contradicts the black-box attitude all over the place)
Upvotes: 5
Views: 5522
Reputation: 17340
You are trying with just the candidate string instead of the full object which also includes the sdpMid and sdpMLineIndex properties, see https://developer.mozilla.org/en-US/docs/Web/API/RTCIceCandidate
You can construct a RTCIceCandidate object as
new RTCIceCandidate({
candidate: 'candidate:2445384676 1 udp 2122194687 192.168.1.26 57088 typ host generation 0 ufrag z1J2 network-id 1 network-cost 10',
sdpMid: 'something', // don't make it up, you get this in onicecandidate
sdpMLineIndex: 12345, // don't make it up, you get this in onicecandidate
})
or you call
pc.addIceCandidate({
candidate: 'candidate:2445384676 1 udp 2122194687 192.168.1.26 57088 typ host generation 0 ufrag z1J2 network-id 1 network-cost 10',
sdpMid: 'something', // don't make it up, you get this in onicecandidate
sdpMLineIndex: 12345, // don't make it up, you get this in onicecandidate
})
The same applies to RTCSessionDescription objects.
Upvotes: 5