From dc58831c27336536626a67c8148e645265045f40 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Thu, 12 May 2016 15:47:19 +0200 Subject: [PATCH] Update RTCConfiguration interface to latest spec --- webrtc/RTCPeerConnection-tests.ts | 24 +++++++++++++++++-- webrtc/RTCPeerConnection.d.ts | 39 +++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/webrtc/RTCPeerConnection-tests.ts b/webrtc/RTCPeerConnection-tests.ts index ea850f8724..9cd8087947 100644 --- a/webrtc/RTCPeerConnection-tests.ts +++ b/webrtc/RTCPeerConnection-tests.ts @@ -3,8 +3,28 @@ let voidpromise: Promise; -var config: RTCConfiguration = - { iceServers: [{ urls: "stun.l.google.com:19302" }] }; +var minimalConfig: RTCConfiguration = {}; +var config: RTCConfiguration = { + iceServers: [ + { + // Single url + urls: "stun.l.google.com:19302" + }, + { + // List of urls and credentials + urls: ["another-stun.example.com"], + username: "dude", + credential: "pass", + credentialType: "token" + }, + ], + iceTransportPolicy: "relay", + bundlePolicy: "max-compat", + rtcpMuxPolicy: "negotiate", + peerIdentity: "dude", + certificates: [{expires: 1337}], + iceCandidatePoolSize: 5 +}; var constraints: RTCMediaConstraints = { mandatory: { offerToReceiveAudio: true, offerToReceiveVideo: true } }; diff --git a/webrtc/RTCPeerConnection.d.ts b/webrtc/RTCPeerConnection.d.ts index dcd36d9aec..a3d39130e0 100644 --- a/webrtc/RTCPeerConnection.d.ts +++ b/webrtc/RTCPeerConnection.d.ts @@ -20,17 +20,46 @@ // TODO(2): get Typescript to have union types as WebRtc uses them. // https://typescript.codeplex.com/workitem/1364 -interface RTCConfiguration { - iceServers: RTCIceServer[]; +// https://www.w3.org/TR/webrtc/#idl-def-RTCIceTransportPolicy +type RTCIceTransportPolicy = 'public' | 'relay' | 'all'; + +// https://www.w3.org/TR/webrtc/#idl-def-RTCBundlePolicy +type RTCBundlePolicy = 'balanced' | 'max-compat' | 'max-bundle'; + +// https://www.w3.org/TR/webrtc/#idl-def-RTCRtcpMuxPolicy +type RTCRtcpMuxPolicy = 'negotiate' | 'require'; + +// https://www.w3.org/TR/webrtc/#idl-def-RTCCertificate +interface RTCCertificate { + expires: number; } + +// https://www.w3.org/TR/webrtc/#idl-def-RTCConfiguration +// https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/RTCPeerConnection#RTCConfiguration_dictionary +interface RTCConfiguration { + iceServers ?: RTCIceServer[]; // optional according to mozilla docs + iceTransportPolicy ?: RTCIceTransportPolicy; // default = 'all' + bundlePolicy ?: RTCBundlePolicy; // default = 'balanced' + rtcpMuxPolicy ?: RTCRtcpMuxPolicy; // default = 'require' + peerIdentity ?: string; // default = null + certificates ?: RTCCertificate[]; // default is auto-generated + iceCandidatePoolSize ?: number; // default = 0 +} + declare var RTCConfiguration: { prototype: RTCConfiguration; new (): RTCConfiguration; }; +// https://www.w3.org/TR/webrtc/#idl-def-RTCIceCredentialType +type RTCIceCredentialType = 'password' | 'token'; + +// https://www.w3.org/TR/webrtc/#idl-def-RTCIceServer interface RTCIceServer { - urls: string; + urls: string | string[]; + username?: string; credential?: string; + credentialType?: RTCIceCredentialType; // default = 'password' } declare var RTCIceServer: { prototype: RTCIceServer; @@ -42,7 +71,7 @@ interface mozRTCPeerConnection extends RTCPeerConnection { } declare var mozRTCPeerConnection: { prototype: mozRTCPeerConnection; - new (settings: RTCPeerConnectionConfig, + new (settings?: RTCConfiguration, constraints?:RTCMediaConstraints): mozRTCPeerConnection; }; // webkit (Chrome) specific prefixes. @@ -50,7 +79,7 @@ interface webkitRTCPeerConnection extends RTCPeerConnection { } declare var webkitRTCPeerConnection: { prototype: webkitRTCPeerConnection; - new (settings: RTCPeerConnectionConfig, + new (settings?: RTCConfiguration, constraints?:RTCMediaConstraints): webkitRTCPeerConnection; };