TypeScript-DOM-lib-generator
TypeScript-DOM-lib-generator copied to clipboard
RTCPeerConnection.addIceCandidate cannot be called with `null`
In WebRTC, the icecandidate event’s candidate property is either “an RTCIceCandidate object … or null to indicate that there are no further candidates”. This currently has the correct type in dom.d.ts:
interface RTCPeerConnectionIceEvent extends Event {
readonly candidate: RTCIceCandidate | null;
}
null has the same special meaning on the receiver side of the ICE gathering process. The addIceCandidate is used both to submit a candidate from the remote peer, or to convey the end-of-candidates signal “[i]f no candidate object is specified, or its value is null”.
But it’s not currently valid to pipe a null from the icecandidate event to addIceCandidate:
interface RTCPeerConnection extends EventTarget {
addIceCandidate(candidate?: RTCIceCandidateInit): Promise<void>;
}
error TS2345: Argument of type
nullis not assignable to parameter of typeRTCIceCandidateInit | undefined