mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Update web-platform-tests to revision 823cca0c2c6b421912973e7f699a357411738c64
This commit is contained in:
parent
6cc582992e
commit
6f4d1ac19b
141 changed files with 2004 additions and 912 deletions
|
@ -190,74 +190,6 @@ function exchangeIceCandidates(pc1, pc2) {
|
|||
doExchange(pc2, pc1);
|
||||
}
|
||||
|
||||
// Helper class to exchange ice candidates between
|
||||
// two local peer connections
|
||||
class CandidateChannel {
|
||||
constructor(source, dest, name) {
|
||||
source.addEventListener('icecandidate', event => {
|
||||
const { candidate } = event;
|
||||
if (candidate && this.activated
|
||||
&& this.destination.signalingState !== 'closed') {
|
||||
this.destination.addIceCandidate(candidate);
|
||||
} else if (candidate) {
|
||||
this.queue.push(candidate);
|
||||
}
|
||||
});
|
||||
dest.addEventListener('signalingstatechange', event => {
|
||||
if (this.destination.signalingState == 'stable' && !this.activated) {
|
||||
this.activate();
|
||||
}
|
||||
});
|
||||
this.name = name;
|
||||
this.destination = dest;
|
||||
this.activated = false;
|
||||
this.queue = [];
|
||||
}
|
||||
activate() {
|
||||
this.activated = true;
|
||||
for (const candidate of this.queue) {
|
||||
this.destination.addIceCandidate(candidate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Alternate function to exchange ICE candidates between two
|
||||
// PeerConnections. Unlike exchangeIceCandidates, it will function
|
||||
// correctly if candidates are added before descriptions are set.
|
||||
function coupleIceCandidates(pc1, pc2) {
|
||||
const ch1 = new CandidateChannel(pc1, pc2, 'forward');
|
||||
const ch2 = new CandidateChannel(pc2, pc1, 'back');
|
||||
return [ch1, ch2];
|
||||
}
|
||||
|
||||
// Helper function for doing one round of offer/answer exchange
|
||||
// between two local peer connections.
|
||||
// Calls setRemoteDescription(offer/answer) before
|
||||
// setLocalDescription(offer/answer) to ensure the remote description
|
||||
// is set and candidates can be added before the local peer connection
|
||||
// starts generating candidates and ICE checks.
|
||||
async function doSignalingHandshake(localPc, remotePc, options={}) {
|
||||
let offer = await localPc.createOffer();
|
||||
// Modify offer if callback has been provided
|
||||
if (options.modifyOffer) {
|
||||
offer = await options.modifyOffer(offer);
|
||||
}
|
||||
|
||||
// Apply offer.
|
||||
await remotePc.setRemoteDescription(offer);
|
||||
await localPc.setLocalDescription(offer);
|
||||
|
||||
let answer = await remotePc.createAnswer();
|
||||
// Modify answer if callback has been provided
|
||||
if (options.modifyAnswer) {
|
||||
answer = await options.modifyAnswer(answer);
|
||||
}
|
||||
|
||||
// Apply answer.
|
||||
await localPc.setRemoteDescription(answer);
|
||||
await remotePc.setLocalDescription(answer);
|
||||
}
|
||||
|
||||
// Returns a promise that resolves when the |transport| gets a
|
||||
// 'statechange' event with the value |state|.
|
||||
// This should work for RTCSctpTransport, RTCDtlsTransport and RTCIceTransport.
|
||||
|
@ -376,96 +308,25 @@ function listenForSSRCs(t, receiver) {
|
|||
// It does the heavy lifting of performing signaling handshake,
|
||||
// ICE candidate exchange, and waiting for data channel at two
|
||||
// end points to open.
|
||||
function createDataChannelPair(
|
||||
pc1=new RTCPeerConnection(),
|
||||
pc2=new RTCPeerConnection(),
|
||||
options={})
|
||||
{
|
||||
options = Object.assign({}, {
|
||||
channelLabel: '',
|
||||
channelOptions: undefined,
|
||||
doSignaling: true
|
||||
}, options);
|
||||
|
||||
let channel1Options;
|
||||
let channel2Options = null;
|
||||
if (options.channelOptions instanceof Array) {
|
||||
[channel1Options, channel2Options] = options.channelOptions;
|
||||
} else {
|
||||
channel1Options = options.channelOptions;
|
||||
async function createDataChannelPair(
|
||||
pc1 = new RTCPeerConnection(),
|
||||
pc2 = new RTCPeerConnection()) {
|
||||
const pair = [pc1, pc2].map(pc =>
|
||||
pc.createDataChannel('', {negotiated: true, id: 0}));
|
||||
const bothOpen = Promise.all(pair.map(dc => new Promise((r, e) => {
|
||||
dc.onopen = r;
|
||||
dc.onerror = ({error}) => e(error);
|
||||
})));
|
||||
try {
|
||||
exchangeIceCandidates(pc1, pc2);
|
||||
await exchangeOfferAnswer(pc1, pc2);
|
||||
await bothOpen;
|
||||
return pair;
|
||||
} finally {
|
||||
for (const dc of pair) {
|
||||
dc.onopen = dc.onerror = null;
|
||||
}
|
||||
}
|
||||
|
||||
const channel1 = pc1.createDataChannel(options.channelLabel, channel1Options);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let channel2;
|
||||
let opened1 = false;
|
||||
let opened2 = false;
|
||||
|
||||
function cleanup() {
|
||||
channel1.removeEventListener('open', onOpen1);
|
||||
channel2.removeEventListener('open', onOpen2);
|
||||
channel1.removeEventListener('error', onError);
|
||||
channel2.removeEventListener('error', onError);
|
||||
}
|
||||
|
||||
function onBothOpened() {
|
||||
cleanup();
|
||||
resolve([channel1, channel2]);
|
||||
}
|
||||
|
||||
function onError(...args) {
|
||||
cleanup();
|
||||
reject(...args);
|
||||
}
|
||||
|
||||
function onOpen1() {
|
||||
opened1 = true;
|
||||
if (opened2) {
|
||||
onBothOpened();
|
||||
}
|
||||
}
|
||||
|
||||
function onOpen2() {
|
||||
opened2 = true;
|
||||
if (opened1) {
|
||||
onBothOpened();
|
||||
}
|
||||
}
|
||||
|
||||
function onDataChannelPairFound() {
|
||||
channel2.addEventListener('error', onError, { once: true });
|
||||
const { readyState } = channel2;
|
||||
|
||||
if (readyState === 'open') {
|
||||
onOpen2();
|
||||
} else if (readyState === 'connecting') {
|
||||
channel2.addEventListener('open', onOpen2, { once: true });
|
||||
} else {
|
||||
onError(new Error(`Unexpected ready state ${readyState}`));
|
||||
}
|
||||
}
|
||||
|
||||
function onDataChannel(event) {
|
||||
channel2 = event.channel;
|
||||
onDataChannelPairFound();
|
||||
}
|
||||
|
||||
channel1.addEventListener('open', onOpen1, { once: true });
|
||||
channel1.addEventListener('error', onError, { once: true });
|
||||
|
||||
if (channel2Options !== null) {
|
||||
channel2 = pc2.createDataChannel(options.channelLabel, channel2Options);
|
||||
onDataChannelPairFound();
|
||||
} else {
|
||||
pc2.addEventListener('datachannel', onDataChannel);
|
||||
}
|
||||
|
||||
if (options.doSignaling) {
|
||||
exchangeIceCandidates(pc1, pc2);
|
||||
doSignalingHandshake(pc1, pc2, options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Wait for RTP and RTCP stats to arrive
|
||||
|
@ -708,20 +569,19 @@ function getUserMediaTracksAndStreams(count, type = 'audio') {
|
|||
|
||||
// Performs an offer exchange caller -> callee.
|
||||
async function exchangeOffer(caller, callee) {
|
||||
const offer = await caller.createOffer();
|
||||
await caller.setLocalDescription(offer);
|
||||
return callee.setRemoteDescription(offer);
|
||||
await caller.setLocalDescription(await caller.createOffer());
|
||||
await callee.setRemoteDescription(caller.localDescription);
|
||||
}
|
||||
// Performs an answer exchange caller -> callee.
|
||||
async function exchangeAnswer(caller, callee) {
|
||||
const answer = await callee.createAnswer();
|
||||
await callee.setLocalDescription(answer);
|
||||
return caller.setRemoteDescription(answer);
|
||||
await callee.setLocalDescription(await callee.createAnswer());
|
||||
await caller.setRemoteDescription(callee.localDescription);
|
||||
}
|
||||
async function exchangeOfferAnswer(caller, callee) {
|
||||
await exchangeOffer(caller, callee);
|
||||
return exchangeAnswer(caller, callee);
|
||||
await exchangeAnswer(caller, callee);
|
||||
}
|
||||
|
||||
// The returned promise is resolved with caller's ontrack event.
|
||||
async function exchangeAnswerAndListenToOntrack(t, caller, callee) {
|
||||
const ontrackPromise = addEventListenerPromise(t, caller, 'track');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue