-
Notifications
You must be signed in to change notification settings - Fork 54
/
no-media-call.html
129 lines (110 loc) · 4.73 KB
/
no-media-call.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>RTCPeerConnection No-Media Connection Test</title>
</head>
<body>
<div id="log"></div>
<h2>iceConnectionState info</h2>
<div id="stateinfo">
</div>
<!-- These files are in place when executing on W3C. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webrtc/RTCPeerConnection-helper.js"></script>
<script type="text/javascript">
var test = async_test('Can set up a basic WebRTC call with no data.');
var gFirstConnection = null;
var gSecondConnection = null;
var onOfferCreated = test.step_func(function(offer) {
gFirstConnection.setLocalDescription(offer, ignoreSuccess,
failed('setLocalDescription first'));
// This would normally go across the application's signaling solution.
// In our case, the "signaling" is to call this function.
receiveCall(offer.sdp);
});
function receiveCall(offerSdp) {
var parsedOffer = new RTCSessionDescription({ type: 'offer',
sdp: offerSdp });
gSecondConnection.setRemoteDescription(parsedOffer).then(
function() {
gSecondConnection.createAnswer().then(onAnswerCreated,
failed('createAnswer'));
},
failed('setRemoteDescription second'));
};
var onAnswerCreated = test.step_func(function(answer) {
gSecondConnection.setLocalDescription(answer, ignoreSuccess,
failed('setLocalDescription second'));
// Similarly, this would go over the application's signaling solution.
handleAnswer(answer.sdp);
});
function handleAnswer(answerSdp) {
var parsedAnswer = new RTCSessionDescription({ type: 'answer',
sdp: answerSdp });
gFirstConnection.setRemoteDescription(parsedAnswer).then(ignoreSuccess,
failed('setRemoteDescription first'));
};
var onIceCandidateToFirst = test.step_func(function(event) {
// If event.candidate is null = no more candidates.
if (event.candidate) {
gSecondConnection.addIceCandidate(event.candidate);
}
});
var onIceCandidateToSecond = test.step_func(function(event) {
if (event.candidate) {
gFirstConnection.addIceCandidate(event.candidate);
}
});
var onIceConnectionStateChange = test.step_func(function(event) {
assert_equals(event.type, 'iceconnectionstatechange');
assert_not_equals(gFirstConnection.iceConnectionState, "failed", "iceConnectionState of first connection");
assert_not_equals(gSecondConnection.iceConnectionState, "failed", "iceConnectionState of second connection");
var stateinfo = document.getElementById('stateinfo');
stateinfo.innerHTML = 'First: ' + gFirstConnection.iceConnectionState
+ '<br>Second: ' + gSecondConnection.iceConnectionState;
// Note: All these combinations are legal states indicating that the
// call has connected. All browsers should end up in completed/completed,
// but as of this moment, we've chosen to terminate the test early.
// TODO: Revise test to ensure completed/completed is reached.
if (gFirstConnection.iceConnectionState == 'connected' &&
gSecondConnection.iceConnectionState == 'connected') {
test.done()
}
if (gFirstConnection.iceConnectionState == 'connected' &&
gSecondConnection.iceConnectionState == 'completed') {
test.done()
}
if (gFirstConnection.iceConnectionState == 'completed' &&
gSecondConnection.iceConnectionState == 'connected') {
test.done()
}
if (gFirstConnection.iceConnectionState == 'completed' &&
gSecondConnection.iceConnectionState == 'completed') {
test.done()
}
});
// Returns a suitable error callback.
function failed(function_name) {
return test.step_func(function() {
assert_unreached('WebRTC called error callback for ' + function_name);
});
}
// Returns a suitable do-nothing.
function ignoreSuccess(function_name) {
}
// This function starts the test.
test.step(function() {
gFirstConnection = new RTCPeerConnection(null);
gFirstConnection.onicecandidate = onIceCandidateToFirst;
gFirstConnection.oniceconnectionstatechange = onIceConnectionStateChange;
gSecondConnection = new RTCPeerConnection(null);
gSecondConnection.onicecandidate = onIceCandidateToSecond;
gSecondConnection.oniceconnectionstatechange = onIceConnectionStateChange;
generateVideoReceiveOnlyOffer(gFirstConnection)
.then(onOfferCreated, failed('createOffer'));
});
</script>
</body>
</html>