blob: 4821e468fb78ec44452f666a978d1a1a5e14957e [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/promise-utils.js"></script>
</head>
<body>
<script>
if (window.internals)
internals.useMockRTCPeerConnectionFactory("");
let stream;
let offer;
description("Test setting up media between two RTCPeerConnection instances with one single SDP dialog.");
if (window.testRunner)
testRunner.setUserMediaPermission(true);
else {
debug("This test can not be run without the testRunner");
finishJSTest();
}
debug("Create RTCPeerConnection A");
const pcA = new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]});
shouldBe("pcA.signalingState", "'stable'");
shouldBeNull("pcA.pendingLocalDescription");
shouldBeNull("pcA.currentLocalDescription");
shouldBeNull("pcA.pendingRemoteDescription");
shouldBeNull("pcA.currentRemoteDescription");
debug("<br>Create RTCPeerConnection B");
const pcB = new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]});
shouldBe("pcB.signalingState", "'stable'");
shouldBeNull("pcB.pendingLocalDescription");
shouldBeNull("pcB.currentLocalDescription");
shouldBeNull("pcB.pendingRemoteDescription");
shouldBeNull("pcB.currentRemoteDescription");
debug("");
pcA.ontrack = function () {
debug("----------");
testPassed("A: got remote track event");
debug("----------");
};
pcB.ontrack = function () {
debug("----------");
testPassed("B: got remote track event");
debug("----------");
};
navigator.mediaDevices.getUserMedia({ "audio": true })
.then(function (s) {
stream = s;
debug("A: add media");
pcA.addTrack(stream.getAudioTracks()[0], stream);
debug("A: create offer");
return pcA.createOffer();
})
.then(function (offer) {
debug("A: got offer, set it as local description");
return pcA.setLocalDescription(offer);
})
.then(function () {
debug("A: local offer set");
shouldBe("pcA.signalingState", "'have-local-offer'");
shouldBeType("pcA.pendingLocalDescription", "RTCSessionDescription");
shouldBeNull("pcA.currentLocalDescription");
debug("<br>A: send offer to B");
debug("A --- offer --> B");
debug("B: got offer from A, set it as remote description");
return pcB.setRemoteDescription(pcA.localDescription);
})
.then(function () {
debug("B: remote offer set");
shouldBe("pcB.signalingState", "'have-remote-offer'");
shouldBeType("pcB.pendingRemoteDescription", "RTCSessionDescription");
shouldBeNull("pcB.currentRemoteDescription");
debug("<br>B: add media (to include in answer)");
pcB.addTrack(stream.getAudioTracks()[0], stream);
debug("B: create answer");
return pcB.createAnswer();
})
.then(function (answer) {
debug("B: got answer, set it as local description");
return pcB.setLocalDescription(answer);
})
.then(function () {
debug("B: local answer set");
shouldBe("pcB.signalingState", "'stable'");
shouldBeNull("pcB.pendingLocalDescription");
shouldBeType("pcB.currentLocalDescription", "RTCSessionDescription");
shouldBeNull("pcB.pendingRemoteDescription");
shouldBeType("pcB.currentRemoetDescription", "RTCSessionDescription");
debug("<br>B: send answer to A");
debug("A <-- answer -- B");
debug("A: got answer from B, set it as remote description");
return pcA.setRemoteDescription(pcB.localDescription);
})
.then(function () {
debug("A: remote answer set");
shouldBe("pcA.signalingState", "'stable'");
shouldBeNull("pcA.pendingLocalDescription");
shouldBeType("pcA.currentLocalDescription", "RTCSessionDescription");
shouldBeNull("pcA.pendingRemoteDescription");
shouldBeType("pcA.currentRemoetDescription", "RTCSessionDescription");
debug("");
testPassed("Offer/answer dialog completed")
debug("");
finishJSTest();
})
.catch(function (error) {
testFailed("Error in promise chain: " + error);
finishJSTest();
});
window.jsTestIsAsync = true;
window.successfullyParsed = true;
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>