summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webrtc-encoded-transform/routines.js
blob: 4db7f39621cc891288fe7fb5b107eb9dbf21fc2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
async function createConnections(test, setupLocalConnection, setupRemoteConnection, doNotCloseAutmoatically) {
    const localConnection = new RTCPeerConnection();
    const remoteConnection = new RTCPeerConnection();

    remoteConnection.onicecandidate = (event) => { localConnection.addIceCandidate(event.candidate); };
    localConnection.onicecandidate = (event) => { remoteConnection.addIceCandidate(event.candidate); };

    await setupLocalConnection(localConnection);
    await setupRemoteConnection(remoteConnection);

    const offer = await localConnection.createOffer();
    await localConnection.setLocalDescription(offer);
    await remoteConnection.setRemoteDescription(offer);

    const answer = await remoteConnection.createAnswer();
    await remoteConnection.setLocalDescription(answer);
    await localConnection.setRemoteDescription(answer);

    if (!doNotCloseAutmoatically) {
        test.add_cleanup(() => {
            localConnection.close();
            remoteConnection.close();
        });
    }

    return [localConnection, remoteConnection];
}

function waitFor(test, duration)
{
    return new Promise((resolve) => test.step_timeout(resolve, duration));
}