Skip to content

Commit

Permalink
Fix review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
soareschen committed Nov 3, 2018
1 parent 06ee892 commit e610400
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 101 deletions.
55 changes: 37 additions & 18 deletions webrtc/RTCDtlsTransport-getRemoteCertificates.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// doSignalingHandshake

// The following helper functions are called from RTCTransport-helper.js:
// waitConnectingPc
// createDtlsTransportsFromSctp
// createDtlsTransportsFromSenderReceiver
// waitForConnectedState
// getDtlsTransportFromSctpTransport
// getDtlsTransportsFromSenderReceiver

function validateConnectedDtlsTransport(dtlsTransport) {
const certs = dtlsTransport.getRemoteCertificates();
Expand Down Expand Up @@ -43,17 +43,31 @@
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc2.close());

const [dtlsTransports1, dtlsTransports2] = await createDtlsTransportsFromSenderReceiver(pc1, pc2)
const dtlsTransports = [...dtlsTransports1, ... dtlsTransports2];
const [track, mediaStream] = await getTrackFromUserMedia('audio')
addTrackOrTransceiver(pc1, track, mediaStream);
exchangeIceCandidates(pc1, pc2);

for (const dtlsTransport of dtlsTransports) {
await doSignalingHandshake(pc1, pc2);

const dtlsTransports1 = getDtlsTransportsFromSenderReceiver(pc1);
const dtlsTransports2 = getDtlsTransportsFromSenderReceiver(pc2);

for (const dtlsTransport of dtlsTransports1) {
validateConnectingDtlsTransport(dtlsTransport);
}

for (const dtlsTransport of dtlsTransports2) {
validateConnectingDtlsTransport(dtlsTransport);
}

await waitConnectingPc(pc1);
await waitConnectingPc(pc2);
await waitForConnectedState(pc1);
await waitForConnectedState(pc2);

for (const dtlsTransport of dtlsTransports1) {
validateConnectedDtlsTransport(dtlsTransport);
}

for (const dtlsTransport of dtlsTransports) {
for (const dtlsTransport of dtlsTransports2) {
validateConnectedDtlsTransport(dtlsTransport);
}
}, 'RTP - connected DTLS transports should have valid remote certificates');
Expand All @@ -65,17 +79,22 @@
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc2.close());

const dtlsTransports = await createDtlsTransportsFromSctp(pc1, pc2)
for (const dtlsTransport of dtlsTransports) {
validateConnectingDtlsTransport(dtlsTransport);
}
pc1.createDataChannel('');
exchangeIceCandidates(pc1, pc2);

await waitConnectingPc(pc1);
await waitConnectingPc(pc2);
await doSignalingHandshake(pc1, pc2);

for (const dtlsTransport of dtlsTransports) {
validateConnectedDtlsTransport(dtlsTransport);
}
const dtlsTransport1 = getDtlsTransportFromSctpTransport(pc1.sctp);
const dtlsTransport2 = getDtlsTransportFromSctpTransport(pc2.sctp);

validateConnectingDtlsTransport(dtlsTransport1);
validateConnectingDtlsTransport(dtlsTransport2);

await waitForConnectedState(pc1);
await waitForConnectedState(pc2);

validateConnectedDtlsTransport(dtlsTransport1);
validateConnectedDtlsTransport(dtlsTransport2);
}, 'SCTP - connected DTLS transports should have valid remote certificates');

</script>
46 changes: 35 additions & 11 deletions webrtc/RTCIceTransport.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
// addTrackOrTransceiver

// The following helper functions are called from RTCTransport-helper.js:
// waitConnectingPc
// waitForConnectedState
// getDtlsTransportFromSctpTransport
// getDtlsTransportsFromSenderReceiver
// getIceTransportFromSctpTransport
// getIceTransportsFromSenderReceiver
// createIceTransportsFromSenderReceiver
// getIceTransportFromDtlsTransport
// getIceTransportsFromDtlsTransports

function validateIceCandidates(candidates) {
assert_greater_than(candidates.length, 0,
Expand Down Expand Up @@ -88,10 +90,19 @@
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc2.close());

const [iceTransport1, iceTransport2] = await createIceTransportsFromSctp(pc1, pc2);
pc1.createDataChannel('');
exchangeIceCandidates(pc1, pc2);

await doSignalingHandshake(pc1, pc2);

const dtlsTransport1 = getDtlsTransportFromSctpTransport(pc1.sctp);
const dtlsTransport2 = getDtlsTransportFromSctpTransport(pc2.sctp);

await waitConnectingPc(pc1);
await waitConnectingPc(pc2);
const iceTransport1 = getIceTransportFromDtlsTransport(dtlsTransport1);
const iceTransport2 = getIceTransportFromDtlsTransport(dtlsTransport2);

await waitForConnectedState(pc1);
await waitForConnectedState(pc2);

validateConnectedIceTransport(iceTransport1);
validateConnectedIceTransport(iceTransport2);
Expand All @@ -104,13 +115,26 @@
const pc2 = new RTCPeerConnection();
t.add_cleanup(() => pc2.close());

const [iceTransports1, iceTransports2] = await createIceTransportsFromSenderReceiver(pc1, pc2)
const iceTransports = [...iceTransports1, ...iceTransports2];
const [track, mediaStream] = await getTrackFromUserMedia('audio')
addTrackOrTransceiver(pc1, track, mediaStream);
exchangeIceCandidates(pc1, pc2);

await waitConnectingPc(pc1);
await waitConnectingPc(pc2);
await doSignalingHandshake(pc1, pc2);

for (const iceTransport of iceTransports) {
const dtlsTransports1 = getDtlsTransportsFromSenderReceiver(pc1);
const dtlsTransports2 = getDtlsTransportsFromSenderReceiver(pc2);

const iceTransports1 = getIceTransportsFromDtlsTransports(dtlsTransports1);
const iceTransports2 = getIceTransportsFromDtlsTransports(dtlsTransports2);

await waitForConnectedState(pc1);
await waitForConnectedState(pc2);

for (const iceTransport of iceTransports1) {
validateConnectedIceTransport(iceTransport);
}

for (const iceTransport of iceTransports2) {
validateConnectedIceTransport(iceTransport);
}
}, 'RTP - Connected ICE transports should have relevants attributes set');
Expand Down
13 changes: 4 additions & 9 deletions webrtc/RTCPeerConnection-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,10 @@ function canAddTransceiver() {
}
}

// A dependency agnostic way of adding track depending
// on the supported method on a browser. Uses addTransceiver(track)
// first if available, otherwise use addTrack(track, mediaStream)
// or falls back to the legacy addStream method (which has been removed
// from the spec).
// A dependency agnostic way to add a track track depending
// on the supported method on a browser.
// - If addTransceiver(track) is usable, use that.
// - If addTrack(track, mediastream) is available, use that.
function addTrackOrTransceiver(pc, track, mediaStream) {
if (canAddTransceiver()) {
return pc.addTransceiver(track);
Expand All @@ -519,10 +518,6 @@ function addTrackOrTransceiver(pc, track, mediaStream) {
// it for now so that we can test older versions of Firefox that only
// implements addTrack with compulsory mediaStream argument.
return pc.addTrack(track, mediaStream);
} else if (typeof pc.addStream === 'function') {
// FIXME: Remove this case of using addStream once most major browsers
// support addTrack or addTransceiver.
return pc.addStream(mediaStream)
} else {
throw new Error('This test requires either addTrack or addTransceiver implemented');
}
Expand Down
62 changes: 5 additions & 57 deletions webrtc/RTCTransport-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// is "connected", all RTCIceTransports and RTCDtlsTransports are in the
// "connected", "completed" or "closed" state and at least one of them is in the
// "connected" or "completed" state.
function waitConnectingPc(pc) {
function waitForConnectedState(pc) {
return new Promise((resolve, reject) => {
if (pc.connectionState === 'connected') {
resolve();
Expand Down Expand Up @@ -56,9 +56,9 @@ function getIceTransportFromSctpTransport(sctpTransport) {
}

// Get one or more RTCDtlsTransports from RTCRtpSender/Receiver
// in pc. There may be more than one e.g. there are more than one
// senders/receivers or when there are different underlying
// transports for RTP and RTCP.
// in pc.There may be more than one DTLSTransport if there are
// multiple underlying transports, such as when not using max-bundle,
// or when not using RTCP multiplexing.
function getDtlsTransportsFromSenderReceiver(pc) {
const senders = pc.getSenders();
const receivers = pc.getReceivers();
Expand Down Expand Up @@ -91,7 +91,7 @@ function getDtlsTransportsFromSenderReceiver(pc) {
const dtlsTransports = [...dtlsTransportsSet];

if (dtlsTransports.length === 0) {
assert_unreached('Expect to get at least one unique RTCDtlsTransport from sender receivers');
assert_unreached('Expect to get at least one unique RTCDtlsTransport from senders and receivers');
}

return dtlsTransports;
Expand Down Expand Up @@ -124,55 +124,3 @@ function getIceTransportsFromSenderReceiver(pc) {

return [...iceTransports];
}

// Create DTLS transports by creating data channels
// and connecting two peer connections. Returns an
// array of two RTCDtlsTransports, which obtained
// from RTCSctpTransport in pc.sctp.
async function createDtlsTransportsFromSctp(pc1, pc2) {
pc1.createDataChannel('');
exchangeIceCandidates(pc1, pc2);

await doSignalingHandshake(pc1, pc2);

const dtlsTransport1 = getDtlsTransportFromSctpTransport(pc1.sctp);
const dtlsTransport2 = getDtlsTransportFromSctpTransport(pc2.sctp);

return [dtlsTransport1, dtlsTransport2];
}

// Create DTLS transports by adding tracks and connecting
// two peer connections. Returns an array of two array of
// RTCDtlsTransports. This is because each peer connection
// may have multiple underlying DTLS transports for each
// RTP/RTCP sender/receivers.
async function createDtlsTransportsFromSenderReceiver(pc1, pc2) {
const [track, mediaStream] = await getTrackFromUserMedia('audio')
addTrackOrTransceiver(pc1, track, mediaStream);
exchangeIceCandidates(pc1, pc2);

await doSignalingHandshake(pc1, pc2);

const dtlsTransports1 = getDtlsTransportsFromSenderReceiver(pc1);
const dtlsTransports2 = getDtlsTransportsFromSenderReceiver(pc2);

return [dtlsTransports1, dtlsTransports2];
}

async function createIceTransportsFromSctp(pc1, pc2) {
const [dtlsTransport1, dtlsTransport2] = await createDtlsTransportsFromSctp(pc1, pc2)

const iceTransport1 = getIceTransportFromDtlsTransport(dtlsTransport1);
const iceTransport2 = getIceTransportFromDtlsTransport(dtlsTransport2);

return [iceTransport1, iceTransport2];
}

async function createIceTransportsFromSenderReceiver(pc1, pc2) {
const [dtlsTransports1, dtlsTransports2] = await createDtlsTransportsFromSenderReceiver(pc1, pc2)

const iceTransports1 = getIceTransportsFromDtlsTransports(dtlsTransports1);
const iceTransports2 = getIceTransportsFromDtlsTransports(dtlsTransports2);

return [iceTransports1, iceTransports2];
}
14 changes: 8 additions & 6 deletions webrtc/tools/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
rules: {
'no-undef': 1,
'no-unused-vars': 0,
'no-unused-vars': 0
},
plugins: [
'html'
Expand All @@ -10,6 +10,9 @@ module.exports = {
browser: true,
es6: true
},
parserOptions: {
ecmaVersion: 2017
},
globals: {
// testharness globals
test: true,
Expand Down Expand Up @@ -155,15 +158,14 @@ module.exports = {
validateCertificateStats: true,

// RTCTransport-helper.js
waitConnectingPc: true,
waitForConnectedState: true,
getDtlsTransportFromSctpTransport: true,
getIceTransportFromSctpTransport: true,
getDtlsTransportsFromSenderReceiver: true,
getIceTransportFromDtlsTransport: true,
getIceTransportsFromSenderReceiver: true,
createDtlsTransportsFromSctp: true,
createDtlsTransportsFromSenderReceiver: true,
createIceTransportsFromSctp: true,
createIceTransportsFromSenderReceiver: true,
getIceTransportFromDtlsTransport: true,
getIceTransportsFromDtlsTransports: true,
getIceTransportsFromSenderReceiver: true
}
}
1 change: 1 addition & 0 deletions webrtc/tools/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json

0 comments on commit e610400

Please sign in to comment.